matchChunk to find fontNames

Björnke von Gierke bvg at mac.com
Wed Jun 22 20:18:03 EDT 2005


On Jun 23 2005, at 00:29, Claudi Cornaz wrote:

> Hi all,
>
> I am trying to implement a text menu and need to find all the fontNames
> and text attributes in the selectedChunk first to update my menu and 
> afterwards
> to handle the choice.
> As long as all the text has all the same attributes (bold / italic 
> etc) it's no problem
> but I need also to find all the attributes when it's mixed.
>
> I have been trying to get the instances of  <font face=" xxxx xxx - 
> xxx" [Size="yy"] [color="#ZZZZZZ"]>
> to extract all the parts like, the fontname, the size and the color if 
> applicable with matchChunk.


you could get the foregroundColor (or more aptly named the textColor) 
of the char. The textStyle property reports the current styles 
delimited by comma, if you query only one style at once. The textSize 
again returns mixed for a whole selection, but you can get it char per 
char, and it will give you exact data that way.

so for example:
   --preparation
   put empty into theColor
   put empty into theSize
   put empty into theStyle
   put word two of the selectedchunk into theStart
   put word four of the selectedchunk into theEnd
   put word -1 of the selectedchunk into theField
   --getting the actual data from the chars
   repeat with x = theStart to theEnd
     put (the effective textColor of char x of field theField) & comma 
after theColor
     put (the effective textSize of char x of field theField) & comma 
after theSize
     put (the effective textStyle of char x of field theField) & comma 
after theStyle
   end repeat
   --now we can do whatever we want with the assembled list
   --for example to know what the dominant textSize is:
   put empty into theSizes
   --adding them up by using an array
   repeat for each item theItem in theSize
     add 1 to theSizes[theItem]
   end repeat
   --finall cleanup of the data we got
   combine theSizes using return and comma
   sort theSizes numeric by item 2 of each
   put theSizes
   --and finally you got your most used size!
   put line -1 of theSizes

hope it does what you want?
Björnke who wrote this mail
Wouter and Mark who gave some vital hints (arrays, counting, sorting)
-- 

http://contest.wecode.org
Now running: the first ChatRev coding contest!
sponsors:
Altuit
Andre Garzia
Fourth World
Karl Becker
Runtime Revolution
TidBITS in cooperation with eHUG



More information about the use-livecode mailing list