View Single Post
  #1  
Old July 29th, 2010, 03:30 PM
teresas teresas is offline
Junior Community Member
 
Join Date: Jun 2010
Location: Chicago
Posts: 17
Question HELP!!! Copyfit Rule w/ Multiple Styles & Leading Issues

I have a template where there I'm using a copyfitline rule that needs some help. There are three fields with line breaks in between in one text frame (did it this way so lines would suppress if empty). I used a copyfit rule for each field with specific values for a max and min font size (using a regular copyfitting rule was making everything the same size).

The problem came with the leading; when there was a large font over a small font, the leading wasn't being adjusted (copyfitting defaults to 120% the point size regardless of the line above), so the descenders in the large line were hanging into the smaller line below it.

I changed my rule to look for descenders in the line above, find their height in point size (knowing what percentage the descenders are of the total point size) and add it to the leading of the next field.

My problem now is that if the second variable breaks to more than one line, it retains that extra leading.

What I need: I need to find a way to tell it to only apply the extra leading to the line directly beneath the large line.

What I'm thinking: searching for when the line breaks during copyfitting and telling it not to use the additional leading.

Is there a way to do that? Is there some easier way to do this that I'm not seeing? PLEASE HELP!!! Any help would be greatly appreciated. I'm going crazy.

THE CODE:
Code:
var heading = Field("itemHeading");
var subHeading = Field("itemSubHeading");
var desc = Field("itemDescription");
var totalText;
var prevLine;
var descenders = /Q|q|y|p|g|j/
var lead = 0; //used to fix leading in copyfit

// adjust heading copyfit
heading = CopyfitLineHorizontal(heading, "Adobe Garamond Pro Bold", 65, 370, 60, 0, false);
totalText = heading;

if (subHeading != ""){
// handle subHeading copyfit
    subHeading = CopyfitLineHorizontal(subHeading, "Adobe Garamond Pro Bold", 20, 740, 16, 22, false, true); 
  
    totalText = totalText + "<br>" + subHeading;}
if (desc != ""){
// handle description copyfit
    desc = CopyfitLineHorizontal(desc, "Adobe Garamond Pro Bold", 14, 740, 12, 13, false, true); 
    totalText = totalText + "<br>" + desc;}

return totalText;

// Copyfiting
    // str = data field containing the string to alter
    // font = the font (put it in quotes) using the name that FusionPro recognizes
    // size = the original point size you want to use
    // width = width of the text area you want to fit measured in points (72 pts = 1 in)
    // minimum = the smallest point size you want the text to be in.
    // maximum = the largest point size you want the text to be in (if none, put 0)
    // justwidth = enter true if you want the text to be "narrowed" down to the "minimum" sized entered, enter false if you want the actual font size shrunk.
    // set justwidth to true for horizontal scaling, false for changing point size
    // fixLead = true if leading needs adjusting

function CopyfitLineHorizontal(str, font, size, width, minimum, maximum, justwidth, fixLead)
{
  var tm = new FusionProTextMeasure;
  tm.maxWidth = -1;
  if (maximum == "0"){
    maximum = 10000000;
  }
  var newsize, retcode, i;
  var  trackInt = new Array(0, -1, -2, -3, -4, -5);
 
  basetags = "<f name=\"" + font + "\">";
  newsize = size;
  i = 0;
 
  do
  {
    tags = basetags;
    tags += (justwidth) ? "<setwidth " : "<z ";
    tags += "newsize=" + newsize + "><tracking newsize=" + trackInt[i] + ">" + str;
    retcode = tm.CalculateTextExtent(tags);
    (i < 5) ? i++ : i=5;
    if (tm.textWidth > width * 100)
       newsize -= 0.1;
  } while (newsize <= maximum && newsize > minimum && tm.textWidth > width*100 && retcode == 0);
  // stores leading to add for next line
    if(fixLead && (prevLine.search(descenders) > -1)){
        var origLead = newsize*1.2;
        var newLead = (origLead + lead)*10;
        tags = "<leading newsize=" + newLead + ">" + tags +"</leading>";
    }
    lead = .269*newsize;  // stores leading to add for next line
    prevLine = str;
  return tags; // + " " + tm.textWidth + " " + width*100;
}
Using FusionPro Desktop 7.0P1c with Windows7
Reply With Quote