Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Text 如何根据Postscipt中的字符长度自动收缩文本?或者调整文本大小以适应固定区域?_Text_Postscript - Fatal编程技术网

Text 如何根据Postscipt中的字符长度自动收缩文本?或者调整文本大小以适应固定区域?

Text 如何根据Postscipt中的字符长度自动收缩文本?或者调整文本大小以适应固定区域?,text,postscript,Text,Postscript,如何根据Postscipt中的字符长度自动缩小文本大小?或者调整文本大小以适应固定区域?我认为制作一个1磅字体、测量然后放大更简单。类似于(未经测试) 这个代码根本不考虑高度 我的做法是: 获取字符串宽度 将区域宽度除以字符串宽度 将当前字体大小乘以该值 然后将其用作新字体大小并显示 因此,代码类似于: %some bogus vars to make it understandable /myfont /Helvetica def /mysz 10 def /mywidth 100 def

如何根据Postscipt中的字符长度自动缩小文本大小?或者调整文本大小以适应固定区域?

我认为制作一个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

您想使用
stringwidth
。有关相关讨论,请参阅。
%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