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 October 8th, 2008, 02:38 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,340
Lightbulb A better CopyfitLine

Here's a function I wrote to basically do what CopyfitLine does, using the <magnify> tag and a more efficient algorithm:
Code:
 
  function CopyfitLineWithMagnifyTag(line, widthInPoints, AllowToExpand)
  {
    var tm = new FusionProTextMeasure;
    tm.CalculateTextExtent(line);
    if (tm.messages)
      ReportError("CopyfitMagnifyLine: " + tm.messages);
 
    if (tm.textWidth < widthInPoints*100 && !AllowToExpand)
      return line;
 
    var factor = Round(widthInPoints / tm.textWidth * 10000, 0) - 1;
    return "<magnify type=setwidth factor=" + factor + ">" +
            line + "</magnify>";
  }
The idea here is that we don't need to iterate until we find a size that fits; we can simply take the ratio of how big the line is already compared to the desired width and use that as the magnification factor.

Note that you have to specify all the font and size information with tags. So a call would look something like this:
Code:
 
  return CopyfitLineWithMagnifyTag('<f name="Arial">' +
            '<z newsize=12>' + Field("Address"), 360);
The caller can add the optional third parameter of "true" to allow the text to get bigger, like so:
Code:
 
  return CopyfitLineWithMagnifyTag('<f name="Arial">' +
            '<z newsize=12>' + Field("Address"), 360, true);
This function could also be modified to take parameters specifying the font name and bold/italic faces.
__________________
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
  #2  
Old October 20th, 2008, 02:00 PM
pklingler pklingler is offline
Forum n00b
 
Join Date: Sep 2008
Location: Ohio
Posts: 6
Default Re: A better CopyfitLine

Dan,

I tried your copyfit function in a new job, and it works great. However, I ran into something odd when I went to print. If I output to PDF or PS, it prints correctly, but if I use VIPP output, the copyfitting does not occur in the printed output. In fact, the unreduced text actually prints past the boundary of the text frame.

I checked all of the other advanced settings in composition (like integral point size), and nothing is different between the compositions.

Has anyone else tested printed output using this function? Could there be something in the <magnify> tag that is not supported in VIPP? Or am I missing some other variable that caused the difference in my output?
__________________
Paul Klingler
TMR, Inc.

Printable 5.1 P1a, Adobe Acrobat Pro 8.1.2, Windows XP
Reply With Quote
  #3  
Old October 20th, 2008, 02:15 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,340
Default Re: A better CopyfitLine

Quote:
Originally Posted by pklingler View Post
DaIf I output to PDF or PS, it prints correctly, but if I use VIPP output, the copyfitting does not occur in the printed output. In fact, the unreduced text actually prints past the boundary of the text frame.
I don't personally know a lot about the internals of the VIPP output module. I would recommend you try two things:
  1. Download the newest version of FusionPro and see if you can reproduce the problem there. If so;
  2. Contact Support and send them your job for analysis.
__________________
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
  #4  
Old April 24th, 2014, 04:31 PM
sandig@customprinters.com sandig@customprinters.com is offline
Regular Contributor
 
Join Date: Feb 2010
Posts: 62
Default Re: A better CopyfitLine

Dan, I use this copyfit line rule often. It works great, except if the users enters an ampersand, such as "Teacher & Mentor", the rule does not work.
What can be done so that I can include amphersands in this copyfit line rule.
Reply With Quote
  #5  
Old October 17th, 2014, 10:28 AM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Re: A better CopyfitLine

Dan,

I'm just trying this for the first time. It seems to be magnifying just the width of the type, not the height. Is this intended, or am I missing a step?

Here's my code:
HTML Code:
  function CopyfitLineWithMagnifyTag(line, widthInPoints, AllowToExpand)
  {
    var tm = new FusionProTextMeasure;
    tm.CalculateTextExtent(line);
    if (tm.messages)
      ReportError("CopyfitMagnifyLine: " + tm.messages);
 
    if (tm.textWidth < widthInPoints*87 && !AllowToExpand)
      return line;
 
    var factor = Round(87 / tm.textWidth * 10000, 0) - 1;
    return "<magnify type=setwidth factor=" + factor + ">" +
            line + "</magnify>";
  }
  
    return CopyfitLineWithMagnifyTag('<f name="Swis721 BT">' +
            '<z newsize=11>' + Field("Name") + '<z newsize=6>' + ", " + Field("Designation"), 87, false);
__________________
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 October 17th, 2014, 11:14 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,340
Default Re: A better CopyfitLine

Quote:
Originally Posted by sandig@customprinters.com View Post
Dan, I use this copyfit line rule often. It works great, except if the users enters an ampersand, such as "Teacher & Mentor", the rule does not work.
What can be done so that I can include amphersands in this copyfit line rule.
You're passing tagged markup to the function, so you need to encode the text properly as tagged, with the TaggedTextFromRaw function. Although if it's a field value, it's better to use TaggedDataField instead, like so:
Code:
  return CopyfitLineWithMagnifyTag('<f name="Arial">' +
            '<z newsize=12>' + TaggedDataField("Address"), 360);
__________________
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
  #7  
Old October 17th, 2014, 11:15 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,340
Default Re: A better CopyfitLine

Quote:
Originally Posted by MeeshKB View Post
I'm just trying this for the first time. It seems to be magnifying just the width of the type, not the height. Is this intended, or am I missing a step?
In the <magnify> tag, change "type=setwidth" to "type=pointsize".
__________________
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
  #8  
Old October 17th, 2014, 12:14 PM
MeeshKB MeeshKB is offline
Regular Contributor
 
Join Date: Jun 2012
Location: Alberta, Canada
Posts: 64
Default Re: A better CopyfitLine

Quote:
Originally Posted by Dan Korn View Post
In the <magnify> tag, change "type=setwidth" to "type=pointsize".
Brilliant. Thanks so much, Dan. It's working like a charm.
__________________
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 August 19th, 2015, 10:21 AM
jmerrick0657 jmerrick0657 is offline
Junior Community Member
 
Join Date: Nov 2013
Posts: 35
Default Re: A better CopyfitLine

Dan, I found this old post and it works great for using multiple font styles in one line, however I can't figure out how to modify the function so I can input a name of the text field I want to copyfit and have it automatically calculate the width. Is that possible? Thanks.
Reply With Quote
  #10  
Old August 19th, 2015, 11:05 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,340
Default Re: A better CopyfitLine

Quote:
Originally Posted by jmerrick0657 View Post
Dan, I found this old post and it works great for using multiple font styles in one line, however I can't figure out how to modify the function so I can input a name of the text field I want to copyfit and have it automatically calculate the width. Is that possible? Thanks.
What do you mean by "text field?" Do you mean a data field? All the examples in this thread use the name of a data field to copyfit:
Quote:
Originally Posted by Dan Korn View Post
Code:
return CopyfitLineWithMagnifyTag('<f name="Arial">' +
            '<z newsize=12>' + TaggedDataField("Address"), 360);
Just put the name of your data field in there instead of "Address".

Or when you say "text field," do you mean that you want to use the name of a text frame? If so, you can use the FindTextFrame and GetSettableTextWidth() functions, like so:
Quote:
Originally Posted by Dan Korn View Post
Code:
var widthInPoints = FindTextFrame("YourFrameName").GetSettableTextWidth() / 100; 
return CopyfitLineWithMagnifyTag('<f name="Arial">' +
            '<z newsize=12>' + TaggedDataField("Address"), widthInPoints);
Or, if you check the "Re-evaluate this rule for every text flow" box, you can have it use the current frame's width automatically, like so:
Quote:
Originally Posted by Dan Korn View Post
Code:
var widthInPoints = FindTextFrame(FusionPro.Composition.CurrentFlow.name).GetSettableTextWidth() / 100; 
return CopyfitLineWithMagnifyTag('<f name="Arial">' +
            '<z newsize=12>' + TaggedDataField("Address"), widthInPoints);
Although if you're doing that, it's probably easier just to turn on full-flow Copyfitting for the flow and check the "Do not break on Copyfit" box in the Paragraph Formatting dialog.
__________________
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
Reply

Tags
javascript, rules

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 03:31 AM.


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