Jump to content

Default Font Size to remain at Min if Copyfit does not fit.


jl_arnold

Recommended Posts

I've been struggling to find a way to keep my font size at the minimum font if copyfit does not fit.

 

The way I see copyfit working in my template, one of three outcomes occur:

 

1) Text fits, copyfit not needed. No font sizing adjustments.

2) Text exceeds frame. Copyfitting is used, reducing font as needed until minimum font size is met. In this specific scenario, the reduced font size fits the frame, so copyfitting is successful.

3) Text exceeds frame (by a lot). Copyfitting fails. Text output displayed at default.

 

 

I'm trying to fix scenario #3 so when copyfit is used, the font will always stay at the minimum size and will not increase back to default on Copyfit fail.

 

Does this make sense?

Zip file included just in case.

CCHMC Newsletter_BluePurple_FINAL.zip

Link to comment
Share on other sites

Technically speaking, failure to copyfit is not necessarily indicative of the text not fitting within the text flow at the specified minimum font size. The Copyfit function also takes into account the min/max magnification factors and if the minimum magnification factor is reached before the minimum font size, copyfit will fail.

 

That said, if you want to set the font size to the lower limit whenever there text does not fit, you can try this:

var minSize = 6;
if (!Copyfit(new MagnifyAttributes("text", 25, 400, minSize, 72))) {
   var cf = FusionPro.Composition.CurrentFlow;
   cf.content = '<para><span pointsize="' + minSize +'">' + cf.content + '</span></para>';
   ReportWarning("Could not copyfit text in flow " + cf.name);
}

Link to comment
Share on other sites

  • 3 weeks later...

Hey Step,

 

This seemed to be working just fine, but I think I've actually found a small issue that I think you'll be able to help.

 

The issue I am having is that I am trying to set a minimum font and minimum leading. I have modifed the code you provided, with the code from your Copyfit Text and Leading post (http://forums.printable.com/showthread.php?t=4071&highlight=font+size+leading).

 

 

I think I'm having a similiar issue you had. What I'm trying to accomplish is if the text does not fit the frame, then the font is reduced. Once the pointsize or leading is reduced and cannot copyfit anymore, I want to use my minimum values for pointsize and leading, which are not proportional, but set values.

 

 

I've attempted the following two codes.

 

if (FusionPro.Composition.CurrentFlow.name == "MyTextFrame")
{
var cf = FusionPro.Composition.CurrentFlow;
if (!cf.fits)
   cf.content = '<span pointsize="' + minSizeCaption +'"><leading newsize="' + leadingSizeCaption + '">' + cf.content + '</leading></span>';
if (!Copyfit(new MagnifyAttributes("text", 25, 400, 7, 8.5),new MagnifyAttributes("leading", 25, 400, 10, 12)))
cf.content = '<span pointsize="' + minSizeCaption +'"><leading newsize="' + maxleadingSizeCaption + '">' + cf.content + '</leading></span>';
   ReportWarning("Could not copyfit text in flow " +
                 FusionPro.Composition.CurrentFlow.name);
}

 

 

This works for both to an extent, but if I enter 200 characters and only 100 are visible with copyfit, than the text will reduce to the minimum size but the leading ends up being 12 point.

 

 

So I made a change to this code:

 

if (FusionPro.Composition.CurrentFlow.name == "MyTextFrame")
{
// default settings
var pointsize_min = 7;
var pointsize_max = 8.5;
var leadsize_min = 10;
var leadsize_max = 12;
var mag_min = 25;
var mag_max = 400;
var leadmag_min = 25;
var leadmag_max = 400;

var cf = FusionPro.Composition.CurrentFlow.content;
cf = cf.replace(/<variable name="([^"]*)">/g,function(a,b){return RuleOrField(b);});

var keys = ["pointsize", "z newsize"];
var find = '(' + keys.join("|") + ')\\s?=\\s?"?\\d*';
var pointsize = cf.match(new RegExp(find, 'gi')) || [];
// Remove dups
pointsize = pointsize.filter(function(item, pos) {return pointsize.indexOf(item) == pos;});
// Make them numeric values
pointsize = pointsize.map(function(s){s = s.replace(/[^\d]/g,''); return StringToNumber(s);});
// Sort in ascending order
pointsize = pointsize.sort(function(a,b){return (a > b) ? 1 : (a < b) ? -1 : 0;});

if (pointsize.length > 1) {
   var smallest = pointsize[0];
   var largest = pointsize[pointsize.length-1];
   mag_min = Round((pointsize_min/smallest)*100,0);
   mag_max = Round((pointsize_max/largest)*100,0);
}

var leadkeys = ["leading", "z newsize"];
var leadfind = '(' + leadkeys.join("|") + ')\\s?=\\s?"?\\d*';
var leadsize = cf.match(new RegExp(leadfind, 'gi')) || [];
// Remove dups
leadsize = leadsize.filter(function(item, pos) {return leadsize.indexOf(item) == pos;});
// Make them numeric values
leadsize = leadsize.map(function(s){s = s.replace(/[^\d]/g,''); return StringToNumber(s);});
// Sort in ascending order
leadsize = leadsize.sort(function(a,b){return (a > b) ? 1 : (a < b) ? -1 : 0;});

if (leadsize.length > 1) {
   var leadsmallest = leadsize[0];
   var leadlargest = leadsize[leadsize.length-1];
   leadmag_min = Round((leadsize_min/leadsmallest)*100,0);
   leadmag_max = Round((leadsize_max/leadlargest)*100,0);
}

// If the font's already larger than max, don't allow Copyfit it to increase it
leadmag_max = (largest > leadsize_max) ? 100 : mag_max;
// If the font's already smaller than the min, don't allow Copyfit it to shrink it
leadmag_min = (smallest < leadsize_min) ? 100 : mag_min;

// If the font's already larger than max, don't allow Copyfit it to increase it
mag_max = (largest > pointsize_max) ? 100 : mag_max;
// If the font's already smaller than the min, don't allow Copyfit it to shrink it
mag_min = (smallest < pointsize_min) ? 100 : mag_min;

if (!Copyfit(new MagnifyAttributes("text", mag_min, mag_max, pointsize_min, pointsize_max),new MagnifyAttributes("leading", leadmag_min, leadmag_max, leadsize_min, leadsize_max)))
cf.content = '<span pointsize="' + minSizeCaption +'"><leading newsize="' + leadingSizeCaption + '">' + cf.content + '</leading></span>';
   ReportWarning("Could not copyfit text in flow " +
                 FusionPro.Composition.CurrentFlow.name);
}

 

 

 

This second code works, as long as the text does not exceed the number of characters that can be copyfit. Meaning if 100 characters can be copy, my text is reduced to match minimum leading and pointsize. However, if I enter 101 characters, the text is displayed at the Max point size and Max leading.

 

I want to modify this code so that if anything text containing more characters than can be copyfit, to use the minimum for both point size and leading.

 

 

I have attached a PDF sample downloaded from MarcomCentral showing the textboxes in question as well as a zip of my template.

 

I have applied this Copyfit code to three text frames: FrontPhotoCaption, BackPhotoCaption-1 and BackPhotoCaption-2. These frames are found on page 1 and Page 4 of my template. In the sample provided, you will see two text sections on the bottom of the second page. The first section on the left has 239 characters and the right has 237. The right box adjusts the text correctly if the content needs to be adjusted.

 

 

 

I think the biggest issues I'm having is that the pointsize to leading is not proportional, and when the pointsize is reduced to the smallest size in, the text boxes I'm working with wouldn't fit any more text with the reduced leading, but my client wants to be sure the smallest pointsize and leading are both used if once copyfit reaches it minimum for either.

 

 

 

Thanks in advance for your help!

 

Jason

paad50hd.pdf

CCHMC Newsletter_BluePurple_FINAL.zip

Link to comment
Share on other sites

To be honest, I'm not really sure I understand the problem you're encountering. As far as I can tell, the text within all three frames you mentioned (FrontPhotoCaption, BackPhotoCaption-1, and BackPhotoCaption-2) fit.

 

 

The issue I am having is that I am trying to set a minimum font and minimum leading. I have modifed the code you provided, with the code from your Copyfit Text and Leading post (http://forums.printable.com/showthread.php?t=4071&highlight=font+size+leading).

 

 

I think I'm having a similiar issue you had. What I'm trying to accomplish is if the text does not fit the frame, then the font is reduced. Once the pointsize or leading is reduced and cannot copyfit anymore, I want to use my minimum values for pointsize and leading, which are not proportional, but set values.

If you aren't trying to keep the font size and leading proportional, there's no point in bothering with that code.

 

I've attempted the following two codes.

 

if (FusionPro.Composition.CurrentFlow.name == "MyTextFrame")
{
var cf = FusionPro.Composition.CurrentFlow;
if (!cf.fits)
   cf.content = '<span pointsize="' + minSizeCaption +'"><leading newsize="' + leadingSizeCaption + '">' + cf.content + '</leading></span>';
if (!Copyfit(new MagnifyAttributes("text", 25, 400, 7, 8.5),new MagnifyAttributes("leading", 25, 400, 10, 12)))
cf.content = '<span pointsize="' + minSizeCaption +'"><leading newsize="' + maxleadingSizeCaption + '">' + cf.content + '</leading></span>';
   ReportWarning("Could not copyfit text in flow " +
                 FusionPro.Composition.CurrentFlow.name);
}

This works for both to an extent, but if I enter 200 characters and only 100 are visible with copyfit, than the text will reduce to the minimum size but the leading ends up being 12 point.

In that code, you're setting the font size of the copy to 'minSizeCaption' before you even attempt to Copyfit the copy. And wrapping the copy in leading tags won't work here because FP's text editor has already stealthily added leading tags (and font tags, and color tags, etc) to the copy so that outer tag is useless. You can, however, replace the editor's values with the values you want to insert:

 

var minSize = 10;
var minLead = 10;

if (!Copyfit(new MagnifyAttributes("text", 25, 400, minSize, 13), new MagnifyAttributes("leading", 25, 400, minLead, 14))) {
   var cf = FusionPro.Composition.CurrentFlow;
   cf.content = '<para><span pointsize="' + minSize +'">'
     + cf.content.replace(/(quad="[A-Z]" )(leading="\d+")?/g, function(s,p) { return p + 'leading="' + minLead * 10 + '"'; })
     + '</span></para>';
   ReportWarning("Could not copyfit text in flow " + cf.name);
}

 

Rather than sift through the 628 lines (:eek:) of code in your OnCopyfit rule, I've attached a smaller sample that illustrates how the code works with 3 text frames.

sample.zip

Link to comment
Share on other sites

I think the issue may lay with MarcomCentral.

 

In the two back textboxes the left one has 500+ characters entered in the field while the textbox on the right has exactly 237.

 

I'm wanting 238+ characters to act the same as 237, but it doesn't.

 

I'll go through your code and example and let you know how it goes! It looks like it should help! Thanks!

 

Jason

Link to comment
Share on other sites

SteP!

 

Just wanted to thank you for providing that sample!!!! It worked great when entered with my existing codes after removing the first tags that were setting the sizing before copyfit.

 

 

 

I haven't fully tested every field in MarcomCentral yet but it seems to be working just as needed for all fields. I just had to play around with the Resources I had created, setting the Main Article Copy for the Front Only to override existing paragraph formatting.

 

I'm not sure what that setting has done in the past, but it seems to work INCREDIBLY now!! I have to take you for all your help and Javascript knowledge.

 

Thanks again!

Jason

Link to comment
Share on other sites

I'm really struggling with this now.

 

To simply everything, I have used your sample file.

 

 

The issue I am encountering is due to text frame flowing. The script you have provided takes into account the point size and leading, but this needs to be determined for two frames, where content can flow from frame 1 to frame 2, but even if content on frame 2 fills and there is room on frame 1, text can never flow from frame 1 to frame 2.

 

 

 

I am attaching your modified sample with the script I had created in my template.

 

I have not been successful modifying the code to all scenarios needed.

 

1) I am using resources to display the text.

2) The resources are returned as content in rules (set as front / back) to set which resource is front and which is back.

3) The rules are then returned as RawTextFromTagged in a rule called TextFlow, which joins the front and back copy with <p verticalstart="topofpage">

4) Linked frames (blue and magenta) display Rule(TextFlow)

 

 

How this should work:

1) if Frame 1 does not fill, start Resource 2 [Rule(Set back copy to back)] text on back

2) if Frame 1 fills, start a new paragraph with Resource 2.

3) If Frame 1 does not fill but Frame 2 does, copyfit text and leading, while keeping <p verticalstart="topofpage">.

4) If Frame 1 fills and frame 2 fills reduce font size and leading.

 

 

Honestly, I don't care if copyfit is set before replacing the vertical start for page 2. I'm just having all sorts of problems. Mainly when frame 2 fills, content flows to frame 1. Also I am not getting my font size to reduce to 9 points.

 

 

Can you take a look at this for me?

sample_copy-edit.zip

Link to comment
Share on other sites

The issue I am encountering is due to text frame flowing. The script you have provided takes into account the point size and leading, but this needs to be determined for two frames, where content can flow from frame 1 to frame 2, but even if content on frame 2 fills and there is room on frame 1, text can never flow from frame 1 to frame 2.

That doesn't make sense to me. Maybe you mistyped that description? As I understand it, the Copyfit function isn't concerned with text frames per se – but rather the text flow. A text frame (or frames) is used to determine if the content will fit but to FusionPro, linked text frames are one single text flow. So I'm not really sure that's the issue.

 

I have not been successful modifying the code to all scenarios needed.

 

1) I am using resources to display the text.

2) The resources are returned as content in rules (set as front / back) to set which resource is front and which is back.

3) The rules are then returned as RawTextFromTagged in a rule called TextFlow, which joins the front and back copy with <p verticalstart="topofpage">

4) Linked frames (blue and magenta) display Rule(TextFlow)

 

 

How this should work:

1) if Frame 1 does not fill, start Resource 2 [Rule(Set back copy to back)] text on back

2) if Frame 1 fills, start a new paragraph with Resource 2.

3) If Frame 1 does not fill but Frame 2 does, copyfit text and leading, while keeping <p verticalstart="topofpage">.

4) If Frame 1 fills and frame 2 fills reduce font size and leading.

 

 

Honestly, I don't care if copyfit is set before replacing the vertical start for page 2. I'm just having all sorts of problems. Mainly when frame 2 fills, content flows to frame 1. Also I am not getting my font size to reduce to 9 points.

 

 

Can you take a look at this for me?

It sounds like you've got quite a few moving parts but I'm not sure I understand the reasoning behind all of them. I don't understand why you need 2 rules that are set to "re-evaluate for every text flow" to return formatted text resources to yet another rule that's set to "re-evaluate for every text flow."

 

I think this thread has gotten a little off topic from your original question. Given the complexity of what it seems like you're trying to accomplish, you might consider outsourcing the template development to a contractor on the job board or contact FusionProSupport@PTI.com regarding paid consulting. At the very least, I would start a new thread for relevancy.

Link to comment
Share on other sites

Quote:

Originally Posted by jl_arnold http://forums.pti.com/images/buttons/viewpost.gif

The issue I am encountering is due to text frame flowing. The script you have provided takes into account the point size and leading, but this needs to be determined for two frames, where content can flow from frame 1 to frame 2, but even if content on frame 2 fills and there is room on frame 1, text can never flow from frame 1 to frame 2.

 

You are correct, that was a typo.. Here is the true flow:

1) Text Frame 1 fills and flows to frame 2.

2) Text Frame 1 does not fill. Text Frame 2 fills. Point size and leading reduced. Text Frame 2 should never flow to text frame 1.

 

 

 

 

I think this thread has gotten a little off topic from your original question. Given the complexity of what it seems like you're trying to accomplish, you might consider outsourcing the template development to a contractor on the job board or contact FusionProSupport@PTI.com regarding paid consulting. At the very least, I would start a new thread for relevancy.

 

 

I understand how it seems off topic, but I did have another thread about the text flow using the p tag for verticalstart="topofpage". And while your code did what I needed for the Min font size, I was also trying to set the minimum lead size which could not be done without a regex for replace.

 

 

 

I know where I need to modify my coding to get this to function how I need to, but I just don't know how to, or if it's possible.

 

Basically I have two separate replace functions going on in my Copyfit rule. I need them to work simultaneously, but they seem to work one, then the other.

 

var minSize = 9;
var leadingSizeBody = 14

if (FusionPro.Composition.CurrentFlow.name == "MainArticleBodyCopy1-3")
{
var cf = FusionPro.Composition.CurrentFlow;
// If it doesn't fit, don't start back page at "topofpage"
if (!cf.fits)
   cf.content = cf.content.replace(/<variable name="([^"]+)">/g, function(s,p) {
       return RuleOrField(p).replace('verticalstart="topofpage"', 'leadbefore="0"');
  });
           if (!Copyfit(new MagnifyAttributes("text", 80, 150, minSize, 10),new MagnifyAttributes("leading", 80, 150, leadingSizeBody, 15)))
                  cf.content = '<para><span pointsize="' + minSize +'">'
   + cf.content.replace(/(quad="[A-Z]" )(leading="\d+")?/g, function(s,p) { return p + 'leading="' + leadingSizeBody * 10 + '"'; })
   + '</span></para>';    
   ReportWarning("Could not copyfit text in flow " + 
                 FusionPro.Composition.CurrentFlow.name);
}

 

 

I don't know if if it's possible to combine the replace functions, but I thought I would ask you here anyway.

 

THanks,

Jason

Link to comment
Share on other sites

I know where I need to modify my coding to get this to function how I need to, but I just don't know how to, or if it's possible.

Right, well that's why I suggested contracting a developer to help.

 

Basically I have two separate replace functions going on in my Copyfit rule. I need them to work simultaneously, but they seem to work one, then the other.

Technically there are 3 replace methods but I'm going to assume you're referring to the one that replaces the 'verticalstart" attribute and the one that replaces the leading with the "leadingSizeBody." What do you mean you need them to work simultaneously? You can chain replace methods if that's what you're wanting to do (although I don't know why):

return '<p br="false" quad="L">First paragraph.'
    + '<p verticalstart="topofpage" quad="L">Second paragraph'
      .replace('verticalstart="topofpage"', '') 
      .replace(/(quad="[A-Z]" )(leading="\d+")?/g, function(s,p) {
         return p + 'leading="' + leadingSizeBody * 10 + '"';
       }); 
/*
 Returns:
 <p br="false" quad="L" leading="140">First paragraph.
 <p quad="L" leading="140">Second paragraph
*/

I think part of the reason for the confusion is stemming from syntax errors. Let's take a closer look at your code:

var minSize = 9;
var leadingSizeBody = 14

[color="Red"]if (FusionPro.Composition.CurrentFlow.name == "MainArticleBodyCopy1-3")
{[/color]
var cf = FusionPro.Composition.CurrentFlow;
// If it doesn't fit, don't start back page at "topofpage"
[color="Magenta"]if (!cf.fits)
   cf.content = cf.content.replace(/<variable name="([^"]+)">/g, function(s,p) {
       return RuleOrField(p).replace('verticalstart="topofpage"', 'leadbefore="0"');
  });[/color]
           [color="SeaGreen"]if (!Copyfit(new MagnifyAttributes("text", 80, 150, minSize, 10),new MagnifyAttributes("leading", 80, 150, leadingSizeBody, 15)))
                  cf.content = '<para><span pointsize="' + minSize +'">'
   + cf.content.replace(/(quad="[A-Z]" )(leading="\d+")?/g, function(s,p) { return p + 'leading="' + leadingSizeBody * 10 + '"'; })
   + '</span></para>';    [/color]
   ReportWarning("Could not copyfit text in flow " + 
                 FusionPro.Composition.CurrentFlow.name);
[color="red"]}[/color]

Everything within the red brackets executes if and only if the name of the text flow is "MainArticleBodyCopy1-3." The pink code checks to see if the content fits in the text flow (before attempting to copyfit) and if it doesn't, it replaces the first "verticalstart" attribute with "leadbefore=0." The green code (my apologies if you are red/green colorblind) attempts to copyfit the text flow by adjusting the font size and leading within the limitations you defined and if it can not, it wraps the entire content in span tags (to set the font size to the minimum) and applies the minimum leading to all 'p' tags. The "ReportWarning" part actually executes every time the "MainArticleBodyCopy1-3" text flow is processed. That's resulting in a false error so you might want to only do that if the copyfit fails – in which case you need to wrap that 'if' statement in brackets (because you're executing multiple lines of code):

if (!Copyfit(new MagnifyAttributes("text", 80, 150, minSize, 10), new MagnifyAttributes("leading", 80, 150, leadingSizeBody, 15))) [color="red"]{[/color]
 cf.content = '<para><span pointsize="' + minSize +'">' + cf.content.replace(/(quad="[A-Z]" )(leading="\d+")?/g, function(s,p) { return p + 'leading="' + leadingSizeBody * 10 + '"'; }) + '</span></para>';    
 ReportWarning("Could not copyfit text in flow " + FusionPro.Composition.CurrentFlow.name);
[color="Red"]}[/color]

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