我想对文本的所有路径执行循环(在其中输入)。我尝试用构建图片,btex ... etex
但这种图片似乎只有一个元素(length
给出 1)。我想要类似 mpman.pdf 的字形示例,但针对整个单词。有办法吗?
picture mots[];
mots[1]:= btex coucou etex shifted (2cm,0);
beginfig(0);
show length(mots[1]);
for i within mots[1]:
show i;
endfor;
draw mots[1];
endfig;
end.
答案1
是的,但你需要往下一级。像这样:
prologues := 3;
outputtemplate := "%j%c.eps";
picture word; word = btex Cuckoo etex;
beginfig(1);
x = 0;
for p within word:
if textual p:
string w; w = textpart p;
for i = 1 upto length w:
string c; picture g;
c = substring (i-1, i) of w;
g = glyph c of fontpart p scaled 1/4;
for thing within g:
drawarrow pathpart thing shifted (x,0);
endfor
x := x + 160;
endfor
fi
endfor
endfig;
end.
编译此文件mpost
将生成如下所示的 EPS 文件:
可能有更有效的方法可以做到这一点,但我还没有发现。
注意textpart
返回一个字符串或者更多字符,并且返回pathpart
中可能有多个(例如在“o”字符中)。<picture>
glyph
答案2
首先是另一个答案的稍有不同的版本:
prologues := 3;
outputtemplate := "%j%c.eps";
beginfig(1);
save g, x, w ;
picture g;
x := 0 ;
string w; w := "Cuckoo" ;
for i = 1 upto length w:
g := glyph (substring (i-1, i) of w) of "cmr10" scaled 1/10 ;
for thing within g:
drawarrow pathpart thing shifted (x,0) withpen pencircle scaled 1pt ;
endfor
x := x + xpart urcorner g + 2pt ;
endfor
endfig;
end.
(我不知道左边那个小东西是什么,它看起来几乎像右边箭头的一小部分,但我希望不是。)
更有趣一点(嗯,MetaFun),编译如下context
:
\startMPpage[offset=1ts]
picture word ;
word = image(
draw outlinetext.d ("Cuckoo")(scaled 5)
) ;
for i within word :
drawarrow pathpart i randomizedcontrols 1 withcolor (uniformdeviate(1),uniformdeviate(1),uniformdeviate(1));
endfor ;
\stopMPpage
文本更改为“Too baffled”时的输出。请注意 T 和 o 之间的字距调整以及 ffl 连字符。
答案3
我记得锡拉丘兹的动画:https://melusine.eu.org/syracuse/metapost/animations/mehats/?swf=anim.swf#simple_source
以下是代码:
verbatimtex%&latex
\documentclass{article}
\usepackage{fourier}
\begin{document}
etex;
% text material and glyphs contours
picture tex_pct, glp_pct;
numeric glp_num, pth_num[];
path glp_pth[][];
% tex_pct btex .. etex material
% glp_num number of glyphs within tex_pct
% pth_num[i] number of paths defining the rank i (0 .. glp_num-1) glyph
% glp_pth[i][j] rank j (0 .. pth_num[i]-1) path of the rank i glyph
% glp_pct glyphs picture
tex_pct:=btex Too baffled etex scaled 3;
glp_pct:=nullpicture;
string fnt_str, txt_str, sub_str;
numeric txt_wd;
glp_num:=0;
for tkn within tex_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;
addto glp_pct doublepath glp_pth[glp_num][pth_num[glp_num]];
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
fi
endfor
beginfig(0);
for i:= 0 upto glp_num-1:
for j:= 0 upto pth_num[i]-1:
draw glp_pth[i][j];
endfor
endfor
endfig;
end
不幸的是,我并不了解一切。
- 为什么这里的连字没问题?(
ASCII
参数?) - 如果我是对的,那么字距调整是与字形的边界框一起提供的吗?
- 我不明白为什么有一个 1/1000 的因子
fontsize
。