【问题标题】:How to determine height and depth of a PostScript font?如何确定 PostScript 字体的高度和深度?
【发布时间】:2012-01-07 22:34:10
【问题描述】:

我正在寻找估计 PostScript 字体高度(上升空间)和深度(下降空间)的 PostScript 代码。可以为此使用字体的边界框 (FontBBox) 吗?`

这是我的问题的一些背景:字体的字形位于基线上。显然,带有下降线的字形将到达基线以下,我想知道下降线可以到达基线以下多远,以便我可以在布局中提供足够的空间。

我见过PostScript code that renders a given string to check its dimension。我对给定字体的一般答案很感兴趣。

【问题讨论】:

    标签: fonts postscript


    【解决方案1】:

    嗯,你已经发现了这两个“捷径”。 FontBBox 给出了叠加在一起的字体中所有字形的边界框。 false charpath flattenpath pathbbox 给出指定字符串的框。

    对于 Type 3(用户定义的)字体,这是您可以合理期望的全部;但是对于更流行的 Type 1 字体,字体和“metrics”文件(用于其他应用程序)中都有丰富的度量信息。

    但这是我不太了解的部分。因此,我将阅读(在 Adob​​e Type 1 手册中)并稍后扩展此答案。

    编辑:实际上,看起来这些可能是总体上最好的方法。

    一个Type 1字体的垂直对齐值数组,在/Private字典中,在名称/BlueValues下;但不能保证字体会尊重它们。数组中的第一个数字是基线超调;这是像“O”这样的字母的底部边缘,它低于基线。数组中的最大值将是 ascender-height overshootcap-height overshoot(以较高者为准)。但是可以绘制任何单个字符而不考虑这些值(因此,不能保证)。

    另一方面,FontBBox 本身可能反映字体中存在的任何“特殊”字符的边界框,无论它们是否可以通过编码向量访问(即,你不能show它们,但必须glyphshow他们)。

    因此,最好的选择可能是采用您打算使用的所有字符的字符串中的pathbbox。这将忽略可能存在但与您的目的无关的任何其他角色的贡献。并且不要忘记flattenpath 从曲线中删除控制点(可能远离“真实”边界框)。

    【讨论】:

      【解决方案2】:

      luser droog 的答案看起来相当完整,毫无疑问比我的更强大,但我并不满意这是确定标准字体的可用垂直空间的最简单方法,它允许我创建一个可行的newline。这是我想出的:

      %!ps-nonconforming
      /inch {72 mul} bind def
      /Helvetica 10 selectfont
      1 inch 10 inch moveto
      /fontheight currentfont dup /FontBBox get dup 3 get % top
       exch 1 get sub % top - bottom
       exch /FontMatrix get 3 get mul def % adjusted by height multiplier
      /lineheight fontheight 1.2 mul def % add 20% for line spacing
      /newline {0 lineheight neg rmoveto} bind def % negate height to move downwards
      gsave (lineheight: ) show lineheight 20 string cvs show grestore
      newline gsave (that worked!) show grestore
      showpage
      

      使用gs test.ps运行它的结果:


      一天后,再次查看此内容,并意识到 OP 想要分别对待上行者和下行者。所以这里是只使用下降器的说明:

      %!ps-nonconforming
      /inch {72 mul} bind def
      /Helvetica 30 selectfont
      1 inch 2 inch moveto
      /descender currentfont dup /FontBBox get 1 get % bottom (negative number!)
       exch /FontMatrix get 3 get mul def % adjusted by height multiplier
      % first draw a gray line at base of text
      gsave 7.5 inch 0 rlineto 0.5 setgray stroke grestore
      gsave (descender: ) show descender 20 string cvs show ( pixels) show grestore
      gsave 0 descender 1 sub rmoveto  % one pixel below lowest descender
      7.5 inch 0 rlineto 0 setgray stroke grestore
      showpage
      

      gs -sDEVICE=pnggray -g640x480 -o/tmp/descender.png descender.ps的结果:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-11
        • 1970-01-01
        • 2012-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多