Meir Posted May 1, 2013 Share Posted May 1, 2013 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. Quote Link to comment Share on other sites More sharing options...
step Posted May 1, 2013 Share Posted May 1, 2013 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>@"); Quote Link to comment Share on other sites More sharing options...
Meir Posted May 1, 2013 Author Share Posted May 1, 2013 Thank you very much. That worked great! Quote Link to comment Share on other sites More sharing options...
Meir Posted May 1, 2013 Author Share Posted May 1, 2013 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. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted May 1, 2013 Share Posted May 1, 2013 However, this is returning "{Name Copyfit Rule}" rather than the name. You should see the error when you validate the rule in the Rule Editor, and also in the .msg file when you do a regular composition (not a Preview). Quote Link to comment Share on other sites More sharing options...
Meir Posted May 1, 2013 Author Share Posted May 1, 2013 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. 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.