你怎么能得到的PostScript字符串的高度指标?
-
21-08-2019 - |
题
可以得到与stringwidth
当前字体的字符串的宽度,虽然这实际上推压偏移坐标在栈上,在y值似乎总是是无用的。有一种方法,以确定一个字符串的准确高度,其可以或可以不包括下伸?
解决方案
stringwidth
,因为它说,不返回字符串的高度。 (在我看着所有的情况下,执行后stringwidth
堆栈上的第二整数是0
- 对于在水平方向上运行的字符串)stringwidth
执行(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
它计算串的(印刷红色)高度,并使用该信息来尝试和中心小实心圆(以黑色印刷)成其边界框的中心:
其他提示
我已经在如何确定的PostScript串高度回答了这个?,但它是有用的在这里也。
只需添加为 pipitas 强>答案:
/textheight {
gsave % save graphic context
{
100 100 moveto % move to some point
(HÍpg) true charpath pathbbox % gets text path bounding box (LLx LLy URx URy)
exch pop 3 -1 roll pop % keeps LLy and URy
exch sub % URy - LLy
}
stopped % did the last block fail?
{
pop pop % get rid of "stopped" junk
currentfont /FontMatrix get 3 get % gets alternative text height
}
if
grestore % restore graphic context
} bind def
/jumpTextLine {
textheight 1.25 mul % gets textheight and adds 1/4
0 exch neg rmoveto % move down only in Y axis
} bind def
的方法,预计一些字体已经设置。它的工作原理在所选择的字体(setfont
)及其大小(scalefont
)。
我用(HÍpg),以获得最大的边界框可能的,使用突出大写字符和“下行”的字符。结果是足够好。
另一种方法从窃取的 dreamlax 的答案 - 有的字体不支持charpath
运营商
保存和恢复图形上下文保持代替当前点,因此它具有在文档的“流”没有任何影响。
希望我帮助。
这似乎是工作的大部分时间:
/fontheight { currentfont /FontMatrix get 3 get } bind def
/lineheight { fontheight 1.2 mul } bind def
它不会对所有/FontType
s工作。
不隶属于 StackOverflow