加速 setTextFormat()
我有一篇文本,其中包含一长串要突出显示的单词,并且为每个单词调用 setTextFormat() 需要很长时间。有什么方法可以加快这个操作吗?我尝试使用不在 DisplayObject 列表中实例化的 TextField 来绕过渲染阶段,但我发现性能是相同的。有什么想法吗?
i've a text with a very long list of words to highlight and calling setTextFormat() one for each word takes ages. There's some way to speedup this operation ? i've tried with a TextField not instantiate in the DisplayObject's list, to bypass the rendering stage but i've founded that the performance are the same. Any ideas ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我强烈建议您查看文本布局框架处理富文本样式的新模式。
本质上,TLF 有一个 TextFlow 对象,其中包含文本模型,包括所有相关的特定于跨度的格式。这与文本显示的“视图”部分不同,后者将由单独的流程编辑器和 EditManager 管理(在可编辑文本的情况下)。
因此,您可以对文本模型的大范围执行格式转换,并且仅在最后根据命令重新绘制视图。
I'm going to strongly suggest you take a look at the Text Layout Framework's new mode of handling rich text styling.
Essentially, the TLF has a TextFlow object that contains a model of your text, including all relevant span-specific formatting. This is distinct from the "view" portion of text display, which would be managed (in your case of edit-able text) by a separate flow composer and EditManager.
Thus, you can perform formatting transformations on wide swaths of the text model, and only have the view re-draw itself on command at the very end.
使用 TLF,在开始为所有内容着色之前调用 beginCompositeOperation();最后调用 _objEditManager.endCompositeOperation();这是我的代码中的一个示例
最后,您应该只为可视范围+/- 300 个字符的内容着色。然后在滚动时重新着色当前可视区域。这适用于 http://www.Dedoose.com 上的一些非常大的文档。
Use TLF, and before you start coloring everything call beginCompositeOperation(); and at the end call _objEditManager.endCompositeOperation(); Here's a sample right out of my code
Finally, you should only color whats in viewable range +/- 300 characters. Then on scrolling recolor the current viewable region. This works for some insanely large document on http://www.Dedoose.com.
如果它是 htmlText 并且您想要突出显示的单词放在
之类的标签中,您应该查看 StyleSheet 对象,您可以通过 加载 css 文件 或者您可以像这样分配样式:
if its a htmlText and the words that you wanna to highlight are put in tags like
<strong>
you should look at the StyleSheet Object you can define its styles by loading a css file or you can assign the styles like this: