Jump to content

Change Font with Copyfit Rule


hkenney

Recommended Posts

if (!Copyfit(new MagnifyAttributes("text", 8, 70, 8, 70)))

{

FusionPro.Composition.CurrentFlow.content = '<span font="Gotham Condensed Medium">' + FusionPro.Composition.CurrentFlow.content + '</span>';

ReportWarning("Could not copyfit text in flow " +

FusionPro.Composition.CurrentFlow.name);

}

 

 

I used this rule to change the font of a single variable field on the back of a business card(and it worked like a charm) but now I want to apply it to a single line(the email field) on the front. This field is included in a frame with four other lines that I don't wish to adjust. When I try to write a CopyFitLine rule I receive an error message that <Arial> is not loaded but I am not using arial anywhere in this job.

Link to comment
Share on other sites

if (!Copyfit(new MagnifyAttributes("text", 8, 70, 8, 70)))
{
        FusionPro.Composition.CurrentFlow.content = '<span font="Gotham Condensed Medium">' + FusionPro.Composition.CurrentFlow.content + '</span>';
        ReportWarning("Could not copyfit text in flow " + 
                          FusionPro.Composition.CurrentFlow.name);
}

 

I used this rule to change the font of a single variable field on the back of a business card(and it worked like a charm) but now I want to apply it to a single line(the email field) on the front.

Be careful when you adjust the OnCopyfit callback to modify the content of a text flow. I'm glad that code worked for you, but that code affects every text frame that you have set to copyfit – not just the single variable on the back. Meaning: if one of the other frames within that template was unable to copyfit the contents using the parameters you have set, the font would be changed as well.

 

Speaking of which, changing the font after failing to copyfit the text is not ideal either. While I (think I) understand that you're wanting to use a "condensed" font if the text doesn't fit, changing the font after the function has run on what I assume is a non-condensed version of the font will result in a smaller font size (i.e. the point size of a condensed font may not need to be reduced as much as it's non-condensed counterpart to fit within the frame) and still does not guarantee the text was not truncated despite condensing the font. I think you'd want to copyfit both fonts in that scenario:

if (!Copyfit(new MagnifyAttributes("text", 8, 70, 8, 70))) {
   // If it doesn't fit, change the font to condensed and try again
   FusionPro.Composition.CurrentFlow.content = '<span font="Gotham Condensed Medium">' + FusionPro.Composition.CurrentFlow.content + '</span>';
   if (!Copyfit(new MagnifyAttributes("text", 8, 70, 8, 70))) {
       ReportWarning("Could not copyfit text in flow " + FusionPro.Composition.CurrentFlow.name);
   }
}

This field is included in a frame with four other lines that I don't wish to adjust. When I try to write a CopyFitLine rule I receive an error message that <Arial> is not loaded but I am not using arial anywhere in this job.

Including an example of what you're working with (at the very least) would be helpful. Perhaps if you included the CopyfitLine rule that you wrote in your post, we could make sense of the error that you received. I'm assuming that error appeared when you ran the job and not when you validated your rule? Regardless, I believe you were on the right track with the CopyfitLine function. Depending on what you want the output to look like, you might even want to try the CopyfitEmail function. If you'd rather FP only adjust the width of the characters as opposed to the size of the characters you can do that like so:

var email = Field('email'); // Your email field
var font = 'Gotham Medium';
var condensedFont = 'Gotham Condensed Medium';
var size = 12; // font size (in points)
var minSize = 8; 

try {
   var width = FusionPro.inValidation ? 72 : GetSettableTextWidth(FindTextFrame(FusionPro.Composition.CurrentFlow.name))/100;
} catch (e) {
   return 'Remember to name this text frame & set the rule to "Re-evaluate for every text flow"';
}

return CopyfitLine("", email, font, size, width, minSize, true);

 

If you want to change the font to "condensed" if the line has been copyfitted to the smallest allowed pointsize, you can do this:

var email = Field('email'); // Your email field
var font = 'Gotham Medium';
var condensedFont = 'Gotham Condensed Medium';
var size = 12; // font size (in points)
var minSize = 8; 

try {
   var width = FusionPro.inValidation ? 72 : GetSettableTextWidth(FindTextFrame(FusionPro.Composition.CurrentFlow.name))/100;
} catch (e) {
   return 'Remember to name this text frame & set the rule to "Re-evaluate for every text flow"';
}

var result = CopyfitLine("", email, font, size, width, minSize);

if (new RegExp('newsize=' + minSize + '.0').test(result))
   result = CopyfitLine("", email, condensedFont, size, width, minSize);

return result;

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