Dan: Reading this through, here's a follow-up question:
The function uses takes a width as a parameter. Is there a function or property that can return the width of a specified text container at run time, so that widthInPoints could be controlled by a variable? Or do you just need to know how big your text box is, and plug that value (in points) into the rule that calls this function?? Thanks again, -- andy -- -----Original Message----- From: Dan Korn [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 19, 2007 10:04 AM To: FusionPro Users Forum Subject: [fusionpro] RE: Rule to copyfit a variable to one line?? Hi Andy, If you want to fit text to a single line, you can just use the CopyfitLine function. If you want to fit to a different number of lines, you will need to roll your own copyfit logic using the FusionProTextMeasure object. Basically, most copyfitting involves iterations of measuring some text, then modifying its size and measuring again, until it fits. The <magnify> tag can be very helpful in this regard. Here's a function that should work: function CopyfitToLines(text, widthInPoints, numLines, magnifyType) { var MagnifyType = magnifyType || "text"; var NumLines = Int(numLines) || 1; var tm = new FusionProTextMeasure; tm.maxWidth = widthInPoints*100; var retcode = 0; var factor = 100; var tags = text; for (var factor = 100; factor >= 10; factor--) { if (factor != 100) tags = "<magnify type=" + MagnifyType + " factor=" + factor + ">" + text + "</magnify>"; retcode = tm.CalculateTextExtent(tags); if (tm.messages) ReportError("CopyfitLines: " + tm.messages); if (retcode != 0) break; if (tm.textLines <= NumLines) return tags; } ReportWarning("CopyfitLines failed to fit the text"); return text; } The last two parameters are optional. Note that the font name, point size, and anything else affecting the measurement must be specified in the tags. Here's an example of calling it: var text = "<f name=Arial><z newsize=36>" + Field("FName") + " " + Field("Lname") + " of " + Field("City") + ", " + Field("State"); return CopyfitToLines(text, 200, 2); Dan +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Calling all FP Web Users! Do you have a question or lots of knowledge to share about FusionPro Web? If so, join our Printable Web to Print Users' Forum today! Send email to [EMAIL PROTECTED] to find out how! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- -- Users of FusionPro Desktop have unlimited free email support. Contact Printable Support at [EMAIL PROTECTED] -- View FusionPro Knowledge Base, FusionPro Samples at www.printable.com/vdp/desktop.htm -- You are currently subscribed to fusionpro as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] -- -- Note: All e-mail sent to or from this address will be received or otherwise recorded by the e-mail recipients of this forum. It is subject to archival, monitoring or review by, and/or disclosure to someone other than the recipient. Our privacy policy is posted on www.printplanet.com -- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- Calling all FP Web Users! Do you have a question or lots of knowledge to share about FusionPro Web? If so, join our Printable Web to Print Users' Forum today! Send email to [EMAIL PROTECTED] to find out how! +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- -- Users of FusionPro Desktop have unlimited free email support. Contact Printable Support at [EMAIL PROTECTED] -- View FusionPro Knowledge Base, FusionPro Samples at www.printable.com/vdp/desktop.htm -- You are currently subscribed to fusionpro as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] -- -- Note: All e-mail sent to or from this address will be received or otherwise recorded by the e-mail recipients of this forum. It is subject to archival, monitoring or review by, and/or disclosure to someone other than the recipient. Our privacy policy is posted on www.printplanet.com --
