Fixed Width Fonts #2
Ken Ray
kray at sonsothunder.com
Mon Jan 28 17:24:02 EST 2008
On Mon, 28 Jan 2008 12:13:50 -0800, Scott Rossi wrote:
> Here's what I ran from a button on a card (I removed your object/global
> references to simplify the test):
Scott, I modified the code to not need to use fields at all (I'm using
the templateField), and I discovered a speed increase (at least on my
machine). When I ran your code I got about 5 seconds (initially), and
then it was almost instantaneous the next time I ran it (I changed your
code to track milliseconds instead of seconds and it was 9ms).
When I changed the code to use the templateField (see below), it took
786ms after a cold start of Rev, and then also only 9ms afterwards. I
have two versions below - one that doesn't assume that the
templateField is being used later on by Rev for some other purpose, and
one that resets it back to its prior state - the second one only took a
couple of ms longer on the first pass (
-- Resets templateField to the "factory version" when done:
on mouseUp
put the fontnames into vAvailableFonts
sort lines of vAvailableFonts
put the milliseconds into S
repeat with x = 1 to the number of lines of vAvailableFonts
set the text of the templateField to "iiiii"
set the textfont of the templateField to line x of vAvailableFonts
put the formattedWidth of the templateField into w1
set the text of the templateField to "wwwww"
set the textfont of the templateField to line x of vAvailableFonts
put the formattedWidth of the templateField into w2
if w1 = w1 then
put line x of vAvailableFonts &return after temp
end if
end repeat
reset the templateField
put the milliseconds - S & cr & cr & temp
end mouseUp
-- Carefully restores the templateField to its previous state when done:
on mouseUp
put the fontnames into vAvailableFonts
sort lines of vAvailableFonts
put the milliseconds into S
put the text of the templateField into tOldText
put the textFont of the templateField into tOldFont
repeat with x = 1 to the number of lines of vAvailableFonts
set the text of the templateField to "iiiii"
set the textfont of the templateField to line x of vAvailableFonts
put the formattedWidth of the templateField into w1
set the text of the templateField to "wwwww"
set the textfont of the templateField to line x of vAvailableFonts
put the formattedWidth of the templateField into w2
if w1 = w1 then
put line x of vAvailableFonts &return after temp
end if
end repeat
set the text of the templateField to tOldText
set the textFont of the templateField to tOldFont
put the milliseconds - S & cr & cr & temp
end mouseUp
Best thing is - it doesn't use an actual field object, so it could be
wrapped up in a library function...
:-)
Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
More information about the use-livecode
mailing list