如何使文本大小根据postscript字符长度自动收缩?或者让文本调整大小以适应固定区域?
我认为制作1-pt字体,测量,然后缩放更简单。比如(未经测试)
/showwid { % string width /font-name
gsave
1 selectfont
1 index stringwidth pop div % width/stringwidth
currentfont scalefont setfont
show
grestore
} def
这段代码根本没有考虑高度。
我的做法是:
- 获取字符串宽度
- 将区域宽度除以字符串宽度
- 将当前字体大小乘以
- 然后使用这个作为新的字体大小,并显示
%some bogus vars to make it understandable
/myfont /Helvetica def
/mysz 10 def
/mywidth 100 def
/mystr (Hello PS world!) def
%supposedly you'd be in the middle of something
%therefore we would have the font already selected
myfont mysz selectfont
50 50 moveto
myfont mywidth mystr stringwidth pop div mysz mul selectfont
mystr show
% and for good measure, a line showing the size
50 49 moveto
mywidth 0 rlineto stroke