【问题标题】:Glyph names and GeneralPath in Apache FontBox (PDFBox)Apache FontBox (PDFBox) 中的字形名称和 GeneralPath
【发布时间】:2017-10-25 01:14:33
【问题描述】:

我正在使用 Apache FontBox 来获取字体指标。我从一个字形中得到一个 GeneralPath,并从那里得到一些信息,比如一个字形的高度。

我正在尝试从 OpenType 字体的字形名称中获取 GeneralPath 对象。如果我使用此表单,我将获得准确的字形信息(路径)。

GeneralPath glyphPath = otfFont.getPath("uni24C8");
System.out.println(glyphPath.getBounds2D().getMaxY()); //Ok...

但是,如果我尝试从 Unicode 代码中获取字形名称,则会得到不正确的字形信息:

int glyphID = otfFont.getUnicodeCmap().getGlyphId(0x0075);
String name = otfFont.getCFF().getFont().getCharset().getNameForGID(glyphID);
GeneralPath glyphPath = otfFont.getPath(name);
System.out.println(glyphPath.getBounds2D().getMaxY()); //Incorrect...

实际上,FontBox 找不到与给定名称匹配的字形。例如,以下调用返回 false。

otfFont.hasGlyph(otfFont.getCFF().getFont().getCharset().getNameForGID(glyphID));

我做错了什么? 每当我直接使用“uni0075”或“uni24C8”之类的名称时,我都会得到正确的值。但我不知道如何从 GlyphId 中获取这些名称。

Ps.:otfFont 是一个对象 OpenTypeFont。

提前谢谢你。

【问题讨论】:

    标签: java apache path pdfbox glyph


    【解决方案1】:

    我找到了解决办法。

    只需替换以下调用:

    GeneralPath glyphPath = otfFont.getPath(name);
    

    为此:

    GeneralPath glyphPath = otfFont.getCFF().getFont().getPath(name);
    

    这解决了我使用的 OpenType 字体的问题。

    【讨论】:

      猜你喜欢
      • 2017-01-21
      • 2015-05-15
      • 1970-01-01
      • 2014-06-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多