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 January 4th, 2013, 10:38 AM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Add a character conditially if line does not break

This post is a further wrinkle to the issue I posted here.

I am working on a business card form where we require the individual's name, professional designations and title in one area. Ideally, the card looks like this:



But in some cases, if the employee's name is particulary long and they have a lot of designations, that line must be split to accommodate both. Like so:



I have managed to do so by applying "do not break" rules to the name field and the designation field. But now the client has thrown a wrench in the works. They don't want the comma following the employee's name if the designations fall on the next line.

The comma itself is already applied with a rule. It is only inserted if there is something in the designation field. That rule looks like this:
if (Field("Designation") > "0")
{
return "<span>" + RawText(", ") + "</span>";
}
return "";

Now I need to add another condition to that rule (I think) where the comma is only added if there is data in the designation field AND the designation does not break to another line.

Any thoughts on how to do this?
__________________
Michelle
Digital Services Coordinator at Rileys (print and electronic services provider) in Alberta, Canada
FusionPro VDP 9.1.0, Windows 7, Acrobat Pro XI , InDesign CS6, Avanti eAccess, EFI Digital Storefront
Reply With Quote
  #2  
Old January 4th, 2013, 11:11 AM
Dan Korn's Avatar
Dan Korn Dan Korn is online now
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,370
Default Re: Add a character conditially if line does not break

This looks like a job for text measurement, using the FusionProTextMeasure object to see what fits on the first line.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #3  
Old January 4th, 2013, 11:21 AM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Re: Add a character conditially if line does not break

Thanks, Dan.

I investigated TextMeasure when I began this project, but a search of these boards failed to turn up any info that I understood well enough to apply to my project (I am working hard to get up to speed on JS, but am still a noob).

Could you please point me in the direction of some info on applying TextMeasure in an instance like this?

Thanks so much.
__________________
Michelle
Digital Services Coordinator at Rileys (print and electronic services provider) in Alberta, Canada
FusionPro VDP 9.1.0, Windows 7, Acrobat Pro XI , InDesign CS6, Avanti eAccess, EFI Digital Storefront
Reply With Quote
  #4  
Old January 4th, 2013, 11:26 AM
Dan Korn's Avatar
Dan Korn Dan Korn is online now
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,370
Default Re: Add a character conditially if line does not break

Quote:
Originally Posted by MeeshKB View Post
Could you please point me in the direction of some info on applying TextMeasure in an instance like this?
You want to do something very similar to this thread:
http://forums.pti.com/showthread.php?t=3116

Hopefully that will give you something to start from.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});

Last edited by Dan Korn; January 4th, 2013 at 11:31 AM.. Reason: change printable to pti in link
Reply With Quote
  #5  
Old January 4th, 2013, 01:23 PM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Re: Add a character conditially if line does not break

Thanks. I'll check this out.
__________________
Michelle
Digital Services Coordinator at Rileys (print and electronic services provider) in Alberta, Canada
FusionPro VDP 9.1.0, Windows 7, Acrobat Pro XI , InDesign CS6, Avanti eAccess, EFI Digital Storefront
Reply With Quote
  #6  
Old January 7th, 2013, 12:14 PM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Re: Add a character conditially if line does not break

Okay, so I've read and done my best to comprehend the sample you directed me to, Dan. And I am closer to understanding, but not quite there.

I am getting that I need to define the variable, thusly:

var tm = new FusionProTextMeasure;
var frameWidth = 4; // width of your text frame in inches
tm.pointSize = "10 pt"; // your point size here
tm.font = "Helvetica"; // your font here
tm.useTags = true;

But I am not sure how to apply that result to give me the conditional text I require. Also, is this solution still viable considering that within the frame I have text with two different sizes? I guess the only one I need to measure it the Employee Name field, so maybe that's moot.
__________________
Michelle
Digital Services Coordinator at Rileys (print and electronic services provider) in Alberta, Canada
FusionPro VDP 9.1.0, Windows 7, Acrobat Pro XI , InDesign CS6, Avanti eAccess, EFI Digital Storefront

Last edited by MeeshKB; January 7th, 2013 at 12:49 PM..
Reply With Quote
  #7  
Old January 7th, 2013, 01:20 PM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Add a character conditially if line does not break

Basically, you would want to create a variable which contains a record's name and designations (as they would appear if all on one line). You then test that against the tm object to see if its length would exceed the frame width using the pre-defined font and size. If tm.textWidth is less than the frame width, the name and designations are left on one line. If equal to or greater, a break tag can be inserted to separate on two lines.

So your version of the rule might look something like:
Code:
var name = Field(First") + " " + Field("Last);
var test = name + ", " + Field("Designation");
var result = "";

var tm = new FusionProTextMeasure;
var frameWidth = 4; // width of your text frame in inches
tm.pointSize = "10 pt"; // your point size here
tm.font = "Helvetica"; // your font here
tm.useTags = true;

if (name != "") {
    tm.CalculateTextExtent(test);
    if (tm.textWidth < frameWidth * 7200) result = test;
    else result = name + "<br />" + Field("Designation");
}
return result;
Of course, you'll need to correct the details regarding your frame width, font and point size as well as the variables "name" and "test" depending on how your data is provided. And this code only checks to see if the name and designation together fit on one line. If either name or designations don't fit on a line by themselves (i.e. a REALLY LONG name), then you will still have to deal with line breaks on those records.
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
Reply With Quote
  #8  
Old January 7th, 2013, 01:27 PM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Re: Add a character conditially if line does not break

Thanks so much, Eric. I'll try this out.
__________________
Michelle
Digital Services Coordinator at Rileys (print and electronic services provider) in Alberta, Canada
FusionPro VDP 9.1.0, Windows 7, Acrobat Pro XI , InDesign CS6, Avanti eAccess, EFI Digital Storefront
Reply With Quote
  #9  
Old January 7th, 2013, 04:40 PM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Re: Add a character conditially if line does not break

Alright, so I tried out the code you supplied, Eric. Thank you again for that.

My code now looks like this:
(Please excuse my awkward rule naming. "Add Reg to LEED" is the rule I am using for the designation field.)
var name = Rule("Case selection for a name field Rule");
var test = name + ", " + Rule("Add Reg to LEED");
var result = "";

var tm = new FusionProTextMeasure;
var frameWidth = 1.45; // width of your text frame in inches
tm.pointSize = "8"; // your point size here
tm.font = "Myriad Pro Semibold"; // your font here
tm.useTags = true;

if (name != "") {
tm.CalculateTextExtent(test);
if (tm.textWidth < frameWidth * 7200) result = test;
else result = Rule("Case selection for a name field Rule") + '<br>' + Rule("Add Reg to LEED");
}
return result;

It works well except for a couple of wrenches in the works...

1) I need to somehow add another condition which will not apply the comma if there is no data in the Designation field.

2) The text for the designation is a smaller point size than the Employee name. Since these are both applied inside the same rule, is there any way to indicate the different sizes?
__________________
Michelle
Digital Services Coordinator at Rileys (print and electronic services provider) in Alberta, Canada
FusionPro VDP 9.1.0, Windows 7, Acrobat Pro XI , InDesign CS6, Avanti eAccess, EFI Digital Storefront
Reply With Quote
  #10  
Old January 8th, 2013, 09:48 AM
esmith's Avatar
esmith esmith is offline
Senior Contributor
 
Join Date: Oct 2008
Location: Charlotte, NC
Posts: 870
Default Re: Add a character conditially if line does not break

There's probably a cleaner way to do this, but here's my solution:
Code:
var name = Rule("Case selection for a name field Rule");
var designation = Rule("Add Reg to LEED");
var result = "";

var frameWidth = 1.45; // width of your text frame in inches

var tmName = new FusionProTextMeasure;
tmName.pointSize = "8"; // point size of name
tmName.font = "Myriad Pro Semibold"; // font for name
tmName.useTags = true;

var tmDesig = new FusionProTextMeasure;
tmDesig.pointSize = "6"; // point size for designations
tmDesig.font = "Myriad Pro Semibold"; // font for designations
tmDesig.useTags = true;

if (designation != "") {
   tmName.CalculateTextExtent(name + ", ");
   tmDesig.CalculateTextExtent(designation);
   if ((tmName.textWidth + tmDesig.textWidth) < frameWidth * 7200) {
      result = name + ", " + designation;
   }
   else result = name + '<br>' + designation;
}
else result = name;

return result;
__________________
Eric Smith
Content Developer
Classic
FP 9.3.6, MAC OSX 10.9.4, Acrobat 11.0.09
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 10:45 AM.


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