[metapost] Stroke Font
horakk at math.cas.cz
Sat May 16 20:02:57 CEST 2015
Troy Henderson napsal(a):
> Is there a preferred method for converting a
> btex Here is my sentence etex
> from a picture to an array of closed paths that can be filled and
> stroked different colors? Thus, I would like to convert the btex ...
> etex sentence picture into an array of outlines for each letter (in
> the current font) used in the sentence so that I can fill the outlines
> one color and draw them with another color.
I am afraid that it is not an easy task.
The first idea that comes is to use path separation from such a picture
typeset by TeX, but in this way one can obtain only subpictures (words
or parts of words depending on the kerning inside, see the example in
2.10 of Metafun manual);
Despite the following comment to loop syntax
for ?symbolic token? within ?picture expression?: ?loop text? endfor
quoted from metapost manual:
"The ?loop text? can be anything that is balanced with respect to for
and endfor. The ?symbolic
token? is a loop variable that scans the components of the picture in
the order in which they were drawn. The component for a clipping or
setbounds path includes everything the path applies to.
Thus if a single clipping or setbounds path applies to everything in the
?picture expression?, the
whole picture could be thought of as one big component. In order to make
the contents of such a
picture accessible, the for...within iteration ignores the enclosing
clipping or setbounds path in this case."
one would not get any path contained in (bounded) picture.
I see one possibility:
take a loop for one letter substrings of the given text string; after
that you can get all the letters as paths:
str:="Here is my sentence";
for i=1 upto length str: ss[i]:=substring(i-1,i) of str;
p[i]:=ss[i] infont defaultfont; s[i]:=pathpart p[i]; endfor
draw pathpart glyph ss1 of defaultfont scaled .01;
What remains is to program how to shift the obtained paths to get final
One can use the information about bbox of any of letters and use label
machanism to find kerning among letters.
Of course, it would be nice if metapost would be enhanced with such a
possibility to access all the glyph paths inside a label:-)
Perhaps somebody would come with better ideas?
All the best,
More information about the metapost