views:

216

answers:

1

Hi, i have to set the text format for some tokens in a plain text. I'm trying to use the Text Layout Framework to improve the speed of the operation but i've founded that TLF is far slower (10X in my tests) than the old setTextFormat(). For each token i call this function:

public function setTextFormat(format:TextLayoutFormat, begin:int, end:int):void{

            var selection:SelectionState = new SelectionState(this._textFlow, begin, end, this._normalFormat);
            IEditManager(_textFlow.interactionManager).applyLeafFormat(format, selection);

        }

is there any faster and clever way to do this operation ?

Thanks

A: 

Most of the processing time in these TLF updates is the recalculation and update of the display. The association of particular formats with portions of your text model is much less intensive. Unfortunately, the applyLeafFormat() call does both format-association and redisplay operations. You need to split those two up.

Instead of only dealing with your tokens in terms of their absolute positions, you could split them into separate FlowElement objects (most likely SpanElements), which can be uniquely identified with an "id" property. Once your tokens are in separate elements, it becomes straightforward to iterate through a whole lot of them, change format characteristics, and only force a display update at the end.

for each (var id:String in ids) {
    var element:SpanElement = _textFlow.getElementByID(id) as SpanElement;
    if (element) {
        element.format = getAppropriateFormatForElement(element);
    }
}
_textFlow.flowComposer.updateAllControllers();

As an aside, splitting your tokens into elements also opens the door for storing your token classification in the elements themselves, freeing you from maintaining a separate classification mapping structure.

ZackBeNimble
That sound great, i've immagined that the problem was that applyLeafFormat() update the view at every call. The question now is, how can i create FlowElement ? i have to change my text by inserting span tags ? i don't' want to change my text because i apply a new colorization for each text change and if i set a new text on every keypress the user see the text thank blinks (i've tried with the old TextArea and htmlText)
wezzy