Package org.apache.pdfbox.pdmodel.font
Class PDCIDFontType2
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.font.PDCIDFont
-
- org.apache.pdfbox.pdmodel.font.PDCIDFontType2
-
- All Implemented Interfaces:
COSObjectable,PDFontLike,PDVectorFont
public class PDCIDFontType2 extends PDCIDFont
Type 2 CIDFont (TrueType).
-
-
Field Summary
Fields Modifier and Type Field Description private int[]cid2gidprivate CmapLookupcmapprivate BoundingBoxfontBBoxprivate MatrixfontMatrixprivate booleanisDamagedprivate booleanisEmbeddedprivate static org.apache.commons.logging.LogLOGprivate java.util.Set<java.lang.Integer>noMappingprivate OpenTypeFontotfprivate TrueTypeFontttf
-
Constructor Summary
Constructors Constructor Description PDCIDFontType2(COSDictionary fontDictionary, PDType0Font parent)Constructor.PDCIDFontType2(COSDictionary fontDictionary, PDType0Font parent, TrueTypeFont trueTypeFont)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcodeToCID(int code)Returns the CID for the given character code.intcodeToGID(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)private TrueTypeFontfindFontOrSubstitute()private BoundingBoxgenerateBoundingBox()BoundingBoxgetBoundingBox()Returns the font's bounding box.MatrixgetFontMatrix()Returns the font matrix, which represents the transformation from glyph space to text space.floatgetHeight(int code)Returns the height of the given character, in glyph space.java.awt.geom.GeneralPathgetNormalizedPath(int code)Returns the normalized glyph path for the given character code in a PDF.private TTFParsergetParser(RandomAccessRead randomAccessRead, boolean isEmbedded)java.awt.geom.GeneralPathgetPath(int code)Returns the glyph path for the given character code.private java.awt.geom.GeneralPathgetPathFromOutlines(int code)TrueTypeFontgetTrueTypeFont()Returns the embedded or substituted TrueType font.floatgetWidthFromFont(int code)Returns the width of a glyph in the embedded font file.booleanhasGlyph(int code)Returns true if this font contains a glyph for the given character code in a PDF.booleanisDamaged()Returns true if the embedded font file is damaged.booleanisEmbedded()Returns true if the font file is embedded in the PDF.-
Methods inherited from class org.apache.pdfbox.pdmodel.font.PDCIDFont
getAverageFontWidth, getBaseFont, getCIDSystemInfo, getCOSObject, getFontDescriptor, getName, getParent, getPositionVector, getVerticalDisplacementVectorY, getWidth, hasExplicitWidth, readCIDToGIDMap
-
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
ttf
private final TrueTypeFont ttf
-
otf
private final OpenTypeFont otf
-
cid2gid
private final int[] cid2gid
-
isEmbedded
private final boolean isEmbedded
-
isDamaged
private final boolean isDamaged
-
cmap
private final CmapLookup cmap
-
fontMatrix
private Matrix fontMatrix
-
fontBBox
private BoundingBox fontBBox
-
noMapping
private final java.util.Set<java.lang.Integer> noMapping
-
-
Constructor Detail
-
PDCIDFontType2
public PDCIDFontType2(COSDictionary fontDictionary, PDType0Font parent) throws java.io.IOException
Constructor.- Parameters:
fontDictionary- The font dictionary according to the PDF specification.parent- The parent font.- Throws:
java.io.IOException- if the font could not be read
-
PDCIDFontType2
public PDCIDFontType2(COSDictionary fontDictionary, PDType0Font parent, TrueTypeFont trueTypeFont) throws java.io.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:
java.io.IOException- if the font could not be read
-
-
Method Detail
-
findFontOrSubstitute
private TrueTypeFont findFontOrSubstitute() throws java.io.IOException
- Throws:
java.io.IOException
-
getFontMatrix
public Matrix getFontMatrix()
Description copied from interface:PDFontLikeReturns the font matrix, which represents the transformation from glyph space to text space.- Returns:
- the font matrix
-
getBoundingBox
public BoundingBox getBoundingBox() throws java.io.IOException
Description copied from interface:PDFontLikeReturns the font's bounding box.- Returns:
- the bounding box
- Throws:
java.io.IOException- if the bounding box could not be read
-
generateBoundingBox
private BoundingBox generateBoundingBox() throws java.io.IOException
- Throws:
java.io.IOException
-
codeToCID
public int codeToCID(int code)
Description copied from class:PDCIDFontReturns the CID for the given character code. If not found then CID 0 is returned.
-
codeToGID
public int codeToGID(int code) throws java.io.IOExceptionReturns the GID for the given character code.
-
getHeight
public float getHeight(int code) throws java.io.IOExceptionDescription copied from interface:PDFontLikeReturns 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:
java.io.IOException- if the height could not be read
-
getWidthFromFont
public float getWidthFromFont(int code) throws java.io.IOExceptionDescription copied from interface:PDFontLikeReturns the width of a glyph in the embedded font file.- Parameters:
code- character code- Returns:
- width in glyph space
- Throws:
java.io.IOException- if the font could not be read
-
encode
public byte[] encode(int unicode)
Description copied from class:PDCIDFontEncodes 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.
-
encodeGlyphId
public byte[] encodeGlyphId(int glyphId)
- Specified by:
encodeGlyphIdin classPDCIDFont
-
isEmbedded
public boolean isEmbedded()
Description copied from interface:PDFontLikeReturns 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:PDFontLikeReturns true if the embedded font file is damaged.- Returns:
- true if the embedded font file is damaged
-
getTrueTypeFont
public TrueTypeFont getTrueTypeFont()
Returns the embedded or substituted TrueType font. May be an OpenType font if the font is not embedded.- Returns:
- the embedded or substituted TrueType font
-
getPath
public java.awt.geom.GeneralPath getPath(int code) throws java.io.IOExceptionDescription copied from interface:PDVectorFontReturns 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:
java.io.IOException- if the font could not be read
-
getNormalizedPath
public java.awt.geom.GeneralPath getNormalizedPath(int code) throws java.io.IOExceptionDescription copied from interface:PDVectorFontReturns 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:
java.io.IOException- if the font could not be read
-
getPathFromOutlines
private java.awt.geom.GeneralPath getPathFromOutlines(int code) throws java.io.IOException- Throws:
java.io.IOException
-
hasGlyph
public boolean hasGlyph(int code) throws java.io.IOExceptionDescription copied from interface:PDVectorFontReturns 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:
java.io.IOException- if the font could not be read
-
getParser
private TTFParser getParser(RandomAccessRead randomAccessRead, boolean isEmbedded) throws java.io.IOException
- Throws:
java.io.IOException
-
-