Class PDCIDFontType2

java.lang.Object
org.sejda.sambox.pdmodel.font.PDCIDFont
org.sejda.sambox.pdmodel.font.PDCIDFontType2
All Implemented Interfaces:
COSObjectable, PDFontLike, PDVectorFont

public class PDCIDFontType2 extends PDCIDFont
Type 2 CIDFont (TrueType).
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
    • ttf

      private final org.apache.fontbox.ttf.TrueTypeFont ttf
    • cid2gid

      private final int[] cid2gid
    • gid2cid

      private final HashMap<Integer,Integer> gid2cid
    • isEmbedded

      private final boolean isEmbedded
    • isDamaged

      private final boolean isDamaged
    • isOriginalEmbeddedMissing

      private boolean isOriginalEmbeddedMissing
    • isMappingFallbackUsed

      private boolean isMappingFallbackUsed
    • cmap

      private final org.apache.fontbox.ttf.CmapLookup cmap
    • fontMatrix

      private Matrix fontMatrix
    • fontBBox

      private org.apache.fontbox.util.BoundingBox fontBBox
    • noMapping

      private final Set<Integer> noMapping
    • invertedUnicodeCmap

      private Map<String,Integer> invertedUnicodeCmap
  • Constructor Details

    • PDCIDFontType2

      public PDCIDFontType2(COSDictionary fontDictionary, PDType0Font parent) throws IOException
      Constructor.
      Parameters:
      fontDictionary - The font dictionary according to the PDF specification.
      parent - The parent font.
      Throws:
      IOException
    • PDCIDFontType2

      public PDCIDFontType2(COSDictionary fontDictionary, PDType0Font parent, org.apache.fontbox.ttf.TrueTypeFont trueTypeFont) throws IOException
      Constructor.
      Parameters:
      fontDictionary - The font dictionary according to the PDF specification.
      parent - The parent font.
      trueTypeFont - The true type font used to create the parent font
      Throws:
      IOException
  • Method Details

    • findFontOrSubstitute

      private org.apache.fontbox.ttf.TrueTypeFont findFontOrSubstitute() throws IOException
      Throws:
      IOException
    • getFontMatrix

      public Matrix getFontMatrix()
      Description copied from interface: PDFontLike
      Returns the font matrix, which represents the transformation from glyph space to text space.
    • getBoundingBox

      public org.apache.fontbox.util.BoundingBox getBoundingBox() throws IOException
      Description copied from interface: PDFontLike
      Returns the font's bounding box.
      Throws:
      IOException
    • generateBoundingBox

      private org.apache.fontbox.util.BoundingBox generateBoundingBox() throws IOException
      Throws:
      IOException
    • codeToCID

      public int codeToCID(int code)
      Description copied from class: PDCIDFont
      Returns the CID for the given character code. If not found then CID 0 is returned.
      Specified by:
      codeToCID in class PDCIDFont
      Parameters:
      code - character code
      Returns:
      CID
    • codeToGID

      public int codeToGID(int code) throws IOException
      Returns the GID for the given character code.
      Specified by:
      codeToGID in class PDCIDFont
      Parameters:
      code - character code
      Returns:
      GID
      Throws:
      IOException
    • getHeight

      public float getHeight(int code) throws IOException
      Description copied from interface: PDFontLike
      Returns the height of the given character, in glyph space. This can be expensive to calculate. Results are only approximate.

      Warning: This method is deprecated in PDFBox 2.0 because there is no meaningful value which it can return. The PDFontLike.getWidth(int) method returns the advance width of a glyph, but there is no corresponding advance height. The logical height of a character is the same for every character in a font, so if you want that, retrieve the font bbox's height. Otherwise if you want the visual bounds of the glyph then call getPath(..) on the appropriate PDFont subclass to retrieve the glyph outline as a GeneralPath.
      Parameters:
      code - character code
      Throws:
      IOException
    • getWidthFromFont

      public float getWidthFromFont(int code) throws IOException
      Description copied from interface: PDFontLike
      Returns the width of a glyph in the embedded font file.
      Parameters:
      code - character code
      Returns:
      width in glyph space
      Throws:
      IOException - if the font could not be read
    • encode

      public byte[] encode(int unicode)
      Description copied from class: PDCIDFont
      Encodes the given Unicode code point for use in a PDF content stream. Content streams use a multi-byte encoding with 1 to 4 bytes.

      This method is called when embedding text in PDFs and when filling in fields.

      Specified by:
      encode in class PDCIDFont
      Parameters:
      unicode - Unicode code point.
      Returns:
      Array of 1 to 4 PDF content stream bytes.
    • generateInvertedUnicodeCmap

      private Map<String,Integer> generateInvertedUnicodeCmap()
      Inverts the unicode cmap from the parent and uses it for lookup
    • lookupInInvertedUnicodeCmap

      private int lookupInInvertedUnicodeCmap(int unicode)
    • isEmbedded

      public boolean isEmbedded()
      Description copied from interface: PDFontLike
      Returns true if the font file is embedded in the PDF.
    • isDamaged

      public boolean isDamaged()
      Description copied from interface: PDFontLike
      Returns true if the embedded font file is damaged.
    • getTrueTypeFont

      public org.apache.fontbox.ttf.TrueTypeFont getTrueTypeFont()
      Returns the embedded or substituted TrueType font. May be an OpenType font if the font is not embedded.
    • getPath

      public GeneralPath getPath(int code) throws IOException
      Description copied from interface: PDVectorFont
      Returns the glyph path for the given character code.
      Parameters:
      code - character code in a PDF. Not to be confused with unicode.
      Throws:
      IOException - if the font could not be read
    • hasGlyph

      public boolean hasGlyph(int code) throws IOException
      Description copied from interface: PDVectorFont
      Returns true if this font contains a glyph for the given character code.
      Parameters:
      code - character code in a PDF. Not to be confused with unicode.
      Throws:
      IOException
    • isOriginalEmbeddedMissing

      public boolean isOriginalEmbeddedMissing()
      Description copied from interface: PDFontLike
      Returns true if the font file that was supposed to be embedded in the PDF is missing.
    • isMappingFallbackUsed

      public boolean isMappingFallbackUsed()
      Description copied from interface: PDFontLike
      Returns true if a substitute font was searched via font mappings, but an exact match was not found, and a fallback was used