我有一个包含很长单词列表的文本要突出显示并为每个单词调用 setTextFormat() 需要很长时间。有什么方法可以加快这个操作?我尝试使用不在 DisplayObject 列表中实例化的 TextField 来绕过渲染阶段,但我发现性能是相同的。有任何想法吗 ?
问问题
645 次
3 回答
1
使用 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上的一些非常大的文档。
于 2010-12-16T01:17:50.443 回答
1
我强烈建议您看看 Text Layout Framework 处理富文本样式的新模式。
本质上,TLF 有一个 TextFlow 对象,其中包含一个文本模型,包括所有相关的跨度特定格式。这与文本显示的“视图”部分不同,后者将由单独的流程编辑器和 EditManager 管理(在您的可编辑文本的情况下)。
因此,您可以在文本模型的大范围内执行格式转换,并且只有在最后根据命令重新绘制视图。
于 2010-01-18T14:20:27.280 回答
0
如果它是一个 htmlText 并且您想要突出显示的单词被放在标签中,就像<strong>
您应该查看StyleSheet对象一样,您可以通过加载 css 文件来定义其样式,或者您可以像这样分配样式:
var style:StyleSheet = new StyleSheet();
var strong:Object = new Object();
strong.textDecoration = "underline";
style.setStyle("strong", strong);
于 2010-01-17T18:01:43.567 回答