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 May 26th, 2016, 01:23 PM
TroyM68 TroyM68 is offline
Junior Community Member
 
Join Date: Mar 2016
Location: Tampa, FL
Posts: 31
Default CopyFitting text on a business card

I have a client that is having difficulty using copyfit. They are trying to create a business card template as follows:

Let me preface, this is a hospital and the Drs. like their certifications and credentials. For the purpose of this example, we are just calling them "Cert(s)".


1) First and Last Name, Cert, Cert, Cert
2) Cert, Cert, Cert, Cert, Cert, Cert, Cert
3) Title

4) Department
5) Address | City, St. Zip
6) Phone1 | Phone2
7) Phone3 | Phone4
8) Email


They would like the field "Certs", shown above in red, to be able to fill the remaining space on line 1 of the text frame. Since Doctors like to show all of their certifications, the customer would like to have multiple certifications roll to line 2, if necessary (if they all don't fit on line 1).
(All certifications will be entered into 1 field separated by commas) They do not, however, want certifications to roll to a 3rd line of text.
If the certifications exceed the space on line 2 of the text frame, the customer would like to return "Certifications exceed the allotted space".

When they were doing these cards manually, they would adjust the spacing between the letters and the letter width, while not affecting the font height.

When experimenting with CopyFit, they found all the text shrunk by a percentage and would role to more then to two line limitation.

I haven't been able to figure this one out on my own, so I am reaching out to see if anyone has run into something similar in the past...or... has any suggestions on how I can accomplish this?

Thank you!!!
Reply With Quote
  #2  
Old May 26th, 2016, 01:35 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,359
Default Re: CopyFitting text on a business card

Are you really trying to copyfit the certs, or are you just trying to limit them to two lines? In other words, should the rule try to shrink the certs down to a specific size to try to fit them onto two lines? Or is the idea just to see if they fit on two lines at the original point size, and report an error if they don't?
__________________
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 May 27th, 2016, 03:00 PM
TroyM68 TroyM68 is offline
Junior Community Member
 
Join Date: Mar 2016
Location: Tampa, FL
Posts: 31
Default Re: CopyFitting text on a business card

What They currently do is one of two things pending the number of certs. They either squeeze the text (width-wise) as much as 85% (to get the certs all on only the first line) or...If the certs still can't fit on line 1, they abandon the "Text Squeeze" and wrap the text to a second line with no adjustment to the font whatsoever.

Right now the customer doesn't know if they can have both options.

The perfect scenario would be for a rule to look at the space available in the first line of text to see if the certs could be "squeezed", no more then 85%, to keep all the text on line 1...

If it is too long to fit on that first line... They would like to abandon the "text squeeze", and instead, roll the text to a second line, but not to exceed the spaces available on line two... If that limit is exceeded...they would like a message telling them the maximum number of characters has been exceeded.

If this is too crazy... please let me know... But thanks for listening and for your input1

Troy
Reply With Quote
  #4  
Old May 31st, 2016, 09:35 AM
ScottHillock ScottHillock is offline
Regular Contributor
 
Join Date: Mar 2010
Posts: 91
Default Re: CopyFitting text on a business card

Based off of Dan's and Step's code here on the forum.

Code:
//Field names
var v_field = [Field('First and Last Name'), Field('Cert1'), Field('Cert2'), Field('Cert3'), Field('Cert4')].filter(String);
//Font
var font_name = "2Volkswagon Heavy-K";
//Font Size
var v_size = "12";
//Frame Width in inches
var v_frame = "3";


var var1_n =  '<f name="' + font_name + '">';
var var1_s =  '<z newsize="' + v_size + '">';
var var2 = v_field.join(', '); //combine fields
var var3 = v_frame*72; //get frame width in points
var var4 = var1_n + var1_s + var2;
var tm = new FusionProTextMeasure;
tm.CalculateTextExtent(var4);
var tmwidth = tm.textWidth;
if (tmwidth < var3*100){return var4;} //if no scaling needed return without magnify
var factor = Round(var3 / tm.textWidth * 10000, 0) - 1;
if (factor >= 85){return "<magnify type=setwidth factor=" + factor + ">" + var4 + "</magnify>";} //if scaling is above 85% return with scaling
if (tmwidth < var3*200){return var4;} //if it can fit 2 lines without scaling return

//error Message
Print ("the maximum number of characters has been exceeded");
return "Certifications exceed the allotted space";
The line that contains "if (tmwidth < var3*200){return var4;}" might need the 200 value adjusted lower. Since some text breaks at different points.
Reply With Quote
  #5  
Old May 31st, 2016, 10:23 AM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: CopyFitting text on a business card

One thing you could do is to create a text rule to return your name and credentials called "Name":
Code:
var name = Field('name');
var creds = Field('creds');

return []
    .concat(name, creds.split(','))
    .map( function(s) {
        return Trim(s);
    })
    .filter(String)
    .join(', ');
Then you could insert that into a text frame along with other rules/variables and let onCopyfit handle the resizing of your text by inserting this into the onCopyFit callback:
Code:
var cf = FusionPro.Composition.CurrentFlow
var rule = 'Name';
if (!Copyfit(new MagnifyAttributes("text", 25, 400, 6, 72))) {
  ReportWarning("Could not copyfit text in flow " + 
                FusionPro.Composition.CurrentFlow.name);
} else {
  if (Rule(rule)) {
    var factor = Int((cf.content.match(/factor="(\d+)"/) || ['','100'])[1]) / 100;
    var tag = '<variable name="' + rule + '">';
    var find = new RegExp('<para.*?(?='+tag+')', '')
    var paragraph = (cf.content.match(find) || [''])[0];
    var font = (paragraph.match(/<f name="([^"]+)"/) || ['','Arial'])[1];
    var size = Int((paragraph.match(/<z newsize="([^"]+)"/) || ['','12'])[1]) * factor;

    var tm = new FusionProTextMeasure;
    tm.font = font;
    tm.pointSize = Int(size) + 'pt';
    tm.maxWidth = GetSettableTextWidth(FindTextFrame(cf.name));
    tm.CalculateTextExtent(Rule(rule));

    if (tm.textLines > 2)
      cf.content = cf.content.replace(new RegExp(tag, ''), 
        '<color name="Red">Certifications exceed the allotted space</color>');
  }
}
That allows you to more accurately determine if "Name" will require 1 or 2 lines after the frame has been "copyfit" to ensure the text flow fits in the frame. I suppose you could play around with those settings in order to reduce the tracking to a minimum of 85% before wrapping the "Name" to a second line if you wanted to but I'll leave that up to you.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #6  
Old June 1st, 2016, 12:32 PM
TroyM68 TroyM68 is offline
Junior Community Member
 
Join Date: Mar 2016
Location: Tampa, FL
Posts: 31
Default Re: CopyFitting text on a business card

Scott, when I re-create your rule:

//Field names
var v_field = [Field('First Name') + " " + Field('Last Name ') + ", " + Field('Credentials') ].filter(String);
//Font
var font_name = "Arial";
//Font Size
var v_size = "11";
//Frame Width in inches
var v_frame = "2.05";

var var1_n = '<f name="' + font_name + '">';
var var1_s = '<z newsize="' + v_size + '">';
var var2 = v_field.join(' '); //combine fields
var var3 = v_frame*72; //get frame width in points
var var4 = var1_n + var1_s + var2;
var tm = new FusionProTextMeasure;
tm.CalculateTextExtent(var4);
var tmwidth = tm.textWidth;
if (tmwidth < var3*100){return var4;} //if no scaling needed return without magnify
var factor = Round(var3 / tm.textWidth * 10000, 0) - 1;
if (factor >= 85){return "<magnify type=setwidth factor=" + factor + ">" + var4 + "</magnify>";} //if scaling is above 85% return with scaling
if (tmwidth < var3*200){return var4;} //if it can fit 2 lines without scaling return
//error Message
Print ("the maximum number of characters has been exceeded");
return "Certifications exceed the allotted space";

I receive the following message when I try to validate:

<f name="Arial"><z newsize="11">Troy Marshall, cred, cred, cred, cred, cred, cred,

This is also what appears on the Business Card.

What am I doing wrong???
Reply With Quote
  #7  
Old June 1st, 2016, 12:46 PM
ScottHillock ScottHillock is offline
Regular Contributor
 
Join Date: Mar 2010
Posts: 91
Default Re: CopyFitting text on a business card

The v_field is a variable array. So it should only include values separated by a comma. The concatenation with the + is not needed, as that is handled later on.
So I would change it to:
Code:
var FirstLast = Field('First Name') + " " + Field('Last Name ') + ", ";
var v_field = [FirstLast, Field('Credentials') ].filter(String);
This way we can modify the FirstLast later if needed, while still using the rest of the code.
Reply With Quote
  #8  
Old June 1st, 2016, 12:50 PM
TroyM68 TroyM68 is offline
Junior Community Member
 
Join Date: Mar 2016
Location: Tampa, FL
Posts: 31
Default Re: CopyFitting text on a business card

Step,
When I change the OnCopyFit rule (modified below)

var cf = FusionPro.Composition.CurrentFlow
var rule = 'name';
if (!Copyfit(new MagnifyAttributes("text", 25, 400, 6, 72))) {
ReportWarning("Could not copyfit text in flow " +
FusionPro.Composition.CurrentFlow.name);
} else {
if (Rule('name')) {
var factor = Int((cf.content.match(/factor="(\d+)"/) || ['','100'])[1]) / 100;
var tag = '<variable name="' + rule + '">';
var find = new RegExp('<para.*?(?='+tag+')', '')
var paragraph = (cf.content.match(find) || [''])[0];
var font = (paragraph.match(/<f name="([^"]+)"/) || ['','Arial'])[1];
var size = Int((paragraph.match(/<z newsize="([^"]+)"/) || ['','12'])[1]) * factor;
var tm = new FusionProTextMeasure;
tm.font = font;
tm.pointSize = Int(size) + 'pt';
tm.maxWidth = GetSettableTextWidth(FindTextFrame(cf.name));
tm.CalculateTextExtent(Rule(rule));
if (tm.textLines > 2)
cf.content = cf.content.replace(new RegExp(tag, ''),
'<color name="Red">Certifications exceed the allotted space</color>');
}
}

I receive the following error message when I try to validate the rule.

C:\Program Files (x86)\PTI\FusionPro\Builtins.js line 3316 ERROR: in FindFrame(), no frame specified

Any ideas?
Reply With Quote
  #9  
Old June 1st, 2016, 12:55 PM
TroyM68 TroyM68 is offline
Junior Community Member
 
Join Date: Mar 2016
Location: Tampa, FL
Posts: 31
Default Re: CopyFitting text on a business card

Thanks Scott, I will give this a try!
Reply With Quote
  #10  
Old June 1st, 2016, 12:57 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: CopyFitting text on a business card

Quote:
Originally Posted by TroyM68 View Post
Step,
When I change the OnCopyFit rule (modified below)

var cf = FusionPro.Composition.CurrentFlow
var rule = 'name';
if (!Copyfit(new MagnifyAttributes("text", 25, 400, 6, 72))) {
ReportWarning("Could not copyfit text in flow " +
FusionPro.Composition.CurrentFlow.name);
} else {
if (Rule('name')) {
var factor = Int((cf.content.match(/factor="(\d+)"/) || ['','100'])[1]) / 100;
var tag = '<variable name="' + rule + '">';
var find = new RegExp('<para.*?(?='+tag+')', '')
var paragraph = (cf.content.match(find) || [''])[0];
var font = (paragraph.match(/<f name="([^"]+)"/) || ['','Arial'])[1];
var size = Int((paragraph.match(/<z newsize="([^"]+)"/) || ['','12'])[1]) * factor;
var tm = new FusionProTextMeasure;
tm.font = font;
tm.pointSize = Int(size) + 'pt';
tm.maxWidth = GetSettableTextWidth(FindTextFrame(cf.name));
tm.CalculateTextExtent(Rule(rule));
if (tm.textLines > 2)
cf.content = cf.content.replace(new RegExp(tag, ''),
'<color name="Red">Certifications exceed the allotted space</color>');
}
}

I receive the following error message when I try to validate the rule.

C:\Program Files (x86)\PTI\FusionPro\Builtins.js line 3316 ERROR: in FindFrame(), no frame specified

Any ideas?
You need to name the frame that the Rule('name') is shown in.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
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 07:38 AM.


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