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>";
}