scripting challenge: Large/Smaller text size

Mark Smith mark at maseurope.net
Sun Jul 3 10:01:27 EDT 2005


And finally, the RTF version, which is maybe a few milliseconds faster, 
and has the possible advantage that the lower limit could be < 8 if 
necessary.
Worth noting that RTF font size tags are in half-points, hence the 
division by 2 in the getRSizes function, and corresponding 
multiplication afterwards.

I think I should do something else, now. Obsessive, me?

:)

Mark


on changeTextSizeRTF inc
   put the effective textSize of fld 1 into fSize
   put the rtftext of fld 1 into ttext

   put getRSizes(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
     replace "\fs" & (i*2) with "\fs" & ((i+inc)*2) in ttext
   end repeat

   set the textSize of fld 1 to fSize+inc
   set the rtftext of fld 1 to ttext
end changeTextSizeRTF


function getRSizes tt
   put empty into sizeList
   replace cr with empty in tt
   replace "\fs" with cr & "\fs" in tt
   filter tt with "\fs*"

   repeat for each line L in tt
     get offset(space,L)
     put trunc((char 4 to it-1 of L)/2) into sizeVal
     if sizeVal is not among the items of sizeList then put sizeVal & 
comma after sizeList
   end repeat

   return char 1 to -2 of sizeList
end getRSizes




More information about the use-livecode mailing list