Jump to content

Text Measure Breaks


Susan

Recommended Posts

I have a rule where the line will break after the " & " when the whole line won't fit. I also want it to break after " and " since some entries use "and" instead of "&". Where would I add another variable in the rule below?

 

// Use TextMeasure to get the length of each company name

var tm = new FusionProTextMeasure;

var frameWidth = 2.5; // set width of the text box (in inches)

tm.pointSize = "9 pt"; // set the type size

tm.font = "Chronicle Deck"; // set your typeface

var str = Field("Mailing Name "); // set the field to use

tm.CalculateTextExtent(str);

tm.useTags = false;

var tmWidth = tm.textWidth;

var a tmWidth = tm.textWidth;

 

return (tmWidth < frameWidth*7200) ? str : str.replace(" & ", " &<br>");

Link to comment
Share on other sites

I would replace the last line with this:

return (tmWidth < frameWidth*7200) ? str : str.replace(/\b(\&|and)\b/, "$1<br>");

I would also make sure you're handling the text as tagged markup to begin with, like so:

// Use TextMeasure to get the length of each company name
var tm = new FusionProTextMeasure;
var frameWidth = 2.5; // set width of the text box (in inches)
tm.pointSize = "9 pt"; // set the type size
tm.font = "Chronicle Deck"; // set your typeface
var str = TaggedDataField("Mailing Name "); // set the field to use
tm.CalculateTextExtent(str);
var tmWidth = tm.textWidth;
return (textWidth < frameWidth*7200) ? str : str.replace(/\b(\&|and)\b/, "$1<br>");

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...