Top Description Fields Constructors Methods
org.apache.pdfbox.pdmodel.font

public Class PDCIDFontType2

extends PDCIDFont
Class Inheritance
Imports
java.awt.geom.AffineTransform, .GeneralPath, java.io.IOException, java.nio.charset.StandardCharsets, java.util.HashSet, .Set, org.apache.commons.logging.Log, .LogFactory, org.apache.fontbox.cff.CFFFont, .Type2CharString, org.apache.fontbox.cmap.CMap, org.apache.fontbox.ttf.CmapLookup, .GlyphData, .OTFParser, .OpenTypeFont, .TTFParser, .TrueTypeFont, org.apache.fontbox.util.BoundingBox, org.apache.pdfbox.cos.COSDictionary, org.apache.pdfbox.io.RandomAccessRead, org.apache.pdfbox.pdmodel.common.PDRectangle, .PDStream, org.apache.pdfbox.util.Matrix

Type 2 CIDFont (TrueType).
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private final int[]
private final CmapLookup
private BoundingBox
private Matrix
private final boolean
private final boolean
private static final Log
private final Set<Integer>
private final OpenTypeFont
private final TrueTypeFont
Inherited from org.apache.pdfbox.pdmodel.font.PDCIDFont:
dictparent

Constructor Summary

AccessConstructor and Description
public
PDCIDFontType2(COSDictionary
The font dictionary according to the PDF specification.
fontDictionary
,
PDType0Font
The parent font.
parent
)

Constructor.

public
PDCIDFontType2(COSDictionary
The font dictionary according to the PDF specification.
fontDictionary
,
PDType0Font
The parent font.
parent
,
TrueTypeFont
The true type font used to create the parent font
trueTypeFont
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public int
codeToCID(int
character code
code
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDCIDFont.codeToCID.

Returns the CID for the given character code.

public int

Returns:

GID
codeToGID
(int
character code
code
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDCIDFont.codeToGID.

Returns the GID for the given character code.

public byte[]
encode(int
Unicode code point.
unicode
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDCIDFont.encode.

Encodes the given Unicode code point for use in a PDF content stream.

public byte[]
private TrueTypeFont
private BoundingBox
public BoundingBox
getBoundingBox()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getBoundingBox.

Returns the font's bounding box.

public Matrix
getFontMatrix()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getFontMatrix.

Returns the font matrix, which represents the transformation from glyph space to text space.

public float
getHeight(int
character code
code
)

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getHeight.

Returns the height of the given character, in glyph space.

public GeneralPath
getNormalizedPath(int
character code in a PDF. Not to be confused with unicode.
code
)

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.getNormalizedPath.

Returns the normalized glyph path for the given character code in a PDF.

private TTFParser
getParser(RandomAccessRead randomAccessRead, boolean isEmbedded)

public GeneralPath
getPath(int
character code in a PDF. Not to be confused with unicode.
code
)

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.getPath.

Returns the glyph path for the given character code.

private GeneralPath
public TrueTypeFont

Returns:

the embedded or substituted TrueType font
getTrueTypeFont
()

Returns the embedded or substituted TrueType font.

public float
getWidthFromFont(int
character code
code
)

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getWidthFromFont.

Returns the width of a glyph in the embedded font file.

public boolean
hasGlyph(int
character code in a PDF. Not to be confused with unicode.
code
)

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.hasGlyph.

Returns true if this font contains a glyph for the given character code in a PDF.

public boolean
isDamaged()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.isDamaged.

Returns true if the embedded font file is damaged.

public boolean
isEmbedded()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.isEmbedded.

Returns true if the font file is embedded in the PDF.

Inherited from org.apache.pdfbox.pdmodel.font.PDCIDFont:
getAverageFontWidthgetBaseFontgetCIDSystemInfogetCOSObjectgetFontDescriptorgetNamegetParentgetPositionVectorgetVerticalDisplacementVectorYgetWidthhasExplicitWidthreadCIDToGIDMap

Field Detail

cid2gidback to summary
private final int[] cid2gid
cmapback to summary
private final CmapLookup cmap
fontBBoxback to summary
private BoundingBox fontBBox
fontMatrixback to summary
private Matrix fontMatrix
isDamagedback to summary
private final boolean isDamaged
isEmbeddedback to summary
private final boolean isEmbedded
LOGback to summary
private static final Log LOG

Hides org.apache.pdfbox.pdmodel.font.PDCIDFont.LOG.

noMappingback to summary
private final Set<Integer> noMapping
otfback to summary
private final OpenTypeFont otf
ttfback to summary
private final TrueTypeFont ttf

Constructor Detail

PDCIDFontType2back to summary
public PDCIDFontType2(COSDictionary fontDictionary, PDType0Font parent) throws IOException

Constructor.

Parameters
fontDictionary:COSDictionary

The font dictionary according to the PDF specification.

parent:PDType0Font

The parent font.

Exceptions
IOException:
if the font could not be read
PDCIDFontType2back to summary
public PDCIDFontType2(COSDictionary fontDictionary, PDType0Font parent, TrueTypeFont trueTypeFont) throws IOException

Constructor.

Parameters
fontDictionary:COSDictionary

The font dictionary according to the PDF specification.

parent:PDType0Font

The parent font.

trueTypeFont:TrueTypeFont

The true type font used to create the parent font

Exceptions
IOException:
if the font could not be read

Method Detail

codeToCIDback to summary
public int codeToCID(int code)

Implements abstract org.apache.pdfbox.pdmodel.font.PDCIDFont.codeToCID.

Doc from org.apache.pdfbox.pdmodel.font.PDCIDFont.codeToCID.

Returns the CID for the given character code. If not found then CID 0 is returned.

Parameters
code:int

character code

Returns:int

CID

Annotations
@Override
codeToGIDback to summary
public int codeToGID(int code) throws IOException

Implements abstract org.apache.pdfbox.pdmodel.font.PDCIDFont.codeToGID.

Returns the GID for the given character code.

Parameters
code:int

character code

Returns:int

GID

Annotations
@Override
Exceptions
IOException:
if the mapping could not be read
encodeback to summary
public byte[] encode(int unicode)

Implements abstract org.apache.pdfbox.pdmodel.font.PDCIDFont.encode.

Doc from org.apache.pdfbox.pdmodel.font.PDCIDFont.encode.

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.

Parameters
unicode:int

Unicode code point.

Returns:byte[]

Array of 1 to 4 PDF content stream bytes.

Annotations
@Override
encodeGlyphIdback to summary
public byte[] encodeGlyphId(int glyphId)

Implements abstract org.apache.pdfbox.pdmodel.font.PDCIDFont.encodeGlyphId.

Annotations
@Override
findFontOrSubstituteback to summary
private TrueTypeFont findFontOrSubstitute() throws IOException
generateBoundingBoxback to summary
private BoundingBox generateBoundingBox() throws IOException
getBoundingBoxback to summary
public BoundingBox getBoundingBox() throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getBoundingBox.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getBoundingBox.

Returns the font's bounding box.

Returns:BoundingBox

the bounding box

Annotations
@Override
Exceptions
IOException:
if the bounding box could not be read
getFontMatrixback to summary
public Matrix getFontMatrix()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getFontMatrix.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getFontMatrix.

Returns the font matrix, which represents the transformation from glyph space to text space.

Returns:Matrix

the font matrix

Annotations
@Override
getHeightback to summary
public float getHeight(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getHeight.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getHeight.

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 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:int

character code

Returns:float

the height of the given character

Annotations
@Override
Exceptions
IOException:
if the height could not be read
getNormalizedPathback to summary
public GeneralPath getNormalizedPath(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.getNormalizedPath.

Doc from org.apache.pdfbox.pdmodel.font.PDVectorFont.getNormalizedPath.

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:int

character code in a PDF. Not to be confused with unicode.

Returns:GeneralPath

the normalized glyph path for the given character code

Annotations
@Override
Exceptions
IOException:
if the font could not be read
getParserback to summary
private TTFParser getParser(RandomAccessRead randomAccessRead, boolean isEmbedded) throws IOException
getPathback to summary
public GeneralPath getPath(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.getPath.

Doc from org.apache.pdfbox.pdmodel.font.PDVectorFont.getPath.

Returns the glyph path for the given character code.

Parameters
code:int

character code in a PDF. Not to be confused with unicode.

Returns:GeneralPath

the glyph path for the given character code

Annotations
@Override
Exceptions
IOException:
if the font could not be read
getPathFromOutlinesback to summary
private GeneralPath getPathFromOutlines(int code) throws IOException
getTrueTypeFontback to summary
public TrueTypeFont getTrueTypeFont()

Returns the embedded or substituted TrueType font. May be an OpenType font if the font is not embedded.

Returns:TrueTypeFont

the embedded or substituted TrueType font

getWidthFromFontback to summary
public float getWidthFromFont(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.getWidthFromFont.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.getWidthFromFont.

Returns the width of a glyph in the embedded font file.

Parameters
code:int

character code

Returns:float

width in glyph space

Annotations
@Override
Exceptions
IOException:
if the font could not be read
hasGlyphback to summary
public boolean hasGlyph(int code) throws IOException

Implements org.apache.pdfbox.pdmodel.font.PDVectorFont.hasGlyph.

Doc from org.apache.pdfbox.pdmodel.font.PDVectorFont.hasGlyph.

Returns true if this font contains a glyph for the given character code in a PDF.

Parameters
code:int

character code in a PDF. Not to be confused with unicode.

Returns:boolean

true if this font contains a glyph for the given character code

Annotations
@Override
Exceptions
IOException:
if the font could not be read
isDamagedback to summary
public boolean isDamaged()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.isDamaged.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.isDamaged.

Returns true if the embedded font file is damaged.

Returns:boolean

true if the embedded font file is damaged

Annotations
@Override
isEmbeddedback to summary
public boolean isEmbedded()

Implements org.apache.pdfbox.pdmodel.font.PDFontLike.isEmbedded.

Doc from org.apache.pdfbox.pdmodel.font.PDFontLike.isEmbedded.

Returns true if the font file is embedded in the PDF.

Returns:boolean

true if the font file is embedded in the PDF

Annotations
@Override