Class TrueTypeFont

java.lang.Object
org.ofdrw.converter.font.TrueTypeFont
All Implemented Interfaces:
FontDrawPathProvider, GlyphDataProvider

public class TrueTypeFont extends Object implements GlyphDataProvider, FontDrawPathProvider
TrueType 字体解析器

https://docs.microsoft.com/zh-cn/typography/opentype/spec/otff

CMAP见

https://docs.microsoft.com/zh-cn/typography/opentype/spec/cmap

Since:
2021-09-28 21:05:09
Author:
权观宇
  • Field Details

    • fontFamily

      public String fontFamily
      字体名称来资源有 name表
    • fontSubFamily

      public String fontSubFamily
    • psName

      public String psName
  • Constructor Details

    • TrueTypeFont

      public TrueTypeFont()
  • Method Details

    • parse

      public TrueTypeFont parse(InputStream in) throws IOException
      创建TTF字体解析器
      Parameters:
      in - 流
      Returns:
      this
      Throws:
      IOException - IOE
    • parse

      public TrueTypeFont parse(byte[] buf) throws IOException
      创建TTF字体解析器
      Parameters:
      buf - 读取到内存的字体数据
      Returns:
      this
      Throws:
      IOException - IOE
    • parse

      public TrueTypeFont parse(Path inPath) throws IOException
      创建TTF字体解析器
      Parameters:
      inPath - 字体文件路径
      Returns:
      this
      Throws:
      IOException - IOE
    • parse

      public TrueTypeFont parse(TTFDataStream raf) throws IOException
      解析字体
      Parameters:
      raf - 随机读取字体
      Returns:
      this
      Throws:
      IOException - IOE
    • getGlyph

      public GlyphData getGlyph(int gid) throws IOException
      通过字形的Index获取字形数据
      Specified by:
      getGlyph in interface GlyphDataProvider
      Parameters:
      gid - 字形Index
      Returns:
      字形数据
      Throws:
      IOException - IOE
    • getPath

      public GeneralPath getPath(int gid) throws IOException
      通过字体索引号获取字形绘制路径
      Specified by:
      getPath in interface FontDrawPathProvider
      Parameters:
      gid - 字形索引号
      Returns:
      字形路径或null
      Throws:
      IOException - 字体解析异常
    • readCMap

      public CmapSubtable[] readCMap(long cmapOffset, TTFDataStream data) throws IOException
      解析cmap
      Parameters:
      cmapOffset - cmap开始偏移量
      data - 随机访问流
      Returns:
      cmap子表数组
      Throws:
      IOException - IOE
    • getSubtable

      public CmapSubtable getSubtable(int platformId, int platformEncodingId)
      获取特定平台特定编码的字符映射子表

      Returns the subtable, if any, for the given platform and encoding.

      Parameters:
      platformId - 平台ID
      platformEncodingId - 平台编码ID
      Returns:
      映射子表
    • getUnicodeCmapLookup

      public org.apache.fontbox.ttf.CmapLookup getUnicodeCmapLookup()
      获取Unicode到字形的映射表
      Returns:
      映射表
      Throws:
      IllegalArgumentException - 字体没有cmap表
    • getUnicodeGlyph

      public GlyphData getUnicodeGlyph(int code) throws IOException
      通过Unicode获取字形数据

      如果没有cmap那么返回空白字符

      Parameters:
      code - unicode
      Returns:
      字符数据
      Throws:
      IOException - 字体文件解析异常
    • getFontMatrix

      public List<Number> getFontMatrix()
      获取变换矩阵
      Returns:
      矩阵序列