[metapost] is it possible to strike glyphs' paths?
Laurent Méhats
laurent.mehats at gmail.com
Fri Jan 28 00:25:05 CET 2011
Le 27/01/2011 14:53, Vadim Radionov a écrit :
> Dear list members,
>
> (Sorry for possible double-posting).
>
> Is it possible to decompose the picture obtained with btex .. etex and
> then draw all the glyphs' paths with (white) pen of non-zero width?
> My goal is to make a label on the complex picture more legible, but
> unfilling its bbox cuts too much.
> The way i use right now is drawing the same picture with white color
> shifting it slightly in several directions, but i hope there exists a
> correct way to do it.
>
> Thank you in advance,
>
> Vadim
Hello,
Here is an attempt that goes the way you describe.
Regards,
Laurent Méhats
--%<-- test.mp
verbatimtex%&latex
\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{mflogo}
\begin{document}
etex;
vardef init
(suffix glp_num, pth_num, glp_pth, stk_num, stk_pth, stk_thk) expr pct=
% pct btex .. etex material
% glp_num number of glyphs within pct
% pth_num[i] number of paths defining the rank i glyph
% (i ranges from 0 to glp_num-1)
% glp_pth[i][j] rank j path of the rank i glyph
% (j ranges from 0 pth_num[i]-1)
% stk_num number of stroked lines within pct
% stk_pth[i] rank i stroked line
% (i ranges from 0 to stk_num-1)
% stk_thk[i] thickness of the rank i stroked line
% (i ranges from 0 to stk_num-1)
string fnt_str, txt_str, sub_str;
numeric txt_wd;
glp_num:=0;
stk_num:=0;
for tkn within pct:
if textual tkn:
fnt_str:=fontpart tkn;
txt_str:=textpart tkn;
txt_wd:=0;
for glp_idx=0 upto (length txt_str-1):
sub_str:=substring (glp_idx, glp_idx+1) of txt_str;
pth_num[glp_num]:=0;
for sub_tkn within glyph ASCII sub_str of fnt_str
scaled (fontsize fnt_str/1000)
xscaled xxpart tkn
yscaled yypart tkn
shifted (txt_wd+xpart tkn, ypart tkn):
glp_pth[glp_num][pth_num[glp_num]]:=pathpart sub_tkn;
pth_num[glp_num]:=pth_num[glp_num]+1;
endfor
glp_num:=glp_num+1;
txt_wd:=txt_wd+
(xxpart tkn)*xpart urcorner (sub_str infont fnt_str);
endfor
elseif stroked tkn:
stk_pth[stk_num]:=pathpart tkn;
picture pen_pct;
pen_pct:=nullpicture;
addto pen_pct doublepath makepath penpart tkn;
stk_thk[stk_num]:=ypart(urcorner pen_pct-llcorner pen_pct);
stk_num:=stk_num+1;
fi
endfor
enddef;
beginfig(0)
picture pct; % btex .. etex material
numeric wht_thk; % white contours thickness
pct:=btex{Azerty, \TeX, \MP, $\gamma+\sqrt{n}-\frac{a}{b}$.}etex;
wht_thk:=.5;
numeric glp_num, pth_num[], stk_num, stk_thk[];
path glp_pth[][], stk_pth[];
init (glp_num, pth_num, glp_pth, stk_num, stk_pth, stk_thk) pct;
% there we go
fill bbox pct withcolor blue;
for i=0 upto glp_num-1:
for j=0 upto pth_num[i]-1:
draw glp_pth[i][j]
withpen pencircle scaled (2*wht_thk)
withcolor white;
endfor
endfor
for i=0 upto stk_num-1:
draw stk_pth[i]
withpen pencircle scaled (2*wht_thk+stk_thk[i])
withcolor green;
endfor
draw pct;
endfig;
end
--%<-- test.mp
More information about the metapost
mailing list