Jump to content

Possible to use CopyfitLine with "Do not break on copyfit"?


Recommended Posts

Hi all,


As the title indicates, I'm wondering if it's possible to modify the CopyfitLine code in such a way that the line will not break to multiple lines before trying to copyfit.


I currently have the javascript below:


return CopyfitLine("", Field("contactName"), "Helvetica Neue", 9.5, 105.35, 7, false);


However, because I have plenty of room in my text box for the line to break, and because there's a space in the field value ("Firstname Lastname"), it's breaking at the space before it attempts to copyfit. I have "Do Not Break On Copyfit" selected in my text box, but I am guessing that only works on the normal OnCopyfit rule, and not on CopyfitLine.


Is there a javascript function (or other solution) I can use to ensure the line does not break at the space? I should mention, using a non-breaking space isn't a great solution for us, as more often than not, FusionPro will spit out boxes with Xs in them in composition whenever a non-breaking space is used (but that's a different issue altogether).


Any help is appreciated!

Link to comment
Share on other sites

As a quick follow-up... out of curiosity, I removed the space in the field value, and while the copyfit did occur, it is still breaking to two lines, even though it could copyfit to a lower point size.


The javascript validates to the below:

<f name="Helvetica Neue"><z newsize=9.5><z newsize=7.800000000000006>EdwardHanrahanhfewfwerewr


However, I have in my rule to allow it to copyfit down to 6.5pt. I can't figure out why it stops at 7.8pt and continues to want to break.


As an aside, I have the same rule being applied to another field (email address) in the same text box, and the email address version works flawlessly. Is it possible the two rules are conflicting with one another?



Link to comment
Share on other sites

It seems a little excessive, but you could use FusionProTextMeasure:

var contactName = 'Edward Hanrahanhfewfwerewr';
var pointSize = { max: 9.5, min: 6.5 };
contactName = '<span font="Helvetica Neue" pointsize="' + pointSize.max + '">' + contactName + '</span>';
var limit = Int((pointSize.min / pointSize.max) * 100);
return NoBreakCopyfit(contactName, 100, limit);

function NoBreakCopyfit(str, mag, min) {
 if (FusionPro.inValidation) return str;
 try {
   var frameName = FusionPro.Composition.CurrentFlow.name;
   var width = GetSettableTextWidth(FindTextFrame(frameName));
 } catch(e) {
   ReportError('Must name text frame and set rule to "Re-evaluate this rule for every text flow"');
 var tm = new FusionProTextMeasure;
 tm.useTags = true;
 tm.maxWidth = width;
 var magnified = '<magnify factor="' + mag + '" type="text">' + str + '</magnify>';
 return tm.textLines > 1 && mag > min ? NoBreakCopyfit(str, --mag, min) : magnified;

Make sure you name your text frame and set the rule to "Re-evaluate this rule for every text flow."

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.

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