Jump to content

CopyFit/Scale inline graphic??


Recommended Posts

Hello All,


I need to insert a graphic next to (after) a variable text field. The text and graphic need to CopyFit (or similar function) so that both stay in the text frame. Further, the graphic needs to get the same scalling factor as the text.


Any suggestions on how to accomplish this are greatly appreciated.



Link to comment
Share on other sites

FusionPro doesn't actually apply copyfitting to inline graphics. However, it's possible to capture the magnification factor that copyfitting is applying to the text and use it to specify corresponding width and/or height attributes in the <graphic> tag. If you could post the job (or at least a minimal example with the text frame in question), then I, or someone else, might be able to offer more specific help.
Link to comment
Share on other sites

Thanks for the reply Dan. I would like to know how to go about this. The attached example has the variable field and then an graphic returned to the text field. Make believe that the graphic lines up with the text and that its height matches the point size of the text. The goal is that as the contents of the text frame exceed the frame, both the text and the graphic would scale the same % to stay within the frame.


Link to comment
Share on other sites

Try this as the OnCopyfit rule:

var GraphicFile = "Patchlogo.pdf"; // <- change the graphic name here
var CopyfitAttributes = new MagnifyAttributes("text", 25, 400, 6, 72); // <- change properties here

var BaseGraphicTag = '<graphic file="' + GraphicFile + '" />';

// Get graphic dimensions:
var TM = new FusionProTextMeasure;
TM.useTags = true;
var err = TM.CalculateTextExtent(BaseGraphicTag);
if (err)
   throw "Error measuring graphic: " + GraphicFile + ": " + TM.messages;
//Print(GraphicFile + ": Width=" + TM.textWidth + ", Depth=" + TM.textHeight);
//return GraphicFile + ": Width=" + TM.textWidth + ", Depth=" + TM.textHeight;
var BaseGraphicWidth = TM.textWidth;
var BaseGraphicHeight = TM.textHeight;

var OriginalContentNoEndPara = FusionPro.Composition.CurrentFlow.content.replace(/\<\/para\>$/, '');
FusionPro.Composition.CurrentFlow.content = OriginalContentNoEndPara + BaseGraphicTag + '</para>';

var BaseGraphicTag = '<graphic file="' + GraphicFile + '" />';

// Copyfit with base graphic to get magnification factor:
if (!Copyfit(CopyfitAttributes))
   throw "Could not copyfit text in flow " + FusionPro.Composition.CurrentFlow.name;


var magnifyFactor = 100;
var matches = FusionPro.Composition.CurrentFlow.content.match(/factor\=\"(\d+)\"/);
if (matches && matches.length > 1)
   magnifyFactor = Int(matches[1]);
Print("magnifyFactor=" + magnifyFactor);
//return magnifyFactor;

// "fudge" factor to account for the graphic not being magnified with the text originally
if (magnifyFactor != 100)
 magnifyFactor *= 1.3;

var MagnifyTags = "";
var matches = FusionPro.Composition.CurrentFlow.content.match(/^(\<magnify.*\>)\<para/);
if (matches && matches.length > 1)
   MagnifyTags = matches[1];
//Print("MagnifyTags=" + MagnifyTags);
//return MagnifyTags;

// Apply magnification factor to graphic:
var MagnifiedGraphicTag = '<graphic file="' + GraphicFile  + '"' +
                           ' width="' + Round(magnifyFactor / 100.0 * BaseGraphicWidth) + '"' +
                           ' height="' + Round(magnifyFactor / 100.0 * BaseGraphicHeight) + '" />';

FusionPro.Composition.CurrentFlow.content = MagnifyTags + OriginalContentNoEndPara + "\n" + MagnifiedGraphicTag + '</para></magnify>';

// Copyfit again with adjusted graphic to get best fit:
FusionPro.Composition.CurrentFlow.expandToFill = true;
if (!Copyfit(CopyfitAttributes))
   throw "Could not copyfit text in flow " + FusionPro.Composition.CurrentFlow.name;

return FusionPro.Composition.CurrentFlow.content;

Link to comment
Share on other sites



Thanks for all the work. As I have a solution, I will not ask you to pound on it any further. In my testing, it seemed very twitchy. I often saw the graphic reducing while the text was enlarging. Still, impressive what you can manipulate within this environment.





Link to comment
Share on other sites


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

  • Create New...