使用 JavaScript 脚本可靠地检测 InDesign Server 中 TextFrame 中的文本溢出?
我目前正在使用 InDesign Server 编写一些 Javascript 脚本。 在更改格式或将 XML 放入 TextFrame 中后,我无法可靠地检测 TextFrame 中的溢出。
例如,我有一个函数可以缩小 4 列 TextFrame 的高度,直到文本溢出框架。 然后它增加高度,直到不再溢出。 这应该会导致柱高尽可能接近相等。
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");
}
在 InDesign 桌面中,这工作正常(进行一些修改以使其使用当前选定的对象),但在 InDesign Server 中,这似乎在收缩阶段超出了范围,然后仅扩展一次。
将 XML 放入 TextFrame,然后检测该文本是否导致溢出后,也会出现类似的问题。 如果我在 placeXML() 之后直接检查溢出,它总是返回 false,但如果我在脚本的后面部分检查溢出,它会正确检测到它。
这有点像计算文本是否溢出时存在延迟,但它会继续执行脚本,直到 TextFrame 上的溢出属性更新为止。
有没有办法强制脚本等待溢出属性更新? 或者设置脚本的模式等待刷新? 或者我只是做错了?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如您所发现的,组合是一项延迟任务。 大多数需要有效组合的脚本活动都会自动强制执行,但有时您必须使用 recompose() 方法,例如
As you found, composition is a deferred task. Most scripting activities that require valid composition will force it automatically, but sometimes you have to use the recompose() method, e.g.
因此,事实证明,这是由 XML 结构方式的副作用引起的。 我应用于 TextFrame 的 XML 包含许多
标记,这些标记在评估溢出时似乎会混淆布局引擎。 我通过脚本运行 XML,用
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
(the paragraph separator character) and it works fine now.
<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