scripting challenge: Large/Smaller text size

Mark Smith mark at maseurope.net
Sat Jul 2 22:53:10 EDT 2005


And this is my final effort, for tonight, anyway. My earlier 
observation that it was necessary to create size tags for any unstyled 
text seems to be untrue, which saves a bit of work, and I think I've 
dealt with Wouters observation that it would all break if there were 
font face tags present. Of course, the whole thing would break anyway 
if applied to some HTML....

This comes in at around 150 to 200 ms, depending on how big the text 
gets. (It takes rev longer to put bigger text in a field.)


Mark


on changeTextSize inc
   put the effective textSize of fld 1 into fSize
   put the htmltext of fld 1 into ttext

   --now get all the size values from the size tags
   put getHSizes(ttext) into sizeList

   if inc > 0 AND MAX(sizeList & comma & fSize)+inc > 48 then exit to top
   if inc < 0 AND MIN(sizeList & comma & fSize)+inc < 8 then exit to top

   if inc > 0 then
     sort items of sizeList numeric descending
   else if inc < 0 then
     sort items of sizeList numeric ascending
   end if

   repeat for each item i in sizeList
     put quote & i & quote into pSize
     put quote & i+inc & quote into nSize
     replace "size=" & pSize with "size=" & nSize in ttext
   end repeat

   set the textSize of fld 1 to  fSize+inc
   set the htmltext of fld 1 to ttext
end changeTextSize


function getHSizes tt
   put empty into sizeList
   replace cr with empty in tt
   replace "<" with cr in tt
   replace ">" with cr in tt

   filter tt with "*size=*"

   replace quote with comma in tt
   repeat for each line i in tt
     get itemOffset("size=",i)
     get item it+1 of i
     if it is not among the items of sizeList then put it & comma after 
sizeList
   end repeat

   return char 1 to -2 of sizeList
end getHSizes




More information about the use-livecode mailing list