Jump to content

Copyfitting Issue


jmerrick0657

Recommended Posts

I'm having trouble with some copyfitting. Here is the code I am using:

 

var StaticPart = ""; //This text will not copyfit.

var DynamicPart = Rule("DetermineLogoLines"); //This text will copyfit.

var TextFont = "Formata Light";

var FontSize = 7.5;

var MinFontSize = 1;

var AdjustWidthOnly = false;

 

if (Rule("DetermineLogoLines") != "")

return CopyfitLine(StaticPart,DynamicPart,TextFont,FontSize, Round(Rule("LogoHeadingLength") / 100,0), MinFontSize, AdjustWidthOnly);

else

return "";

 

Based on the length of the first line of text, a right aligned tab is set, then the second two lines of text are copyfitted from the edge of the box to the point where the tab is.

 

This seems to be working when there is little or no copyfitting required. However when it needs to copyfit, the minimum font size is always returned.

Link to comment
Share on other sites

Oh, ok. If you would like to take a look at the job I have attached the zip file. I did change the copyfit rule to measure the length of the text field and divide by 99 instead of 100. That seems to work if there is not that much copyfitting.

Thanks. The job is a lot more complicated than I expected. It's very cleverly done, but I found it very difficult to trace through all of the different rules calling other rules (especially since the rules all have similar names).

 

I found it much easier to grok by combining all the logic into a single rule, with some of the code simplified, and a bit of debugging code added:

var Debug = [];
if (!Field("LogoHeading"))
   return "";

var TextFont = "Arial";

// DisplayLogoHeading
var frameWidth = FindTextFrame("LogoBox").GetSettableTextWidth() / 100;
var FontSize = 17.25;
var MinFontSize = 6;
var DisplayLogoHeading = CopyfitLine("", Field("LogoHeading"), TextFont, FontSize, frameWidth, MinFontSize);
Debug.push("DisplayLogoHeading is:\n" + DisplayLogoHeading);

// LogoHeadingLength
var TM = new FusionProTextMeasure;
TM.CalculateTextExtent(DisplayLogoHeading);
var LogoHeadingLength = TM.textWidth;
Debug.push("LogoHeadingLength is: " + LogoHeadingLength);

// DetermineLogoLines
var LogoLines = [Field("Logo1"), Field("Logo2")].filter(String).join('<br><t>');
if (!LogoLines.length)
 return "";
LogoLines = '<p br=false tabstops="0;' + LogoHeadingLength + ',Right,.,"><color name="PANTONE 7540 C" shading=70><t>' + LogoLines + '</color>';
Debug.push("DisplayLogoHeading is:\n" + LogoLines);

var frameWidth = LogoHeadingLength / 99;
var FontSize = 9.25;
var MinFontSize = 1;
var result = CopyfitLine("", LogoLines, TextFont, FontSize, frameWidth, MinFontSize);
Debug.push("result is:\n" + result);
if (FusionPro.inValidation)
   return Debug.join("\n\n");

return result;

Note that I'm using Arial because I don't have your fonts. (Please don't post proprietary fonts to this public forum.)

 

This allowed me to click Validate with the above code, then change the 99 to 100, and Validate again, and compare the results.

 

I think what's happening is that FusionPro has trouble setting the text to fit aligned to a tab stop that's exactly as wide as the text. It needs just the tiniest bit of "wiggle room." I got it to work by, instead of dividing by 99, subtracting 1 (hundredth of a point) from the calculated LogoHeadingLength to set the tab stop width. So my final rule is this:

var Debug = [];
if (!Field("LogoHeading"))
   return "";

var TextFont = "Arial";

// DisplayLogoHeading
var DisplayLogoHeading = Rule("DisplayLogoHeading");
Debug.push("DisplayLogoHeading is:\n" + DisplayLogoHeading);

// LogoHeadingLength
var TM = new FusionProTextMeasure;
TM.CalculateTextExtent(DisplayLogoHeading);
var LogoHeadingLength = TM.textWidth;
Debug.push("LogoHeadingLength is: " + LogoHeadingLength);

// DetermineLogoLines
var LogoLines = [Field("Logo1"), Field("Logo2")].filter(String).join('<br><t>');
if (!LogoLines.length)
 return "";
LogoLines = '<p br=false tabstops="0;' + (LogoHeadingLength - 1) + ',Right,.,"><color name="PANTONE 7540 C" shading=70><t>' + LogoLines + '</color>';
Debug.push("DisplayLogoHeading is:\n" + LogoLines);

var frameWidth = LogoHeadingLength / 100;
var FontSize = 9.25;
var MinFontSize = 1;
var result = CopyfitLine("", LogoLines, TextFont, FontSize, frameWidth, MinFontSize);
Debug.push("result is:\n" + result);
if (FusionPro.inValidation)
   return Debug.join("\n\n");

return result;

The other thing that I think isn't quite right about this is that the last call to the CopyfitLine function is actually measuring two lines of text, which, as its name ("CopyfitLine", singular) suggests, isn't exactly what it was designed to do. But it works anyway because it just examines the width of the full text, which is going to be the widest line's width.

 

Finally, keep in mind that most things that you do with tabs can also be done with tables. So this could be done by defining a table with a single cell, like so:

var Debug = [];
if (!Field("LogoHeading"))
   return "";

var TextFont = "Arial";

// DisplayLogoHeading
var DisplayLogoHeading = Rule("DisplayLogoHeading");
Debug.push("DisplayLogoHeading is:\n" + DisplayLogoHeading);

// LogoHeadingLength
var TM = new FusionProTextMeasure;
TM.CalculateTextExtent(DisplayLogoHeading);
var LogoHeadingLength = TM.textWidth;
Debug.push("LogoHeadingLength is: " + LogoHeadingLength);

// DetermineLogoLines
var LogoLines = [Field("Logo1"), Field("Logo2")].filter(String).join('<br><t>');
if (!LogoLines.length)
 return "";
LogoLines = '<color name="PANTONE 7540 C" shading=70>' + LogoLines + '</color>';
Debug.push("DisplayLogoHeading is:\n" + LogoLines);

var frameWidth = LogoHeadingLength / 100;
var FontSize = 9.25;
var MinFontSize = 1;
var content = CopyfitLine("", LogoLines, TextFont, FontSize, frameWidth, MinFontSize);
Debug.push("Content is:\n" + content);

var table = new FPTable;
table.AddColumn(LogoHeadingLength);
var cell = table.AddRow().Cells[0];
cell.HAlign = "Right";
cell.Content = content;
cell.Margins = { Top:0, Bottom:0, Left:0, Right:0 };
var result = table.MakeTags();

Debug.push("result is:\n" + result);
if (FusionPro.inValidation)
   return Debug.join("\n\n");

return result;

No "wiggle room" necessary!

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...