scripting challenge: Large/Smaller text size

Richard Gaskin ambassador at fourthworld.com
Sat Jul 2 15:59:25 EDT 2005


Mark Smith wrote:
> So I think I've cracked it...
> 
> since the htmltext of a field includes tags only for those parts of the 
> text that do not inherit their attributes from their parent, it seems to 
> be necessary to generate the appropriate tags for the rest of the text, 
> as well. Not doing so produced peculiar results. This took 157 
> milliseconds on the same 20000 word field.

That's some damn fine work, Mark.

Anyone beat 157ms on a block of 20,000 words with 2,000 of them styled?

--
  Richard Gaskin
  Managing Editor, revJournal
  _______________________________________________________
  Rev tips, tutorials and more: http://www.revJournal.comm

> 
> on changeTextSize inc
>   -- make the tags that will set text to the effective textSize in force
>   put "<font size=" & quote & the effective textSize of fld 1 & quote & 
> ">" into openTag
>   put "</font>" into closeTag
> 
>   -- get the html
>   put the htmltext of fld 1 into ttext
> 
> 
>   --this next block sets size tags for all the unsized text
> 
>   replace "</font>" with "</font>" & openTag in ttext
>   replace "<font size=" with closeTag & "<font size=" in ttext
>   replace closeTag & closeTag with closeTag in ttext
>    --ugly, i know, but I could'nt see a better way
>   put openTag after char 3 of ttext
>   -- puts openTag after the intial <p> tag
> 
>   --now get all the size values from the size tags
>   --via the getHSizes function
>   put getHSizes(ttext) into sizeList
> 
>   if sizeList is not empty then
>     repeat for each line L in sizeList
>       put quote & L & quote into pSize
>       put quote & L+inc & quote into nSize
>       replace "<font size=" & pSize with "<font size=" & nSize in ttext
>     end repeat
>   end if
> 
>   set the htmltext of fld 1 to ttext
> end changeTextSize
> 
> function getHSizes tt
>   put empty into sizeList
>   -- turn each tag into an item
>   replace "<" with numToChar(28) in tt
>   replace ">" with numToChar(28) in tt
>   set the itemDelimiter to numToChar(28)
>   repeat for each item i in tt
>     if "font size=" is in i then
>       --if the item is a font size tag then
>       --get the value inside the quotes ie font size="14"
>       put offset(quote,i) +1 into startChar
>       put offset(quote,i,startchar) into endChar
>       put char startChar to (startChar + endChar -1) of i into fSize
>       if fSize is not among the lines of sizeList then put fSize & cr 
> after sizeList
>     end if
>   end repeat
>   return char 1 to -2 of sizeList
> end getHSizes
> 
> 
> Cheers,
> 
> Mark
> _______________________________________________





More information about the use-livecode mailing list