我在后记中有这个
Label
定义:
/Label { % i dx dy (text) Label
% write text at base i plus offset dx, dy
4 3 roll 1 sub coor exch get aload pop moveto
3 1 roll fsize mul exch fsize mul exch rmoveto
show
} bind def
应该用作:
i dx dy (text) Label
我想把它组合成一个 for 循环,像这样:
1 10 20 {
/i exch def
i 0 0 (i) Label
} for
避免写作:
1 0 0 (1) Label
10 0 0 (10) Label
20 0 0 (20) Label
实际上它在每个位置都打印
i
,但是我希望索引 i
而不是 i
作为字符串。任何想法如何结合文本和变量?非常感谢。
正如 Ken 评论的那样,您需要加载变量的值,然后将数字转换为字符串。 Ken 将这些效果组合到循环体中并消除了变量,但另一种选择是定义辅助过程。
/to-string {
256 string cvs
} def
加载变量后在代码中调用
1 10 20 {
/i exch def
i 0 0 i to-string Label
} for
间距有助于使子表达式脱颖而出。