Copy link to clipboard
Copied
I am trying to set the font family, size and style of the selection using ExtendScript. Family and Style are applied correctly but the font size stays the same. FM2019. What am I doing wrong?
FA_Errno is set to FE_Success after the operation.
function fixText(targetDoc){
var i = 0;
var arial = GetFontFamilyValue("Symbol");
var textProps = AllocatePropVals(3);
i=0;
textProps[i].propIdent.num = Constants.FP_FontFamily;
textProps[i].propVal.valType = Constants.Integer;
textProps[i].propVal.ival = arial ;
i++;
textProps[i].propIdent.num = Constants.FP_FontSize;
textProps[i].propVal.valType = Constants.Integer;
textProps[i].propVal.ival = 36 * 65536;
i++;
textProps[i].propIdent.num = Constants.FP_Underlining;
textProps[i].propVal.valType = Constants.Integer;
textProps[i].propVal.ival = Constants.FV_CB_SINGLE_UNDERLINE;
var tr = targetDoc.TextSelection;
targetDoc.SetTextProps(tr, textProps);
PrintFAErrno ();
return;
}
Copy link to clipboard
Copied
Are you sure the valType for font size is Integer? Font sizes can be fractional values.
Copy link to clipboard
Copied
I think Rick is right. When I query the property, it comes back with a valType of 2. The documentation suggests that this should be Constants.FT_Metric. I don't have time at the moment to actually test it.
Russ
Copy link to clipboard
Copied
After posting that, I notice that you are using Constants.Integer. I don't think that is defined. I think it should be Constants.FT_Integer. Makes me wonder why it works, though. Maybe the default is integer if it can't make sense of anything else.
Copy link to clipboard
Copied
Thanks@frameexpert @Russ Ward I have tried both Constants.FT_Metric and Constants.FT_Integer but I still don't get the expected results.
Copy link to clipboard
Copied
I have been trying a few things this morning, but without success.
Copy link to clipboard
Copied
So, I got a little closer, but did not completely succeed. I am out of time for now but maybe this will give somebody a boost.
I find that I can get the property from one text location and apply it to another. So the propVal works. An annoying brute force workaround would be to have a dummy paragraph somewhere with the desired font size and get the prop from there, rather than try to set it up manually.
But all that is to say that something is hidden from us. I found that this reports the font size, when you query property from the doc:
alert(textProp.propVal.val);
...so it seems the value is hidden in the 'val' member, which is not documented to my knowledge. I just found it by playing around. However, I could not set it. This does not work:
textProps[i].propVal.val = 36 * 65536;
In the FDK, you have to do a MetricFloat() conversion to set a metric from a real. But this function does not exist in ExtendScript. So I got the idea to do this:
alert(textProp.propVal.val.constructor.name);
...and it reported "Number". I thought oh yeah, I got it now. Then I tried this:
textProps[i].propVal.val = new Number(36 * 65536);
...and cry me a river emoji, it does not work. The 'val' member gets some default value around 11 points and I just cannot figure out how to change it.
That's as far as I can get right now. I hope it helps.
Copy link to clipboard
Copied
<quote>An annoying brute force workaround would be to have a dummy paragraph somewhere with the desired font size and get the prop from there, rather than try to set it up manually.</quote>
That is a horrible idea....but I thought the same thing :-).
Copy link to clipboard
Copied
Thanks for all the research and confirming that this is not working as expected. The workaround was to have a character format with only the desired settings and apply that to the range. Maybe getting just the font size property is better, I don't know. Both approaches should work even though not the best solution. I would still like to know if there is a way to make the original approach work and why it is not working as expected.
Copy link to clipboard
Copied
Setting order is important.
Setting ival will automatically set valType to Constants.FT_Integer.
OK
textProps[i].propIdent.num = Constants.FP_FontSize;
textProps[i].propVal.ival = 36 * 65536;
textProps[i].propVal.valType = Constants.FT_Metric;
NG
textProps[i].propIdent.num = Constants.FP_FontSize;
textProps[i].propVal.valType = Constants.FT_Metric;
textProps[i].propVal.ival = 36 * 65536;