Package org.apache.pdfbox.pdmodel.font
Class PDCIDFont
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.font.PDCIDFont
-
- All Implemented Interfaces:
COSObjectable,PDFontLike,PDVectorFont
- Direct Known Subclasses:
PDCIDFontType0,PDCIDFontType2
public abstract class PDCIDFont extends java.lang.Object implements COSObjectable, PDFontLike, PDVectorFont
A CIDFont. A CIDFont is a PDF object that contains information about a CIDFont program. Although its Type value is Font, a CIDFont is not actually a font.It is not usually necessary to use this class directly, prefer
PDType0Font.
-
-
Field Summary
Fields Modifier and Type Field Description private floataverageWidthprivate floatdefaultWidthprotected COSDictionarydictprivate float[]dw2private PDFontDescriptorfontDescriptorprivate static org.apache.commons.logging.LogLOGprotected PDType0Fontparentprivate java.util.Map<java.lang.Integer,Vector>positionVectorsprivate java.util.Map<java.lang.Integer,java.lang.Float>verticalDisplacementYprivate java.util.Map<java.lang.Integer,java.lang.Float>widths
-
Constructor Summary
Constructors Constructor Description PDCIDFont(COSDictionary fontDictionary, PDType0Font parent)Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract intcodeToCID(int code)Returns the CID for the given character code.abstract intcodeToGID(int code)Returns the GID for the given character code.protected abstract byte[]encode(int unicode)Encodes the given Unicode code point for use in a PDF content stream.abstract byte[]encodeGlyphId(int glyphId)floatgetAverageFontWidth()This will get the average font width for all characters.java.lang.StringgetBaseFont()The PostScript name of the font.PDCIDSystemInfogetCIDSystemInfo()Returns the CIDSystemInfo, or null if it is missing (which isn't allowed but could happen).COSDictionarygetCOSObject()Convert this standard java object to a COS object.private VectorgetDefaultPositionVector(int cid)Returns the default position vector (v).private floatgetDefaultWidth()This will get the default width.PDFontDescriptorgetFontDescriptor()Returns the font descriptor, may be null.java.lang.StringgetName()Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".PDType0FontgetParent()Returns the Type 0 font which is the parent of this font.VectorgetPositionVector(int code)Returns the position vector (v), in text space, for the given character.floatgetVerticalDisplacementVectorY(int code)Returns the y-component of the vertical displacement vector (w1).floatgetWidth(int code)Returns the advance width of the given character, in glyph space.private floatgetWidthForCID(int cid)booleanhasExplicitWidth(int code)Returns true if the Font dictionary specifies an explicit width for the given glyph.(package private) int[]readCIDToGIDMap()private voidreadVerticalDisplacements()private voidreadWidths()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.pdfbox.pdmodel.font.PDFontLike
getBoundingBox, getFontMatrix, getHeight, getWidthFromFont, isDamaged, isEmbedded
-
Methods inherited from interface org.apache.pdfbox.pdmodel.font.PDVectorFont
getNormalizedPath, getPath, hasGlyph
-
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
parent
protected final PDType0Font parent
-
widths
private java.util.Map<java.lang.Integer,java.lang.Float> widths
-
defaultWidth
private float defaultWidth
-
averageWidth
private float averageWidth
-
verticalDisplacementY
private final java.util.Map<java.lang.Integer,java.lang.Float> verticalDisplacementY
-
positionVectors
private final java.util.Map<java.lang.Integer,Vector> positionVectors
-
dw2
private final float[] dw2
-
dict
protected final COSDictionary dict
-
fontDescriptor
private PDFontDescriptor fontDescriptor
-
-
Constructor Detail
-
PDCIDFont
PDCIDFont(COSDictionary fontDictionary, PDType0Font parent)
Constructor.- Parameters:
fontDictionary- The font dictionary according to the PDF specification.
-
-
Method Detail
-
readWidths
private void readWidths()
-
readVerticalDisplacements
private void readVerticalDisplacements()
-
getCOSObject
public COSDictionary getCOSObject()
Description copied from interface:COSObjectableConvert this standard java object to a COS object.- Specified by:
getCOSObjectin interfaceCOSObjectable- Returns:
- The cos object that matches this Java object.
-
getBaseFont
public java.lang.String getBaseFont()
The PostScript name of the font.- Returns:
- The postscript name of the font.
-
getName
public java.lang.String getName()
Description copied from interface:PDFontLikeReturns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".- Specified by:
getNamein interfacePDFontLike- Returns:
- the name of the font
-
getFontDescriptor
public PDFontDescriptor getFontDescriptor()
Description copied from interface:PDFontLikeReturns the font descriptor, may be null.- Specified by:
getFontDescriptorin interfacePDFontLike- Returns:
- the font descriptor or null
-
getParent
public final PDType0Font getParent()
Returns the Type 0 font which is the parent of this font.- Returns:
- parent Type 0 font
-
getDefaultWidth
private float getDefaultWidth()
This will get the default width. The default value for the default width is 1000.- Returns:
- The default width for the glyphs in this font.
-
getDefaultPositionVector
private Vector getDefaultPositionVector(int cid)
Returns the default position vector (v).- Parameters:
cid- CID
-
getWidthForCID
private float getWidthForCID(int cid)
-
hasExplicitWidth
public boolean hasExplicitWidth(int code) throws java.io.IOExceptionDescription copied from interface:PDFontLikeReturns true if the Font dictionary specifies an explicit width for the given glyph. This includes Width, W but not default widths entries.- Specified by:
hasExplicitWidthin interfacePDFontLike- Parameters:
code- character code- Returns:
- true if the Font dictionary specifies an explicit width for the given glyph
- Throws:
java.io.IOException- if the font could not be read
-
getPositionVector
public Vector getPositionVector(int code)
Description copied from interface:PDFontLikeReturns the position vector (v), in text space, for the given character. This represents the position of vertical origin relative to horizontal origin, for horizontal writing it will always be (0, 0). For vertical writing both x and y are set.- Specified by:
getPositionVectorin interfacePDFontLike- Parameters:
code- character code- Returns:
- position vector
-
getVerticalDisplacementVectorY
public float getVerticalDisplacementVectorY(int code)
Returns the y-component of the vertical displacement vector (w1).- Parameters:
code- character code- Returns:
- w1y
-
getWidth
public float getWidth(int code) throws java.io.IOExceptionDescription copied from interface:PDFontLikeReturns the advance width of the given character, in glyph space.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 instead. See the cyan rectangles in the DrawPrintTextLocations.java example to see this in action.
- Specified by:
getWidthin interfacePDFontLike- Parameters:
code- character code- Returns:
- the width of the given character
- Throws:
java.io.IOException- if the width could not be read
-
getAverageFontWidth
public float getAverageFontWidth()
Description copied from interface:PDFontLikeThis will get the average font width for all characters.- Specified by:
getAverageFontWidthin interfacePDFontLike- Returns:
- The width is in 1000 unit of text space, ie 333 or 777
-
getCIDSystemInfo
public PDCIDSystemInfo getCIDSystemInfo()
Returns the CIDSystemInfo, or null if it is missing (which isn't allowed but could happen).- Returns:
- the CIDSystemInfo, or null
-
codeToCID
public abstract int codeToCID(int code)
Returns the CID for the given character code. If not found then CID 0 is returned.- Parameters:
code- character code- Returns:
- CID
-
codeToGID
public abstract int codeToGID(int code) throws java.io.IOExceptionReturns the GID for the given character code.- Parameters:
code- character code- Returns:
- GID
- Throws:
java.io.IOException- if the mapping could not be read
-
encodeGlyphId
public abstract byte[] encodeGlyphId(int glyphId)
-
encode
protected abstract byte[] encode(int unicode) throws java.io.IOExceptionEncodes 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- Unicode code point.- Returns:
- Array of 1 to 4 PDF content stream bytes.
- Throws:
java.io.IOException- If the text could not be encoded.
-
readCIDToGIDMap
final int[] readCIDToGIDMap() throws java.io.IOException- Throws:
java.io.IOException
-
-