Class OpenTypeParser

java.lang.Object
com.itextpdf.io.font.OpenTypeParser
All Implemented Interfaces:
Closeable, AutoCloseable

class OpenTypeParser extends Object implements Closeable
  • Field Details

    • HEAD_LOCA_FORMAT_OFFSET

      private static final int HEAD_LOCA_FORMAT_OFFSET
      See Also:
    • fileName

      protected String fileName
      The file name.
    • raf

      protected RandomAccessFileOrArray raf
      The file in use.
    • ttcIndex

      protected int ttcIndex
      The index for the TTC font. It is -1 int for a TTF file.
    • directoryOffset

      protected int directoryOffset
      The offset from the start of the file to the table directory. It is 0 for TTF and may vary for TTC depending on the chosen font.
    • fontName

      protected String fontName
      The font name. This name is usually extracted from the table 'name' with the 'Name ID' 6.
    • allNameEntries

      protected Map<Integer,List<String[]>> allNameEntries
      All the names of the Names-Table.
    • cff

      protected boolean cff
      Indicate, that the font contains 'CFF ' table.
    • cffOffset

      protected int cffOffset
      Offset to 'CFF ' table.
    • cffLength

      protected int cffLength
      Length of 'CFF ' table.
    • glyphWidthsByIndex

      private int[] glyphWidthsByIndex
    • hhea

    • os_2

    • post

      protected OpenTypeParser.PostTable post
    • cmaps

      protected OpenTypeParser.CmapTable cmaps
    • tables

      protected Map<String,int[]> tables
      Contains the location of the several tables. The key is the name of the table and the value is an int[2] where position 0 is the offset from the start of the file and position 1 is the length of the table.
  • Constructor Details

  • Method Details

    • getPsFontName

      public String getPsFontName()
      Gets the Postscript font name.
    • getAllNameEntries

      public Map<Integer,List<String[]>> getAllNameEntries()
    • getPostTable

      public OpenTypeParser.PostTable getPostTable()
    • getOs_2Table

      public OpenTypeParser.WindowsMetrics getOs_2Table()
    • getHheaTable

      public OpenTypeParser.HorizontalHeader getHheaTable()
    • getHeadTable

      public OpenTypeParser.HeaderTable getHeadTable()
    • getCmapTable

      public OpenTypeParser.CmapTable getCmapTable()
    • getGlyphWidthsByIndex

      public int[] getGlyphWidthsByIndex()
    • getFontNames

      public FontNames getFontNames()
    • isCff

      public boolean isCff()
    • getFullFont

      public byte[] getFullFont() throws IOException
      Throws:
      IOException
    • readCffFont

      public byte[] readCffFont() throws IOException
      If this font file is using the Compact Font File Format, then this method will return the raw bytes needed for the font stream. If this method is ever made public: make sure to add a test if (cff == true).
      Returns:
      a byte array
      Throws:
      IOException
    • getSubset

      byte[] getSubset(Set<Integer> glyphs, boolean subset) throws IOException
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • initializeSfntTables

      private void initializeSfntTables() throws IOException
      Throws:
      IOException
    • loadTables

      protected void loadTables(boolean all) throws IOException
      Reads the font data.
      Parameters:
      all - if true, all tables will be read, otherwise only 'head', 'name', and 'os/2'.
      Throws:
      IOException
    • getTTCName

      protected static String getTTCName(String name)
      Gets the name from a composed TTC file name. If I have for input "myfont.ttc,2" the return will be "myfont.ttc".
      Parameters:
      name - the full name
      Returns:
      the simple file name
    • checkCff

      protected void checkCff()
    • readGlyphWidths

      protected void readGlyphWidths() throws IOException
      Reads the glyphs widths. The widths are extracted from the table 'hmtx'. The glyphs are normalized to 1000 units (TrueTypeFont.UNITS_NORMALIZATION). Depends on OpenTypeParser.HorizontalHeader.numberOfHMetrics and OpenTypeParser.HeaderTable.unitsPerEm.
      Throws:
      IOException - the font file could not be read.
    • readKerning

      protected IntHashtable readKerning(int unitsPerEm) throws IOException
      Reads the kerning information from the 'kern' table.
      Parameters:
      unitsPerEm - OpenTypeParser.HeaderTable.unitsPerEm.
      Throws:
      IOException - the font file could not be read
    • readBbox

      protected int[][] readBbox(int unitsPerEm) throws IOException
      Read the glyf bboxes from 'glyf' table.
      Parameters:
      unitsPerEm - OpenTypeParser.HeaderTable.unitsPerEm
      Throws:
      IOException - the font is invalid
      IOException - the font file could not be read
    • readNumGlyphs

      protected int readNumGlyphs() throws IOException
      Throws:
      IOException
    • readNameTable

      private void readNameTable() throws IOException
      Extracts the names of the font in all the languages available.
      Throws:
      IOException - on error
      IOException - on error
    • readHheaTable

      private void readHheaTable() throws IOException
      Read horizontal header, table 'hhea'.
      Throws:
      IOException - the font is invalid.
      IOException - the font file could not be read.
    • readHeadTable

      private void readHeadTable() throws IOException
      Read font header, table 'head'.
      Throws:
      IOException - the font is invalid.
      IOException - the font file could not be read.
    • readOs_2Table

      private void readOs_2Table() throws IOException
      Reads the windows metrics table. The metrics are extracted from the table 'OS/2'. Depends on OpenTypeParser.HeaderTable.unitsPerEm property.
      Throws:
      IOException - the font is invalid.
      IOException - the font file could not be read.
    • readPostTable

      private void readPostTable() throws IOException
      Throws:
      IOException
    • readCmapTable

      private void readCmapTable() throws IOException
      Reads the several maps from the table 'cmap'. The maps of interest are 1.0 for symbolic fonts and 3.1 for all others. A symbolic font is defined as having the map 3.0. Depends from readGlyphWidths().
      Throws:
      IOException - the font file could not be read
    • readStandardString

      private String readStandardString(int length) throws IOException
      Reads a String from the font file as bytes using the Cp1252 encoding.
      Parameters:
      length - the length of bytes to read
      Returns:
      the String read
      Throws:
      IOException - the font file could not be read
    • readUnicodeString

      private String readUnicodeString(int length) throws IOException
      Reads a Unicode String from the font file. Each character is represented by two bytes.
      Parameters:
      length - the length of bytes to read. The String will have length/2 characters.
      Returns:
      the String read.
      Throws:
      IOException - the font file could not be read.
    • getGlyphWidth

      protected int getGlyphWidth(int glyph)
      Gets a glyph width.
      Parameters:
      glyph - the glyph to get the width of
      Returns:
      the width of the glyph in normalized 1000 units (TrueTypeFont.UNITS_NORMALIZATION)
    • readFormat0

      private Map<Integer,int[]> readFormat0() throws IOException
      The information in the maps of the table 'cmap' is coded in several formats. Format 0 is the Apple standard character to glyph index mapping table.
      Returns:
      a HashMap representing this map
      Throws:
      IOException - the font file could not be read
    • readFormat4

      private Map<Integer,int[]> readFormat4(boolean fontSpecific) throws IOException
      The information in the maps of the table 'cmap' is coded in several formats. Format 4 is the Microsoft standard character to glyph index mapping table.
      Returns:
      a HashMap representing this map
      Throws:
      IOException - the font file could not be read
    • readFormat6

      private Map<Integer,int[]> readFormat6() throws IOException
      The information in the maps of the table 'cmap' is coded in several formats. Format 6 is a trimmed table mapping. It is similar to format 0 but can have less than 256 entries.
      Returns:
      a HashMap representing this map
      Throws:
      IOException - the font file could not be read
    • readFormat12

      private Map<Integer,int[]> readFormat12() throws IOException
      Throws:
      IOException