加速 setTextFormat()

发布于 2024-08-18 03:51:18 字数 144 浏览 2 评论 0原文

我有一篇文本,其中包含一长串要突出显示的单词,并且为每个单词调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

相权↑美人 2024-08-25 03:51:18

我强烈建议您查看文本布局框架处理富文本样式的新模式。

本质上,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.

2024-08-25 03:51:18

使用 TLF,在开始为所有内容着色之前调用 beginCompositeOperation();最后调用 _objEditManager.endCompositeOperation();这是我的代码中的一个示例

_objFlow.interactionManager = _objEditManager;
                    _objEditManager.beginCompositeOperation();

                    DocColoringUtils.SetRegionColor(_objFlow, iStart, iEnd, BackgroundColor.TRANSPARENT, 1);

                    var colRegions:Vector.<Region> = _objResourceMediator.GetCurrentResourceRegions();
                    var objEditingExcerpt:Excerpt = _objExcerptingMediator.EditingExcerpt;

                    if (_objExcerptingMediator.InEditMode == true && objEditingExcerpt != null)
                    {
                        DocColoringUtils.ColorizeForEditMode(_objFlow, iStart, iEnd, colRegions, objEditingExcerpt.StartIndex, objEditingExcerpt.EndIndex, _objExcerptingMediator.SearchMatchRegions);
                    }
                    else
                    {
                        DocColoringUtils.ColorizeForNonEditMode(_objFlow, iStart, iEnd, colRegions, _objExcerptingMediator.SearchMatchRegions);
                    }
                    _objEditManager.endCompositeOperation();

                    _objFlow.interactionManager = _objSelectionManager;

最后,您应该只为可视范围+/- 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

_objFlow.interactionManager = _objEditManager;
                    _objEditManager.beginCompositeOperation();

                    DocColoringUtils.SetRegionColor(_objFlow, iStart, iEnd, BackgroundColor.TRANSPARENT, 1);

                    var colRegions:Vector.<Region> = _objResourceMediator.GetCurrentResourceRegions();
                    var objEditingExcerpt:Excerpt = _objExcerptingMediator.EditingExcerpt;

                    if (_objExcerptingMediator.InEditMode == true && objEditingExcerpt != null)
                    {
                        DocColoringUtils.ColorizeForEditMode(_objFlow, iStart, iEnd, colRegions, objEditingExcerpt.StartIndex, objEditingExcerpt.EndIndex, _objExcerptingMediator.SearchMatchRegions);
                    }
                    else
                    {
                        DocColoringUtils.ColorizeForNonEditMode(_objFlow, iStart, iEnd, colRegions, _objExcerptingMediator.SearchMatchRegions);
                    }
                    _objEditManager.endCompositeOperation();

                    _objFlow.interactionManager = _objSelectionManager;

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.

故乡的云 2024-08-25 03:51:18

如果它是 htmlText 并且您想要突出显示的单词放在 之类的标签中,您应该查看 StyleSheet 对象,您可以通过 加载 css 文件 或者您可以像这样分配样式:

var style:StyleSheet = new StyleSheet();
var strong:Object = new Object(); 
strong.textDecoration = "underline";
style.setStyle("strong", strong);

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:

var style:StyleSheet = new StyleSheet();
var strong:Object = new Object(); 
strong.textDecoration = "underline";
style.setStyle("strong", strong);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文