Jump to content

Copyfit Callback


Recommended Posts

We have a need for a callback function after copyfitting has taken place. We would like to modify other elements based on the size of text after a copyfit has taken place by determining the output size of the text. In some cases there are strict guidelines that dictate what percent ratio relationship one element will have with another element.

 

For example:

 

A headline element is copyfitted to 100 pt and a description element should be 75% of the 100 pt. But if the headline was copyfitted to 99 pt then the description element should be 50% od the 99 pt.

 

I believe a callback that reported the various output properties of the copyfitted text would be most useful here.

Link to comment
Share on other sites

We have a need for a callback function after copyfitting has taken place. We would like to modify other elements based on the size of text after a copyfit has taken place by determining the output size of the text. In some cases there are strict guidelines that dictate what percent ratio relationship one element will have with another element.

 

For example:

 

A headline element is copyfitted to 100 pt and a description element should be 75% of the 100 pt. But if the headline was copyfitted to 99 pt then the description element should be 50% od the 99 pt.

 

I believe a callback that reported the various output properties of the copyfitted text would be most useful here.

 

Are these multiple "elements" in separate text frames, or all in the same frame? Either way, this functionality is possible with the current product (FusionPro 3.2 or newer), although the enhancements to expose frame properties to JavaScript in FusionPro 6.0 make it easier.

 

If they're in the same frame, you're probably using the CopyfitLine function or something similar to copyfit just the headline, in which case you could modify the logic here to expose the magnification factor, like so:

 var factor = 0; // expose this variable outside of the 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;

   factor = Round(widthInPoints / tm.textWidth * 10000, 0) - 1;
   return "<magnify type=setwidth factor=" + factor + ">" +
           line + "</magnify>";
 }

 // If you're using FusionPro 6.0 or later, put the
 // name of the text frame (flow) here:
 // If you're using a version earlier than FusionPro 6.0,
 // you'll need to hard-code the column width here:
 var ColumnWidthInPoints = FindTextFrame("Story").GetSettableTextWidth() / 100;

 var headlineResult = "";
 var descriptionResult = "";
 headlineResult += CopyfitLineWithMagnifyTag(NormalizeEntities(Field("Headline")),
   ColumnWidthInPoints, false);
 var newFactor = (factor && factor < 100) ? 75 : 50;
 descriptionResult = '<magnify type="text" factor="' + newFactor + '">' +
   NormalizeEntities(Field("Description")) + "</magnify>";
 return headlineResult + "<br>" + copyfitResult;

If the two "elements" are in different frames, you can use this same strategy by moving the declarations of the "factor", "headlineResult", and "descriptionResult" variables to the JavaScript Globals, moving most of the rest of the logic to OnRecordStart, and using the results in two different text rules, one for each frame.

 

-----

 

You might also be able to do something like this even if you're employing "full" copyfitting via the OnCopyfit rule by capturing the magnification factor in effect, with some logic like this at the end of your OnCopyfit rule:

var s = FusionPro.Composition.CurrentFlow.content;
var factor = parseFloat(s.match(/factor=\"([\d|\.]+)\"/)[1]);

However, this (last bit) probably won't work, since one flow's copyfit logic cannot be dependent upon another's, because the order in which copyfitting is applied to multiple text flows is undefined, and without some other highly complicated way to define such dependencies, I don't see any realistic enhancement to change that. So, I would consider moving everything into one frame if it's not already that way.

 

If your job is too complex to change in this way, then there's probably still a way to make this work with more custom JavaScript logic, but I couldn't tell you exactly what to do without further analysis of the specific requirements of your job, and that level of custom template-building would be beyond the scope of what I can do in the context of this forum. But hopefully this will at least point you in the right direction.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...