[metapost] accessing letters in picture (for...within loop)

Hans Hagen pragma at wxs.nl
Tue Nov 21 13:38:15 CET 2006


Stephan Hennig wrote:
> Taco Hoekwater schrieb:
>   
>> Stephan Hennig wrote:
>>     
>>> want to access the coordinates of single letters.  Is there any way to
>>> tell MetaPost to process pictures letter by letter?
>>>       
>> With a "Thank you!" to Hans for a behind-the-scenes answer:
>>
>>    string s;
>>    for i=0 upto length(t)-1:
>>      s := substring(i,i+1) of t ;
>>      show s;
>>    endfor;
>>     
>
> I might be missing the point (in fact, I've not seen Hans' answer yet).
>   
that was on our private high speed development channel -)
>  I need to access properties of single letters such as their coordinates
> in the picture, but see no way to get them using the substring operator.
>    The coordinates returned for t apply to the left most character's
> baseline only.  Since I'm using a proportional font interpolation is no
> elegant solution.  Any more help?
>
> Best regards,
> Stephan Hennig
>
> PS:  Taco, would it take much to change MetaPost's behaviour in this
> respect?  I mean, could for...each process single characters by default?
>  Or what is the rationale for returning those arbitrary bunches of
> letters?  Since the current behaviour seems not to be documented or
> explained I don't think iterating over single letters would introduce an
> incompatible change.  What do you think?
>   

in the metafun manual you will find a way to do such things; if you want 
kerning to play a role you need to stepwise build the string and keep 
track of increments

anyhow, if you use btex ... etex, snippets are resulting from tex's way 
of outputting the result, so if you want something different there you 
need to patch dvitomp to produce less efficient code; if the snippets 
are the result of the instring operator, then the option would be to 
ignore kerning; anyhow, text processing in mp is a hack and if you want 
more control, metapost >= 1.1 (tex-mp integration) will be the answer 
(the library embeded in luatex, not the stand alone mp; it's a waste of 
development energy to extend metapost independently of tex)

Hans

-- 

-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------



More information about the metapost mailing list