Class TrueTypeFont

java.lang.Object
com.itextpdf.io.font.FontProgram
com.itextpdf.io.font.TrueTypeFont
Direct Known Subclasses:
DocTrueTypeFont

public class TrueTypeFont extends FontProgram
  • Field Details

    • bBoxes

      protected int[][] bBoxes
    • isVertical

      protected boolean isVertical
    • kerning

      protected com.itextpdf.io.util.IntHashtable kerning
      The map containing the kerning information. It represents the content of table 'kern'. The key is an Integer where the top 16 bits are the glyph number for the first character and the lower 16 bits are the glyph number for the second character. The value is the amount of kerning in normalized 1000 units as an Integer. This value is usually negative.
  • Constructor Details

  • Method Details

    • hasKernPairs

      public boolean hasKernPairs()
      Overrides:
      hasKernPairs in class FontProgram
    • getKerning

      public int getKerning (Glyph first, Glyph second)
      Gets the kerning between two glyphs.
      Specified by:
      getKerning in class FontProgram
      Parameters:
      first - the first glyph
      second - the second glyph
      Returns:
      the kerning to be applied
    • isCff

      public boolean isCff()
    • getActiveCmap

      public Map<Integer,int[]> getActiveCmap()
    • getFontStreamBytes

      public byte[] getFontStreamBytes()
    • getPdfFontFlags

      public int getPdfFontFlags()
      Specified by:
      getPdfFontFlags in class FontProgram
    • getDirectoryOffset

      public int getDirectoryOffset()
      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.
      Returns:
      directory Offset
    • getGsubTable

      public GlyphSubstitutionTableReader getGsubTable()
    • getGposTable

      public GlyphPositioningTableReader getGposTable()
    • getGdefTable

      public OpenTypeGdefTableReader getGdefTable()
    • getSubset

      public byte[] getSubset (Set<Integer> glyphs, boolean subsetTables)
      Gets subset of the current TrueType font based on the passed glyphs.
      Parameters:
      glyphs - the glyphs to subset the font
      subsetTables - whether subset tables (remove `name` and `post` tables) or not. It's used in case of ttc (true type collection) font where single "full" font is needed. Despite the value of that flag, only used glyphs will be left in the font
      Returns:
      the subset font
    • merge

      public static byte[] merge (Map<TrueTypeFont,Set<Integer>> toMerge, String fontName)
      Merges the passed font into one. Used glyphs per each font are applied to subset the merged font.
      Parameters:
      toMerge - the fonts to merge with used glyphs per each font
      fontName - the name of fonts to merge
      Returns:
      the raw data of merged font
    • mapGlyphsCidsToGids

      public Set<Integer> mapGlyphsCidsToGids (Set<Integer> glyphs)
      Maps a set of glyph CIDs (as used in PDF file) to corresponding GID values (as a glyph primary identifier in the font file). This call is only meaningful for fonts that return true for isCff(). For other types of fonts, GID and CID are always the same, so that call would essentially return a set of the same values.
      Parameters:
      glyphs - a set of glyph CIDs
      Returns:
      a set of glyph ids corresponding to the passed glyph CIDs
    • isCmapPresent

      public boolean isCmapPresent (int platformID, int encodingID)
      Checks whether current TrueTypeFont program contains the “cmap” subtable with provided platform ID and encoding ID.
      Parameters:
      platformID - platform ID
      encodingID - encoding ID
      Returns:
      true if “cmap” subtable with provided platform ID and encoding ID is present in the font program, false otherwise
    • getNumberOfCmaps

      public int getNumberOfCmaps()
      Gets the number of the “cmap” subtables for the current TrueTypeFont program.
      Returns:
      the number of the “cmap” subtables
    • readGdefTable

      protected void readGdefTable() throws IOException
      Throws:
      IOException
    • readGsubTable

      protected void readGsubTable() throws IOException
      Throws:
      IOException
    • readGposTable

      protected void readGposTable() throws IOException
      Throws:
      IOException
    • getCodePagesSupported

      public String[] getCodePagesSupported()
      Gets the code pages supported by the font.
      Returns:
      the code pages supported by the font
    • isBuiltWith

      public boolean isBuiltWith (String fontProgram)
      Description copied from class: FontProgram
      Checks whether the FontProgram was built with corresponding fontName. Default value is false unless overridden.
      Overrides:
      isBuiltWith in class FontProgram
      Parameters:
      fontProgram - a font name or path to a font program
      Returns:
      true, if the FontProgram was built with the fontProgram. Otherwise false.
    • close

      public void close() throws IOException
      Throws:
      IOException
    • updateUsedGlyphs

      public void updateUsedGlyphs (SortedSet<Integer> usedGlyphs, boolean subset, List subsetRanges)
      The method will update usedGlyphs with additional range or with all glyphs if there is no subset. This set of used glyphs can be used for building width array and ToUnicode CMAP.
      Parameters:
      usedGlyphs - a set of integers, which are glyph ids that denote used glyphs. This set is updated inside of the method if needed.
      subset - subset status
      subsetRanges - additional subset ranges