Page 1 of 1
Building styledText or htmlText from scratch to colorize text
Posted: Sun Mar 08, 2020 4:57 pm
by bn
Hi all,
In this thread
viewtopic.php?f=10&t=33737
Orthomaker colorizes syllables of words according to the french rules of pronunciation. He mentions that colorizing can be slow.
I attempted to do the colorization conditionally (using pseudo conditions) using styledText from the unformatted "raw" text.
Additionally I did the colorization using htmlText as comparison and also setting the colors of a word using "set the backgroundColor of char x to y of word to color"
I thought this might be of interest to people applying styles to longer texts.
Kind regards
Bernd
Re: Building styledText or htmlText from scratch to colorize text
Posted: Sun Mar 08, 2020 9:37 pm
by [-hh]
This is a beautiful demo of a "usual" scenario that shows that using htmlText is pretty fast (and here faster than styledText).
Anyway I can't understand the general hyping up of (the here slower) styledText as this is for most people hard to handle without the help of the "real stars" (team members and you).
Re: Building styledText or htmlText from scratch to colorize text
Posted: Sun Mar 08, 2020 10:12 pm
by dunbarx
I added a button in my upload that:
Code: Select all
on mouseUp
put fld "fDest" into fld "fDest"
end mouseUp
clears the text. Just a toy so I can see the text change with each method.
Craig
Re: Building styledText or htmlText from scratch to colorize text
Posted: Mon Mar 09, 2020 9:48 am
by kaveh1000
Thanks for this Bernd.
A few comments, hoping not to derail the thread!
I can see that the times for htmltext and styledText are both roughly proportional to the length of the original text, and that htmlText is a bit faster.
I remember a sample stack that was uploaded some 18 months ago (perhaps in reply to my question) and it might have been Hermann who produced it. (Sorry cannot find it by searching the forum.) It showed that htmlText was fast up to a point but for longer texts styledText was faster. Does that make sense? I remember Trevor Devore was the first who suggested styledText.
I am using htmlText, but the practical problem I find is that I need to color across several lines, so text contains returns. For html I need to close tags before return and open for next line. It just complicates the process. Additionally, i often have nested colors. Again I have to do all kinds of acrobatics to ensure open and close tags match.
For these reasons I have been thinking of moving to styledText, but arrays are not natural for me! Any thoughts on whether styledText would reduce my woes would be appreciated.
Kaveh
Re: Building styledText or htmlText from scratch to colorize text
Posted: Mon Mar 09, 2020 4:44 pm
by bn
kaveh1000 wrote: ↑Mon Mar 09, 2020 9:48 am
I am using htmlText, but the practical problem I find is that I need to color across several lines, so text contains returns. For html I need to close tags before return and open for next line. It just complicates the process. Additionally, i often have nested colors. Again I have to do all kinds of acrobatics to ensure open and close tags match.
For these reasons I have been thinking of moving to styledText, but arrays are not natural for me! Any thoughts on whether styledText would reduce my woes would be appreciated.
I think both htmlText and styledText get complex pretty soon depending on the amount of formatting you apply to the text. I think it boils down to what you are comfortable with. If you do not like arrays styledText is definitely not what you want. StyledText operates like htmlText on the paragraph level. Instead of opening and closing a tag you tag runs of characters in a paragraph by setting their "Style". A run of characters consists of sequential characters that share the same formatting in a numerically indexed run of a paragraph.
If you want to find out you probably have to experiment with some simple formatting an see what happens
Kind regards
Bernd