Dan Korn Posted October 8, 2008 Share Posted October 8, 2008 Here's a function I wrote to basically do what CopyfitLine does, using the <magnify> tag and a more efficient algorithm: 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: 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: 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. Quote Link to comment Share on other sites More sharing options...
pklingler Posted October 20, 2008 Share Posted October 20, 2008 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? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 20, 2008 Author Share Posted October 20, 2008 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:Download the newest version of FusionPro and see if you can reproduce the problem there. If so;Contact Support and send them your job for analysis. Quote Link to comment Share on other sites More sharing options...
sandigcustomprinters.com Posted April 24, 2014 Share Posted April 24, 2014 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. Quote Link to comment Share on other sites More sharing options...
MeeshKB Posted October 17, 2014 Share Posted October 17, 2014 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: 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); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 17, 2014 Author Share Posted October 17, 2014 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: return CopyfitLineWithMagnifyTag('<f name="Arial">' + '<z newsize=12>' + TaggedDataField("Address"), 360); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted October 17, 2014 Author Share Posted October 17, 2014 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". Quote Link to comment Share on other sites More sharing options...
MeeshKB Posted October 17, 2014 Share Posted October 17, 2014 In the <magnify> tag, change "type=setwidth" to "type=pointsize". Brilliant. Thanks so much, Dan. It's working like a charm. Quote Link to comment Share on other sites More sharing options...
jmerrick0657 Posted August 19, 2015 Share Posted August 19, 2015 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. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 19, 2015 Author Share Posted August 19, 2015 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: return CopyfitLineWithMagnifyTag('<f name="Arial">' + '<z newsize=12>' + [color="Green"]TaggedDataField("Address")[/color], 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: 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: 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. Quote Link to comment Share on other sites More sharing options...
jmerrick0657 Posted August 19, 2015 Share Posted August 19, 2015 Dan, Sorry; I meant text frame, not text field. The code you posted using the FindTextFrame and GetSettableTextWidth() functions works perfectly!! Thanks. Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted May 26, 2016 Author Share Posted May 26, 2016 They would like the field "Credentials" to be able to fill the remaining space in the top line, roll to the second line and have the ability to fill the entire second line. They want to be able to copyfit the text and spacing Width the field "Credentials" for the first two lines to a given %. Else return something like "Credential Do Not Fit". Well, first of all, a new thread should be used for a new question. And this isn't really supposed to be just the "Ask Dan" forum. Anyway, I'm not sure I understand the requirements. Under what specific criteria do the Credentials not fit? If First Name, Last Name, and Credentials/Certifications would fill more than two lines after shrinking a certain amount? Maybe some examples of what you expect to see with different data would be helpful. (Also, do you mean Credentials or Certifications?) Quote Link to comment Share on other sites More sharing options...
TroyM68 Posted May 26, 2016 Share Posted May 26, 2016 Sorry Dan, I thought this was similar to the thread. I will create a new post with more detail. Thanks! Quote Link to comment Share on other sites More sharing options...
sdthedawson Posted September 28, 2016 Share Posted September 28, 2016 I love and use this function all the time! However it has issues with specific characters being used like &, <, >. Here’s a simple fix for it that. It escapes the codes to HTML runs the copy fit calculations and then un-escapes the codes back. I am unable to fully test if the magnify factor is affected due to the HTML characters being more characters. Either way its worked well for me! function CopyfitLineWithMagnifyTag(line, widthInPoints, AllowToExpand) { var escapeCode = [ [/\&/g, "&", "&"], [/\</g, "<", "<"], [/\>/g, ">", ">"], [/\¢/g, "¢", "¢"], [/\£/g, "£", "£"], [/\¥/g, "¥", "¥"], [/\€/g, "?", "€"], [/\©/g, "©", "©"], [/\®/g, "®", "®"] ]; //Escape to HTML code for copyFit for(i=0;i<escapeCode.length;i++){ line = line.replace(escapeCode[i][0], escapeCode[i][2]); } var tm = new FusionProTextMeasure; tm.CalculateTextExtent(line); if (tm.messages){ ReportError("CopyfitMagnifyLine: " + tm.messages); } //Unescape HTML codes for(i=0;i<escapeCode.length;i++){ line = line.replace(escapeCode[i][2], escapeCode[i][1]); } 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>"; } Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 29, 2016 Author Share Posted September 29, 2016 I love and use this function all the time! However it has issues with specific characters being used like &, <, >. Here’s a simple fix for it that. It escapes the codes to HTML runs the copy fit calculations and then un-escapes the codes back. I am unable to fully test if the magnify factor is affected due to the HTML characters being more characters. Either way its worked well for me! You shouldn't need to do any of that as long as you pass tagged markup to the function in the first place, either by calling TaggedTextFromRaw or TaggedDataField, and set the rule to return tagged markup, as explained in previous posts in this thread. Quote Link to comment Share on other sites More sharing options...
ThePorge Posted February 11, 2021 Share Posted February 11, 2021 Dan, I've just starting using this function in a rule for a address block. Works so much faster than the other method. The rule works splendidly. However I'm getting copy fit errors when I compose my pdf even tho the output is correct. Is this the normal behavior? var Var1 = Field("FirstName") + " " +Field("LastName"); var Var2 = Field("Company"); var Var3 = Field("Address"); var Var4 = Field("Address2"); var Var5 = Field("City") + ", " + Field("State") + " " + Field("Zip"); var Var6; 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>"; } Var6 = CopyfitLineWithMagnifyTag('<f name="Percanthen">' + '<z newsize=30>' + Var1, 234, false) + "<p>" + CopyfitLineWithMagnifyTag('<f name="Percanthen">' + '<z newsize=30>' + Var2, 234, false) + "<p>" + CopyfitLineWithMagnifyTag('<f name="Percanthen">' + '<z newsize=30>' + Var3, 234, false) + "<p>" + CopyfitLineWithMagnifyTag('<f name="Percanthen">' + '<z newsize=30>' + Var4, 234, false) + "<p>" + CopyfitLineWithMagnifyTag('<f name="Percanthen">' + '<z newsize=30>' + Var5, 234, false); return Var6; FP 11.2.1 Acrobat Architecture: x86_64 Build: 20.13.20074.411690 AGM: 4.30.104 CoolType: 5.14.5 JP2K: 1.2.2.46820 Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 11, 2021 Author Share Posted February 11, 2021 I'm getting copy fit errors What errors specifically? Quote Link to comment Share on other sites More sharing options...
ThePorge Posted February 11, 2021 Share Posted February 11, 2021 Every record has these errors. Job started 13:09:40 - 1613066980. Creator: FusionPro® VDP Creator 11.2.1 Computer Name: Current working folder: /Applications/PTI/FusionPro Temporary files folder: /var/folders/x4/mjdwd7nj7hv8phtj8_ljm3mr0000gn/T/ Template File: /Volumes/Mac_Jobs/140911_GSG/VarableWork/140911_GSG-EnvFPExport Test.dif Input File: /Volumes/Mac_Jobs/140911_GSG/VarableWork/Links/140911_ListTest.csv Job Config File: /private/var/folders/x4/mjdwd7nj7hv8phtj8_ljm3mr0000gn/T/140911_GSG-Env-Test.cfg The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). Composing record #1, input record 1 The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). Composing record #2, input record 2 Quote Link to comment Share on other sites More sharing options...
ThePorge Posted February 11, 2021 Share Posted February 11, 2021 Just the text won't fit errors even tho it does. Job started 13:09:40 - 1613066980. Creator: FusionPro® VDP Creator 11.2.1 Computer Name: Current working folder: /Applications/PTI/FusionPro Temporary files folder: /var/folders/x4/mjdwd7nj7hv8phtj8_ljm3mr0000gn/T/ Template File: /Volumes/Mac_Jobs/140911_GSG/VarableWork/140911_GSG-EnvFPExport Test.dif Input File: /Volumes/Mac_Jobs/140911_GSG/VarableWork/Links/140911_ListTest.csv Job Config File: /private/var/folders/x4/mjdwd7nj7hv8phtj8_ljm3mr0000gn/T/140911_GSG-Env-Test.cfg The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). Composing record #1, input record 1 The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). Composing record #2, input record 2 Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 11, 2021 Author Share Posted February 11, 2021 (edited) Okay, well, what does fit? You probably either have the wrong frame width, or maybe the frame simply isn't big enough vertically. I'd have to see the job files to reproduce the problem and analyze it. Edited February 11, 2021 by Dan Korn Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted April 7, 2021 Author Share Posted April 7, 2021 This might be a symptom of case FP-356, which is fixed in FusionPro VDP 12.0.3. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.