Fixed Width Fonts #2

Scott Rossi scott at tactilemedia.com
Mon Jan 28 15:13:50 EST 2008


Recently, Mark Swindell wrote:

> Curious thing, though.  I created a script
> ( below) which works fine when I run it line by line in the debugger,
> and _sometimes_ when I run it from a button, and then the next time
> (s), from the same button, it just chugs along and and returns
> nothing.  Any ideas?

Well, I tried a couple of things:

1) I added all font names to a variable list, rather than an actual field --
you should do this to save some speed

2) I removed the wait you had in your code and got around 5 to 6 seconds to
process all the fonts I have loaded here (I have kind of a lot loaded)

3) I added a lock screen and surprisingly got an instantaneous result (less
than 1 second); I can't say if all the font results are accurate, but I
recognize a number of monospace font names so I assume they are correct

Here's what I ran from a button on a card (I removed your object/global
references to simplify the test):

on mouseUp
  
  put "iiiii" into field "skinnyLetter"
  put "wwwww" into field "fatLetter"
  
  put the fontnames into vAvailableFonts
  sort lines of vAvailableFonts
  
  lock screen
  
  put the seconds into S
  
  repeat with x = 1 to the number of lines of vAvailableFonts
    set the textfont of field "skinnyLetter" to line x of vAvailableFonts
    set the textfont of field "fatLetter" to line x of vAvailableFonts
    
    --    wait .05 seconds -- needs time to evaluate, maybe? dunno
    put the formattedwidth of fld "skinnyLetter" into vSkinny
    put the formattedwidth of fld "fatLetter" into vFat
    
    if  vSkinny = vFat then
      put line x of vAvailableFonts &return after temp
    end if
    
  end repeat
  
  answer the seconds - S & cr & cr & temp
end mouseUp

HTH.

Regards,

Scott Rossi
Creative Director
Tactile Media, Multimedia & Design





More information about the use-livecode mailing list