org.apache.pdfbox.pdmodel.font

## Class PDCIDFontType0

- java.lang.Object
- - org.apache.pdfbox.pdmodel.font.PDCIDFont
  - - org.apache.pdfbox.pdmodel.font.PDCIDFontType0

All Implemented Interfaces:
  COSObjectable, PDFontLike, PDVectorFont

    public class PDCIDFontType0
    extends PDCIDFont

Type 0 CIDFont (CFF).

Author:
  Ben Litchfield, John Hewson

### Field Summary

### Fields inherited from class org.apache.pdfbox.pdmodel.font.PDCIDFont

`dict, parent`

### Constructor Summary

Constructors
Constructor and Description
`PDCIDFontType0(COSDictionary fontDictionary, PDType0Font parent)` Constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`int` `codeToCID(int code)` Returns the CID for the given character code.
`int` `codeToGID(int code)` Returns the GID for the given character code.
`byte[]` `encode(int unicode)` Encodes the given Unicode code point for use in a PDF content stream.
`byte[]` `encodeGlyphId(int glyphId)`
`float` `getAverageFontWidth()` This will get the average font width for all characters.
`org.apache.fontbox.util.BoundingBox` `getBoundingBox()` Returns the font's bounding box.
`org.apache.fontbox.cff.CFFFont` `getCFFFont()` Returns the embedded CFF CIDFont, or null if the substitute is not a CFF font.
`org.apache.fontbox.FontBoxFont` `getFontBoxFont()` Returns the embedded or substituted font.
`Matrix` `getFontMatrix()` Returns the font matrix, which represents the transformation from glyph space to text space.
`float` `getHeight(int code)` Returns the height of the given character, in glyph space.
`GeneralPath` `getNormalizedPath(int code)` Returns the normalized glyph path for the given character code in a PDF.
`GeneralPath` `getPath(int code)` Returns the glyph path for the given character code.
`org.apache.fontbox.cff.Type2CharString` `getType2CharString(int cid)` Returns the Type 2 charstring for the given CID, or null if the substituted font does not contain Type 2 charstrings.
`float` `getWidthFromFont(int code)` Returns the width of a glyph in the embedded font file.
`boolean` `hasGlyph(int code)` Returns true if this font contains a glyph for the given character code in a PDF.
`boolean` `isDamaged()` Returns true if the embedded font file is damaged.
`boolean` `isEmbedded()` Returns true if the font file is embedded in the PDF.

### Methods inherited from class org.apache.pdfbox.pdmodel.font.PDCIDFont

`getBaseFont, getCIDSystemInfo, getCOSObject, getFontDescriptor, getName, getParent, getPositionVector, getVerticalDisplacementVectorY, getWidth, hasExplicitWidth`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### PDCIDFontType0

    public PDCIDFontType0(COSDictionary fontDictionary,
                          PDType0Font parent)
                   throws IOException

Constructor.

Parameters:
  `fontDictionary` - The font dictionary according to the PDF specification.
  `parent` - The parent font.
Throws:
  `IOException` - if the font could not be read

### Method Detail

#### getFontMatrix

    public final Matrix getFontMatrix()

Description copied from interface: `PDFontLike`
Returns the font matrix, which represents the transformation from glyph space to text space.

Returns:
  the font matrix

#### getBoundingBox

    public org.apache.fontbox.util.BoundingBox getBoundingBox()

Description copied from interface: `PDFontLike`
Returns the font's bounding box.

Returns:
  the bounding box

#### getCFFFont

    public org.apache.fontbox.cff.CFFFont getCFFFont()

Returns the embedded CFF CIDFont, or null if the substitute is not a CFF font.

Returns:
  the embedded CFF CIDFont or null

#### getFontBoxFont

    public org.apache.fontbox.FontBoxFont getFontBoxFont()

Returns the embedded or substituted font.

Returns:
  the embedded or substituted font

#### getType2CharString

    public org.apache.fontbox.cff.Type2CharString getType2CharString(int cid)
                                                              throws IOException

Returns the Type 2 charstring for the given CID, or null if the substituted font does not contain Type 2 charstrings.

Parameters:
  `cid` - CID
Returns:
  the Type 2 charstring for the given CID or null
Throws:
  `IOException` - if the charstring could not be read

#### 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.
Returns:
  the glyph path for the given character code
Throws:
  `IOException` - if the font could not be read

#### getNormalizedPath

    public GeneralPath getNormalizedPath(int code)
                                  throws IOException

Description copied from interface: `PDVectorFont`
Returns the normalized glyph path for the given character code in a PDF. The resulting path is normalized to the PostScript 1000 unit square, and fallback glyphs are returned where appropriate, e.g. for missing glyphs.

Parameters:
  `code` - character code in a PDF. Not to be confused with unicode.
Returns:
  the normalized glyph path for the given character code
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 in a PDF.

Parameters:
  `code` - character code in a PDF. Not to be confused with unicode.
Returns:
  true if this font contains a glyph for the given character code
Throws:
  `IOException` - if the font could not be read

#### codeToCID

    public int codeToCID(int code)

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)

Description copied from class: `PDCIDFont`
Returns the GID for the given character code.

Specified by:
  `codeToGID` in class `PDCIDFont`
Parameters:
  `code` - character code
Returns:
  GID

#### 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.

#### encodeGlyphId

    public byte[] encodeGlyphId(int glyphId)

Specified by:
  `encodeGlyphId` in class `PDCIDFont`

#### 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

#### isEmbedded

    public boolean isEmbedded()

Description copied from interface: `PDFontLike`
Returns true if the font file is embedded in the PDF.

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.

Returns:
  true if the embedded font file is damaged

#### 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. See the cyan rectangles in the DrawPrintTextLocations.java example to see this in action.

Parameters:
  `code` - character code
Returns:
  the height of the given character
Throws:
  `IOException` - if the height could not be read

#### getAverageFontWidth

    public float getAverageFontWidth()

Description copied from interface: `PDFontLike`
This will get the average font width for all characters.

Specified by:
  `getAverageFontWidth` in interface `PDFontLike`
Overrides:
  `getAverageFontWidth` in class `PDCIDFont`
Returns:
  The width is in 1000 unit of text space, ie 333 or 777