scripting challenge: Large/Smaller text size
Mark Smith
mark at maseurope.net
Sat Jul 2 22:13:41 EDT 2005
So this is my revised effort, which incorporates Wouters suggestions,
and Dicks suggestion for using 'filter' in the getHSizes function.
Remarkably this seems a little slower, at 190 to 200 ms.
Mark
on changeTextSize inc
put the effective textSize of fld 1 into fSize
put "<font size=" & quote & fSize & quote & ">" into openTag
put "</font>" into closeTag
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
put openTag after char 3 of ttext
-- puts openTag after the intial <p> tag
--now get all the size values from the size tags
put getHSizes(ttext) into sizeList
--set limits
if inc > 0 AND MAX(sizeList)+inc > 48 then exit to top
if inc < 0 AND MIN(sizeList)+inc < 8 then exit to top
--Wouters sort
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 "<font size=" & pSize with "<font 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 "font size=*"
replace quote with comma in tt
repeat for each line i in tt
get item 2 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