PDA

View Full Version : A better CopyfitLine


Dan Korn
October 8th, 2008, 03:38 PM
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.

pklingler
October 20th, 2008, 03:00 PM
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, 03:15 PM
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 (http://www.printable.com/downloads/fusionpro) and see if you can reproduce the problem there. If so;
Contact Support (support@printable.com) and send them your job for analysis.