如何根据Postscipt中的字符长度自动缩小文本大小?或者为了适应固定区域而调整文本大小?
答案 0 :(得分:2)
我认为制作1-pt字体,测量然后缩放 up 更简单。像(未经测试的)
之类的东西/showwid { % string width /font-name
gsave
1 selectfont
1 index stringwidth pop div % width/stringwidth
currentfont scalefont setfont
show
grestore
} def
此代码根本不考虑高度。
答案 1 :(得分:1)
我这样做的方式是:
所以,代码类似于:
%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