开发者

Speedup setTextFormat()

开发者 https://www.devze.com 2022-12-17 03:36 出处:网络
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 wit开发者_开发问答h a TextF

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 wit开发者_开发问答h 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 ?


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.


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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消