Jump to content

TextMeasure zero value


Hadrian

Recommended Posts

Keep getting a value of 0 in tmWidth. I tried a formatted text source as well. This is a text rule in a text frame. What am I missing here?

var tm = new FusionProTextMeasure;
tm.pointSize = "12 pt";
tm.font = "Baskerville Bold";
var str = Field("ReturnAddress"); 
tm.useTags = false;
var tmWidth = tm.textWidth;
return '<graphic file="'+Field("EnvelopeSeal")+'" width="'+tmWidth+'">';

Link to comment
Share on other sites

You're missing the calculation.

 

var tm = new FusionProTextMeasure;
tm.pointSize = "12 pt";
tm.font = "Baskerville Bold";
var str = Field("ReturnAddress"); 
tm.useTags = false;
tm.CalculateTextExtent('<f name="' + tm.font + '"><z newsize="' + tm.pointSize + '">' + str);
var tmWidth = tm.textWidth;
return '<graphic file="'+Field("EnvelopeSeal")+'" width="'+tmWidth+'">';

Link to comment
Share on other sites

Yes, Thomas is correct: you have to call CalculateTextExtent for the measurement to actually take place.

 

One minor quibble with Thomas's code, though: You don't need to add the font and size tags, since you're specifying those attributes already in the FusionProTextMeasure object. And, in fact, if you're setting the useTags property to false, that won't work anyway, as you're telling the object to measure the tags as literal text. So you should be able to do simply this:

var tm = new FusionProTextMeasure;
tm.pointSize = "12 pt";
tm.font = "Baskerville Bold";
tm.useTags = false;
tm.CalculateTextExtent(Field("ReturnAddress"));
var tmWidth = tm.textWidth;
return '<graphic file="'+Field("EnvelopeSeal")+'" width="'+tmWidth+'">';

Link to comment
Share on other sites

You are right. After I added the calculation but I am still getting 0. I made another more verbose version and no dice still.

 

radd='<p style="(no style)" br="false" override="true" quad="L" findent="0" lindent="0" rindent="0" leadbefore="0" leadafter="0" widows="2" kerning="true" hyphenate="false" skipifempty="false" skipifemptyvar="false" noparabreakoncopyfit="false"><tracking newsize="0.000000"><f name="Baskerville Bold"><z newsize="12.0"><color name="Black"><variable name="ReturnAddress">';

tm = new FusionProTextMeasure;

tm.CalculateTextExtent(radd);

myTM = tm.textWidth;

 

return '<graphic file="'+Field("EnvelopeSeal")+'" width="'+myTM+'">';

Link to comment
Share on other sites

I am assuming that on validation, in FP8, the value will always be 0 but as I am testing this I had the rule return the variable "tmWidth" only. I get zero when I validate but I get an actual number in the text frame. I was going to use the tmWidth to subtract it from the size of the text frame and determine how much space I have to add text to the right of the inline graphic.
Link to comment
Share on other sites

It gives a value in the Rule Editor validation for me. Replace the Field calls with some random text strings in the script and see if you get a value. It could be an issue with your data source.

 

Dan, I never used the pointSize and font properties before and just left useTags as default and defined it out with tags. I was wondering why the returned value seemed oddly off in this case. Makes sense now :)

Link to comment
Share on other sites

Text Measurement of <variable> tags doesn't work correctly at validation time in the Rule Editor, although it does work at composition time:

http://forums.printable.com/showthread.php?p=9546#post9546

 

You need to call the Field function directly to be able to validate the rule; in this case, you can change the first line like so:

radd='<f name="Baskerville Bold"><z newsize="12.0">' + Field("ReturnAddress");

I also removed all the tags which won't have any effect on this calculation.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...