scripting challenge: Large/Smaller text size
Mark Smith
mark at maseurope.net
Sat Jul 2 10:59:03 EDT 2005
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.
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