matchChunk to find fontNames

Claudi Cornaz claudi.c at fiberworld.nl
Thu Jun 23 18:34:13 EDT 2005


Thanks Björnke, Eric  and Marielle,

You all helped me.

In the mean time I got the matchChunkpart also worked out, and am 
putting it all together now.

I will try to make a complete textMenu example, with all the features 
you ever wanted,
plus a few more I hope (well, we will see about that one)

Regex can be really fun and it's not quite that difficult after all and 
tremendously usefull.
It took me a while but I learned quite a lot, and all though I don't 
know every thing I am
certainly not afraid of regex anymore.

I am putting the last bits and pieces together and smooth the whole 
thing a bit.
It's still quite experimental at the moment, but as soon as it's 
"descent" I will post it

In the mean time all the best.

Claudi



On Thursday, June 23, 2005, at 02:18 AM, Björnke von Gierke wrote:

>
> 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
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your 
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list