Hadrian Posted April 19, 2012 Share Posted April 19, 2012 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+'">'; Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted April 19, 2012 Share Posted April 19, 2012 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+'">'; Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted April 19, 2012 Share Posted April 19, 2012 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+'">'; Quote Link to comment Share on other sites More sharing options...
Hadrian Posted April 19, 2012 Author Share Posted April 19, 2012 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+'">'; Quote Link to comment Share on other sites More sharing options...
Hadrian Posted April 19, 2012 Author Share Posted April 19, 2012 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. Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted April 19, 2012 Share Posted April 19, 2012 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 Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted April 19, 2012 Share Posted April 19, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.