Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 11th, 2017, 12:24 PM
gregmaze gregmaze is offline
Junior Community Member
 
Join Date: Jul 2012
Posts: 18
Default FusionProTextMeasure Rule help

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
Reply With Quote
  #2  
Old July 11th, 2017, 01:42 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: FusionProTextMeasure Rule help

Code:
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;
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #3  
Old July 12th, 2017, 08:12 AM
gregmaze gregmaze is offline
Junior Community Member
 
Join Date: Jul 2012
Posts: 18
Default Re: FusionProTextMeasure Rule help

Hello Stepp,

Thank you very much for the help. This works perfectly. A much simpler code... I enjoy reading your's and others' comments on this forum. This is a great learning place.

Thanks again
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:33 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.