Jump to content

copyfit by textwidth and then by font size


Recommended Posts

I need to copyfit a line first by horizontally scaling it If it exceeds max scaling amount, then I need to reduce the font size.

Copy needs to fit onto one line.

There would be several lines of text in the frame, the copyfitting can only apply to specifc lines of text.

 

So far, I've come up with this, but it does not work. It only horiz scales.

 

var thirdname = ToUpper(Field("Available third line"))

 

//apply horiz scaling to font at 2100.

var thirdnameWidth = CopyfitLineWithMagnifyTag('<f name="Pluto Bold">' + '<z newsize=221>' +thirdname, 2100);

 

//calculate the horizwidth of thirdnamewidth

TM = new FusionProTextMeasure;

TM.CalculateTextExtent(thirdnameWidth);

 

//if width is greater than 2100, return horizscaled type and reduce font size to fit frame width of 1400

 

if (TM.textWidth > 2100)

 

return CopyfitLineBasic(thirdnameWidth, "Pluto Bold", 221, 1400, 50, "fontSize");

else return thirdnameWidth;

Link to comment
Share on other sites

Here are the two functions, and attached a FP 8.2.7 PDF file.

see RULE_copyfit_3rdname_widthANDsize

 

function CopyfitLineBasic(lineContent, font, defaultSize, maxWidth, minimumSize, copyfitBy)

 

{

var tm = new FusionProTextMeasure;

 

tm.maxWidth = -1;

var newsize, retcode;

basetags = "<f name=\"" + font + "\">";

newsize = defaultSize;

 

do

 

{

tags = basetags;

 

if (copyfitBy == "fontSize")

{

tags += "<z ";

}

else if (copyfitBy == "fontWidth")

{

tags += '<setwidth "';

}

tags += "newsize=" + newsize + ">" + lineContent;

retcode = tm.CalculateTextExtent(tags);

 

if (tm.textWidth > maxWidth * 100)

 

newsize -= 0.1;

 

} while (newsize > minimumSize && tm.textWidth > maxWidth*100 && retcode == 0);

 

return tags; // + " " + tm.textWidth + " " + maxWidth*100;

 

}

CopyfitbyLineMagnifytest.zip

Link to comment
Share on other sites

Here is the 2nd function

 

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

}

Link to comment
Share on other sites

Here are the two functions, and attached a FP 8.2.7 PDF file.

I appreciate you attaching the collected job. Unfortunately, though, none of the rules work for me at all since I don't have the font "Pluto Bold" installed. Please do not attach fonts to this public forum, though. I'll see if I can figure it out using standard fonts.

Link to comment
Share on other sites

Okay, so I see a few problems. First, you're not specifying the same "width" to both the CopyfitLineWithMagnifyTag and CopyfitLineBasic functions.

 

You're also getting the units wrong. The main problem is here:

if (TM.textWidth > 2100) // wrong, units are different!

The "2100" is supposed to be the frame width in points. But TM.textWidth is in hundredths of points. So to compare those, you either need to divide TM.textWidth by 100 to get that in points, or multiply the 2100 by 100 to get that in hundredths of points. So change that line to this:

if (TM.textWidth > 210000) // compare as hundredths of points

And things should work. (Although an even better way to do this, instead of hard-coding the width of the frame, is to check the "Re-evaluate this rule for every text flow" box, and get the frame width programatically.)

 

However, with that problem fixed, you should see the other problem, which is that that condition is always true, because CopyfitLineWithMagnifyTag always shrinks the text enough to fit, so you never get to the call to CopyfitLineBasic (the "then by font size" part).

 

In your original post, you say:

I need to copyfit a line first by horizontally scaling it If it exceeds max scaling amount, then I need to reduce the font size.

But what is this "max scaling amount," and where is it specified in the rule? Although I think what you really mean is a "minimum scaling factor," e.g. "Scale no less than 50 percent." The CopyfitLineWithMagnifyTag function doesn't have any concept of a "minimum scaling factor." One could be added, and I could probably help with that as well, but I think you should go back and try the changes I already suggested and see if those give you the results you want.

Link to comment
Share on other sites

Thank you Dan. I appreciate you expertise.

I adjusted the rule.

I get the scaled size.

I do not get the font to reduce size as needed.

 

RULE_copyfit_3rdname_widthANDsize

 

if (Field("Available third line") !="")

{

var thirdname = ToUpper(Field("Available third line"))

var thirdnameWidth = CopyfitLineWithMagnifyTag('<f name="Pluto Bold">' +

'<z newsize=221>' +thirdname, 2100);

//The frame with is actually 1400. I do not want it to scale that much, so I made the frame widith in the rule 2100

 

 

TM = new FusionProTextMeasure;

TM.CalculateTextExtent(thirdnameWidth);

 

if (TM.textWidth > 210000) // compare as hundredths of points

 

return CopyfitLineBasic(thirdnameWidth, "Pluto Bold", 221, 1400, 50, "fontSize");

else return thirdnameWidth;

CopyfitbyLineMagnify.pdf

Link to comment
Share on other sites

Dan, do you have any further suggestions from my last post on June 9?

Sorry, I don't. Although you still have not answered this question:

But what is this "max scaling amount," and where is it specified in the rule?

What is the minimum factor by which you wish to horizontally scale the text before reducing the point size?

Link to comment
Share on other sites

According to the rule, I believe the max scaling amount would be 2100.

i.e.

var thirdnameWidth = CopyfitLineWithMagnifyTag('<f name="Pluto Bold">' +'<z newsize=221>' +thirdname, 2100);

if (TM.textWidth > 210000) // compare as hundredths of points

So... You're saying that if the result of the first copyfit (shrinking the setwidth) is larger than 2100 points, then reduce the font size? And while doing so, keep the existing ratio of point size (text height) to text width (setwidth) from the first copyfit operation? Or start over and just reduce point size?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...