dre*_*lax 11 string fonts metrics postscript
您可以使用当前字体获取字符串的宽度,stringwidth
虽然这实际上会推动堆栈上的偏移坐标,但y值似乎总是无用的.有没有办法确定字符串的确切高度,可能包括也可能不包括下行链接?
stringwidth
正如它所说,不会返回字符串的高度.(在我查看的所有情况下,执行后堆栈上的第二个整数stringwidth
是0
- 对于在水平方向上运行的字符串.)stringwidth
给出了执行a后的当前点的相对坐标(string) show
.
PLRM有这样的说法stringwidth
:
请注意,stringwidth返回的宽度定义为当前点的移动.它与字形轮廓的尺寸无关.
那么考虑弦的高度会有什么效果呢?在PRLM中阅读的神奇词汇是charpath
和pathbbox
.试试这个:
%!
/Helvetica findfont 60 scalefont setfont
200 700 4 0 360 arc fill
200 700 moveto (test test) dup
true charpath pathbbox
3 -1 roll sub 2 div neg 3 1 roll sub 2 div exch
1 0 0 setrgbcolor
200 700 moveto rmoveto show showpage
Run Code Online (Sandbox Code Playgroud)
它计算字符串(以红色打印)的高度,并使用该信息尝试将一个小的实心圆(以黑色打印)居中到其边界框的中心:
我已经在如何确定 PostScript 中的字符串高度?中回答了这个问题。,但它在这里也很有用。
\n\n只是添加到Pipitas答案:
\n\n/textheight { \n gsave % save graphic context\n { \n 100 100 moveto % move to some point \n (H\xc3\x8dpg) true charpath pathbbox % gets text path bounding box (LLx LLy URx URy)\n exch pop 3 -1 roll pop % keeps LLy and URy\n exch sub % URy - LLy\n }\n stopped % did the last block fail?\n {\n pop pop % get rid of "stopped" junk\n currentfont /FontMatrix get 3 get % gets alternative text height\n }\n if\n grestore % restore graphic context\n} bind def\n\n/jumpTextLine { \n textheight 1.25 mul % gets textheight and adds 1/4\n 0 exch neg rmoveto % move down only in Y axis\n} bind def\n
Run Code Online (Sandbox Code Playgroud)\n\n该方法期望已经设置了某种字体。它适用于选定的字体 ( setfont
) 及其大小 ( scalefont
)。
我使用 (H\xc3\x8dpg) 来获得可能的最大边界框,使用重音大写字符和“行下”字符。结果已经足够好了。
\n\n另一种方法借鉴了dreamlax的答案——某些字体不支持charpath
运算符。
保存和恢复图形上下文会将当前点保留在适当的位置,因此不会影响文档的“流程”。
\n\n希望我有所帮助。
\n 归档时间: |
|
查看次数: |
2375 次 |
最近记录: |