Jump to content

Issue with textHeight property of the TextMeasure Object.


Recommended Posts

We have been using the method below for years to determine whether a piece is landscape or portrait for some handouts. Testing out FP11 and so far this is the only thing that I've noticed that is causing issues with our code.

var item = CreateResource(path("_graphics") + itemNumberFD,'graphic',true);

// Determine if the item graphic is landscape or portrait
formatFD = GetOrientation(item,localOrientation);

function GetOrientation(res, fallback){
 // Text Measure doesn't run in validation so set a fall back
 // orientation to return in local dev. If the param is null
 // return 'portrait' orientation
 var fallback = fallback || "portrait";
      if (!res instanceof FusionProResource)
        throw "Not a resource: " + res;

      if (!res.exists)
        throw "Resource not found: " + res;

      var TM = new FusionProTextMeasure;
      TM.useTags = true;

     var err=TM.CalculateTextExtent(res.content);
     if (err)
       throw "Error measuring resource: " + res + ": " + TM.messages;

     Print(res + ": Width=" + TM.textWidth + ", Depth=" + TM.textHeight);
     var isLandscape = (TM.textWidth > TM.textHeight);
     return (isLandscape) ? "landscape" : "portrait";
     return fallback;


In the logs on composition, we're getting

The amount of text inserted into a flow exceeds the depth of all frames in the flow <>. Text is truncated. Text does not fit in the last frame on page 0 at (0 in, 0 in). Resource("../_graphics/BFH-059.pdf"): Width=81000, Depth=0


Running FusionPro VDP Server 11.2.1 on a Mac OS 10.13.6 High Sierra.

I've tried passing strings through that FusionProTextMeasure constructor and still get a textHeight property of 0.

Link to comment
Share on other sites

  • 6 months later...

In FP 11 and later on Mac specifically, text measurement of graphics fails at rule validation time, i.e. when you're in the Rule Editor and click validate.


However, as far as I know (and I just tried it to verify), it does work properly at composition time.


So if you return the textHeight property and put the rule into a text frame, the correct value should appear in the output. Or, if you put it into a Print() function call, the correct value should be written to the composition log (.msg) file. And any usage of the function to determine whether the graphic is landscape or portrait should still work in composition.


Sorry for the trouble here.

Edited by Dan Korn
Link to comment
Share on other sites

Also, you can get it to work at rule validation time by providing the full path to the graphic, which can be obtained with the FusionPro.ResolveFile function.


So it will work at validation time if you add that call in the first line, like so:

var item = CreateResource(FusionPro.ResolveFile(path("_graphics") + itemNumberFD), 'graphic', true);

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.

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