Two features I don't understand

Fraser Gordon fraser.gordon at livecode.com
Fri Oct 31 13:38:41 EDT 2014


On 30 Oct 2014, at 18:36, Richard Gaskin <ambassador at fourthworld.com> wrote:

> 
> 2. StyledText array
> Pages 16-18 of the v5.5.4 Release Notes:
> <http://downloads.livecode.com/livecode/5_5_4/LiveCodeNotes-5_5_4.pdf>
> 
> Anyone here use this?  Is it faster than doing equivalent operations on htmlText?  While the style attributes themselves are well represented in the array, the character offsets of runs don't seem to be present, so I'm unclear as to what this should be used for.
> 

The array returned by the styledText property is as close to the field’s internal representation as its possible to get in script.

Internally, the field is structured somewhat like this(*):

- Field
    - Paragraph 1
        - Run 1
        - Run 2
    - Paragraph 2

and the styledText property is that structure in array form. (A “run” in this case is a block of text sharing the same styling attributes). It is also possible to set properties at the paragraph and field levels so these are also exported in the styledText.

The offsets aren’t stored because they are redundant with the contents of the array - Run 2 comes after Run 1 (and Paragraph 2 comes after Paragraph 1). Storing them would cause problems when the contents of any of the runs are updated.

In terms of comparisons with htmlText, styledText is more “raw” - far closer to the field’s internal representation than HTML. Because of this, it is easier for the field to process than HTML (especially as HTML has to be parsed while the array is already structured). Looking at it from the other side, an array is generally easier to manipulate compared to parsing HTML in your scripts.

There are definitely some very heavy users of the styledText in the LiveCode community; I know because the refactoring work for 7 broke it at various times during the DP process…

(*) the field is vastly more complicated than this diagram. For example, there are “lines” and “segments” used internally between paragraphs and runs in order to keep the code remotely manageable. It is by far the most complicated control in the engine and that was before adding support for things like bi-directional text input… the humble LiveCode field is actually not all that different from the insides of a word processor.

Fraser





More information about the use-livecode mailing list