views:

518

answers:

1

I'm doing some Javascript scripting with InDesign Server at the moment. I'm having trouble trying to reliably detect overflows in TextFrames, after changing formatting or placing XML into them.

For example, I've got a function that shrinks a 4 column TextFrame's height until the text overflows the frame. Then it increases the height until it no longer overflows. This should result in as close to equal column heights as possible.

while(!bodyTextFrame.overflows) {
  var bounds = bodyTextFrame.geometricBounds;
  bodyTextFrame.geometricBounds = [bounds[0], bounds[1], bounds[2] - 1, bounds[3]];
  //app.consoleout("shrinking");
}

while(bodyTextFrame.overflows) {
  var bounds = bodyTextFrame.geometricBounds;
  bodyTextFrame.geometricBounds = [bounds[0], bounds[1], bounds[2] + 1, bounds[3]];
  //app.consoleout("expanding");
}

In InDesign desktop this works fine (with some modifications to make it use the currently selected object), but in InDesign Server this seems to overshoot during the shrinking phase, and then only expand once.

A similar problem also occurs after placing XML into a TextFrame and then detecting whether that text has caused an overflow. If I check for the overflow directly after placeXML(), it always returns false, but if I check for the overflow at a later part of the script, it detects it correctly.

It's a bit like there's a delay in calculating whether the text overflows, but it carries on through the script regardless until the overflow property is updated on the TextFrame.

Is there a way of forcing the script to wait until the overflow property has been updated? Or setting the mode of the script to wait for the refresh? Or am I just doing it wrong?

A: 

So, it turns out that this was being caused by a side effect of how my XML was structured. The XML I was applying to the TextFrame contained a number of <p> tags which seemed to confuse the layout engine when assessing the overflows. I ran my XML through a script to replace the tags with &#x2029; (the paragraph separator character) and it works fine now.

tomtaylor