MarcomCentral (PTI) and FusionPro User Communities

MarcomCentral (PTI) and FusionPro User Communities (http://forums.pti.com/index.php)
-   Formatting Text (http://forums.pti.com/forumdisplay.php?f=32)
-   -   A better CopyfitLine (http://forums.pti.com/showthread.php?t=84)

Dan Korn October 8th, 2008 02:38 PM

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.

pklingler October 20th, 2008 02:00 PM

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?

Dan Korn October 20th, 2008 02:15 PM

Re: A better CopyfitLine
 
Quote:

Originally Posted by pklingler (Post 304)
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.

sandig@customprinters.com April 24th, 2014 04:31 PM

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.

MeeshKB October 17th, 2014 10:28 AM

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);


Dan Korn October 17th, 2014 11:14 AM

Re: A better CopyfitLine
 
Quote:

Originally Posted by sandig@customprinters.com (Post 14735)
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 October 17th, 2014 11:15 AM

Re: A better CopyfitLine
 
Quote:

Originally Posted by MeeshKB (Post 15637)
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".

MeeshKB October 17th, 2014 12:14 PM

Re: A better CopyfitLine
 
Quote:

Originally Posted by Dan Korn (Post 15639)
In the <magnify> tag, change "type=setwidth" to "type=pointsize".

Brilliant. Thanks so much, Dan. It's working like a charm.

jmerrick0657 August 19th, 2015 10:21 AM

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.

Dan Korn August 19th, 2015 11:05 AM

Re: A better CopyfitLine
 
Quote:

Originally Posted by jmerrick0657 (Post 17317)
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 (Post 15638)
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 (Post 15638)
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 (Post 15638)
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.


All times are GMT -7. The time now is 07:20 PM.

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