Jump to content

How To Control Where Line Breaks?


Recommended Posts

I am working on a business card that has very specific design specifications. One of the specifications is if the email cannot fit on one line, to drop the @... to the next line.

 

short@client.com would fit on one line but

 

reallyreallyreallyreallylong@client.com would display as

 

reallyreallyreallyreallylong

@client.com

 

Is there a way to set where the line breaks? In this case, set it to break before the @ symbol.

 

Thank you.

Link to comment
Share on other sites

You can give this a shot:


// Use TextMeasure to get the length of each company name
var tm = new FusionProTextMeasure;
var frameWidth = 2; // set width of the text box (in inches)
tm.pointSize = "10 pt"; // set the type size
tm.font = "Helvetica"; // set your typeface
var str = Field("Email"); // set the field to use
tm.CalculateTextExtent(str);
tm.useTags = false;
var tmWidth = tm.textWidth;

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

Link to comment
Share on other sites

I ran into an error trying to make a more complicated version of that. When I did it with the email field, it worked fine.

 

Now I am trying to adapt it to work with multiple fields.

 

I need it to determine if a line made up of first last credential1, credential2, credential3, credential 4 is wider than the text box.

 

If so, I need it to break the line after the first name, so the last name starts a new line.

 

I tried this:

 

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

// Use TextMeasure to get the length of each company name
var names = new FusionProTextMeasure;
names.pointSize = "9 pt"; // set the type size
names.font = "Bosis Bold"; // set your typeface
var strnames = Field("First")+" "+Field("Last"); // set the field to use
names.CalculateTextExtent(strnames);
names.useTags = false;
var namesWidth = names.textWidth;

// Use TextMeasure to get the length of each company name
var credential = new FusionProTextMeasure;
credential.pointSize = "9 pt"; // set the type size
credential.font = "Bosis Light"; // set your typeface
var strcredential = " "+Rule("Credential Rule"); // set the field to use
credential.CalculateTextExtent(strcredential);
credential.useTags = false;
var credentialWidth = credential.textWidth;


return (namesWidth+credentialWidth < frameWidth*7200) ? strnames : strnames.splice(" ", "<br>");

 

However, this is returning "{Name Copyfit Rule}" rather than the name.

Link to comment
Share on other sites

when I validate in the rule editor, it gives me the result I want.

 

When I compose, I get this error

Name Copyfit Rule, line 22: TypeError: strnames.splice is not a function

Composing record #1, input record 1

Value for variable Name Copyfit Rule not found in instance data

 

So I figured out it was because I replaced 'str.replace' with 'strnames.splice'.

 

Thank you.

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...