Jump to content

FusionProTextMeasure Rule help


gregmaze

Recommended Posts

Greetings all...

 

I have a javascript rule I am trying to create that I was hoping someone might help with a problem.

I have a business card that has a Name Line and a degree line. The user can choose up to 3 degrees, which will be separated by a comma. If the Degrees can fit on the Name line the customer would like to have it appear there. If all the degrees cannot fit on the name line together, all degrees should then be on the 2nd line. The script below is what I have so far. I have it pretty much working, except when the degrees go to the 2nd line. I am having a problem with commas and spaces.

Here is the 2 versions it should look like.

Mary Smith, CFO

or

Mary Smith

CFO, COO, CEO

 

currently for the 2nd line option it appears

Mary Smith

CFOCOOCEO,

 

here is the code:

 

var Name = [Field("Name")]

var Degree = [Field("Degree1") + Field("Degree2") + Field("Degree3")];

var result = "";

var test = "";

 

var tm = new FusionProTextMeasure;

var frameWidth = 1.72;

tm.pointSize = "10 pt";

tm.font = "DINOT-Medium";

tm.useTags = true;

 

for (var p=0; p<Name.length; p++) {

if (Name[p] != "" + Degree[p] !="") {

test += Name[p] + Degree[p];

tm.CalculateTextExtent(test);

if (tm.textWidth < frameWidth * 7200) result += Name[p] + ", " + Degree[p];

else {

test += Name[p] + Degree[p];

result += Name[p] + "<br />" + (Degree[p] + ", ");

}

}

}

 

return Left(result,result.length);

 

Thank you in advance for the help if possible.

 

Greg

Mac OS 10.11.3

Fusion Pro 10.0.3

Link to comment
Share on other sites

var result = [
 Field("Name"),
 Field("Degree1"),
 Field("Degree2"),
 Field("Degree3")
].filter(String).join(', ');

var tm = new FusionProTextMeasure;
tm.pointSize = "10 pt";
tm.font = "DINOT-Medium";
tm.maxWidth = 1.72 * 7200;
tm.CalculateTextExtent(result);

return tm.textLines > 1 ? result.replace(', ', '<br/>') : result;

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