怎样才能在PostScript中获得一个字符串的高度指标?

编程入门 行业动态 更新时间:2024-10-27 14:27:00
本文介绍了怎样才能在PostScript中获得一个字符串的高度指标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你可以用 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 div 200 700 moveto rmoveto show showpage

它计算该字符串的高度,并使用该信息尝试和一个小的实心圆中心的边界框。

You can obtain the width of a string in the current font with stringwidth and although this actually pushes offset coordinates on the stack, the y-value always seems to be useless. Is there a way to determine the exact height of a string, that may or may not include descenders?

解决方案

stringwidth, as it says, doesn't return string's height. (In all cases I looked at, the second integer on the stack after executing stringwidth was 0 -- for strings that run in horizontal direction.) stringwidth gives the relative coordinates of the currentpoint after executing a (string) show.

The PLRM has this to say about stringwidth:

Note that the width returned by stringwidth is defined as movement of the current point. It has nothing to do with the dimensions of the glyph outlines.

So what would work to take into account the string's height? The magic words to read up about in PRLM are charpath and pathbbox. Try this:

%! /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 200 700 moveto rmoveto show showpage

It calculates the string's height and uses that info to try and center a small filled circle into the center of its bounding box.

更多推荐

怎样才能在PostScript中获得一个字符串的高度指标?

本文发布于:2023-10-29 20:37:07,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   高度   指标   PostScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!