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

public Class PDCIDFontType0

extends PDCIDFont
Class Inheritance
Imports
java.awt.geom.AffineTransform, .GeneralPath, .Point2D, java.io.IOException, java.util.HashMap, .List, .Map, org.apache.commons.logging.Log, .LogFactory, org.apache.fontbox.FontBoxFont, org.apache.fontbox.cff.CFFCIDFont, .CFFFont, .CFFParser, .CFFType1Font, .Type2CharString, 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 0 CIDFont (CFF).
Authors
Ben Litchfield, John Hewson

Field Summary

Modifier and TypeField and Description
private Float
private int[]
private final CFFCIDFont
private BoundingBox
private Matrix
private final AffineTransform
private final Map<Integer, Float>
private final boolean
private final boolean
private static final Log
private final FontBoxFont
Inherited from org.apache.pdfbox.pdmodel.font.PDCIDFont:
dictparent

Constructor Summary

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

Constructor.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

CID
codeToCID
(int
character code
code
)

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

Returns the CID for the given character code.

public int
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 BoundingBox
private float
public float
public BoundingBox
getBoundingBox()

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

Returns the font's bounding box.

public CFFFont

Returns:

the embedded CFF CIDFont or null
getCFFFont
()

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

public FontBoxFont

Returns:

the embedded or substituted font
getFontBoxFont
()

Returns the embedded or substituted font.

public final Matrix
getFontMatrix()

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

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

private String
getGlyphName(int code)

Returns the name of the glyph with the given character code.

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.

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.

public Type2CharString

Returns:

the Type 2 charstring for the given CID or null
getType2CharString
(int
CID
cid
)

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

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

Field Detail

avgWidthback to summary
private Float avgWidth
cid2gidback to summary
private int[] cid2gid
cidFontback to summary
private final CFFCIDFont cidFont
fontBBoxback to summary
private BoundingBox fontBBox
fontMatrixback to summary
private Matrix fontMatrix
fontMatrixTransformback to summary
private final AffineTransform fontMatrixTransform
glyphHeightsback to summary
private final Map<Integer, Float> glyphHeights
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.

t1Fontback to summary
private final FontBoxFont t1Font

Constructor Detail

PDCIDFontType0back to summary
public PDCIDFontType0(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

Method Detail

codeToCIDback to summary
public int codeToCID(int code)

Implements abstract 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)

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

Doc from 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
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
generateBoundingBoxback to summary
private BoundingBox generateBoundingBox()
getAverageCharacterWidthback to summary
private float getAverageCharacterWidth()
getAverageFontWidthback to summary
public float getAverageFontWidth()

Overrides org.apache.pdfbox.pdmodel.font.PDCIDFont.getAverageFontWidth.

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

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

This will get the average font width for all characters.

Returns:float

The width is in 1000 unit of text space, ie 333 or 777

Annotations
@Override
getBoundingBoxback to summary
public BoundingBox getBoundingBox()

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
getCFFFontback to summary
public CFFFont getCFFFont()

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

Returns:CFFFont

the embedded CFF CIDFont or null

getFontBoxFontback to summary
public FontBoxFont getFontBoxFont()

Returns the embedded or substituted font.

Returns:FontBoxFont

the embedded or substituted font

getFontMatrixback to summary
public final 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
getGlyphNameback to summary
private String getGlyphName(int code)

Returns the name of the glyph with the given character code. This is done by looking up the code in the parent font's ToUnicode map and generating a glyph name from that.

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
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
getType2CharStringback to summary
public 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:int

CID

Returns:Type2CharString

the Type 2 charstring for the given CID or null

Exceptions
IOException:
if the charstring could not be read
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