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

public abstract Class PDCIDFont

extends Object
implements COSObjectable, PDFontLike, PDVectorFont
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.font.PDVectorFont, org.apache.pdfbox.pdmodel.font.PDFontLike, org.apache.pdfbox.pdmodel.common.COSObjectable
Known Direct Subclasses
org.apache.pdfbox.pdmodel.font.PDCIDFontType0, org.apache.pdfbox.pdmodel.font.PDCIDFontType2
Imports
java.io.IOException, .InputStream, java.util.HashMap, .Map, org.apache.commons.logging.Log, .LogFactory, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, .COSNumber, .COSStream, org.apache.pdfbox.io.IOUtils, org.apache.pdfbox.pdmodel.common.COSObjectable, org.apache.pdfbox.util.Vector

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.

Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private float
private float
protected final COSDictionary
private final float[]
private PDFontDescriptor
private static final Log
protected final PDType0Font
private final Map<Integer, Vector>
private final Map<Integer, Float>
private Map<Integer, Float>

Constructor Summary

AccessConstructor and Description
pack-priv
PDCIDFont(COSDictionary
The font dictionary according to the PDF specification.
fontDictionary
,
PDType0Font parent)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public abstract int

Returns:

CID
codeToCID
(int
character code
code
)

Returns the CID for the given character code.

public abstract int

Returns:

GID
codeToGID
(int
character code
code
)

Returns the GID for the given character code.

protected abstract byte[]

Returns:

Array of 1 to 4 PDF content stream bytes.
encode
(int
Unicode code point.
unicode
)

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

public abstract byte[]
encodeGlyphId(int glyphId)

public float
getAverageFontWidth()

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

This will get the average font width for all characters.

public String

Returns:

The postscript name of the font.
getBaseFont
()

The PostScript name of the font.

public PDCIDSystemInfo

Returns:

the CIDSystemInfo, or null
getCIDSystemInfo
()

Returns the CIDSystemInfo, or null if it is missing (which isn't allowed but could happen).

public COSDictionary
getCOSObject()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this standard java object to a COS object.

private Vector
getDefaultPositionVector(int
CID
cid
)

Returns the default position vector (v).

private float

Returns:

The default width for the glyphs in this font.
getDefaultWidth
()

This will get the default width.

public PDFontDescriptor
getFontDescriptor()

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

Returns the font descriptor, may be null.

public String
getName()

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

Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".

public final PDType0Font

Returns:

parent Type 0 font
getParent
()

Returns the Type 0 font which is the parent of this font.

public Vector
getPositionVector(int
character code
code
)

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

Returns the position vector (v), in text space, for the given character.

public float

Returns:

w1y
getVerticalDisplacementVectorY
(int
character code
code
)

Returns the y-component of the vertical displacement vector (w1).

public float
getWidth(int
character code
code
)

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

Returns the advance width of the given character, in glyph space.

private float
getWidthForCID(int cid)

public boolean
hasExplicitWidth(int
character code
code
)

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

Returns true if the Font dictionary specifies an explicit width for the given glyph.

pack-priv final int[]
private void
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

averageWidthback to summary
private float averageWidth
defaultWidthback to summary
private float defaultWidth
dictback to summary
protected final COSDictionary dict
dw2back to summary
private final float[] dw2
fontDescriptorback to summary
private PDFontDescriptor fontDescriptor
LOGback to summary
private static final Log LOG
parentback to summary
protected final PDType0Font parent
positionVectorsback to summary
private final Map<Integer, Vector> positionVectors
verticalDisplacementYback to summary
private final Map<Integer, Float> verticalDisplacementY
widthsback to summary
private Map<Integer, Float> widths

Constructor Detail

PDCIDFontback to summary
pack-priv PDCIDFont(COSDictionary fontDictionary, PDType0Font parent)

Constructor.

Parameters
fontDictionary:COSDictionary

The font dictionary according to the PDF specification.

Method Detail

codeToCIDback to summary
public abstract int codeToCID(int code)

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

Parameters
code:int

character code

Returns:int

CID

codeToGIDback to summary
public abstract int codeToGID(int code) throws IOException

Returns the GID for the given character code.

Parameters
code:int

character code

Returns:int

GID

Exceptions
IOException:
if the mapping could not be read
encodeback to summary
protected abstract byte[] encode(int unicode) throws IOException

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.

Exceptions
IOException:
If the text could not be encoded.
encodeGlyphIdback to summary
public abstract byte[] encodeGlyphId(int glyphId)
getAverageFontWidthback to summary
public float 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
getBaseFontback to summary
public String getBaseFont()

The PostScript name of the font.

Returns:String

The postscript name of the font.

getCIDSystemInfoback to summary
public PDCIDSystemInfo getCIDSystemInfo()

Returns the CIDSystemInfo, or null if it is missing (which isn't allowed but could happen).

Returns:PDCIDSystemInfo

the CIDSystemInfo, or null

getCOSObjectback to summary
public COSDictionary getCOSObject()

Implements org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Doc from org.apache.pdfbox.pdmodel.common.COSObjectable.getCOSObject.

Convert this standard java object to a COS object.

Returns:COSDictionary

The cos object that matches this Java object.

Annotations
@Override
getDefaultPositionVectorback to summary
private Vector getDefaultPositionVector(int cid)

Returns the default position vector (v).

Parameters
cid:int

CID

getDefaultWidthback to summary
private float getDefaultWidth()

This will get the default width. The default value for the default width is 1000.

Returns:float

The default width for the glyphs in this font.

getFontDescriptorback to summary
public PDFontDescriptor getFontDescriptor()

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

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

Returns the font descriptor, may be null.

Returns:PDFontDescriptor

the font descriptor or null

Annotations
@Override
getNameback to summary
public String getName()

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

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

Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".

Returns:String

the name of the font

Annotations
@Override
getParentback to summary
public final PDType0Font getParent()

Returns the Type 0 font which is the parent of this font.

Returns:PDType0Font

parent Type 0 font

getPositionVectorback to summary
public Vector getPositionVector(int code)

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

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

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

Parameters
code:int

character code

Returns:Vector

position vector

Annotations
@Override
getVerticalDisplacementVectorYback to summary
public float getVerticalDisplacementVectorY(int code)

Returns the y-component of the vertical displacement vector (w1).

Parameters
code:int

character code

Returns:float

w1y

getWidthback to summary
public float getWidth(int code) throws IOException

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

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

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

Parameters
code:int

character code

Returns:float

the width of the given character

Annotations
@Override
Exceptions
IOException:
if the width could not be read
getWidthForCIDback to summary
private float getWidthForCID(int cid)
hasExplicitWidthback to summary
public boolean hasExplicitWidth(int code) throws IOException

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

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

Returns true if the Font dictionary specifies an explicit width for the given glyph. This includes Width, W but not default widths entries.

Parameters
code:int

character code

Returns:boolean

true if the Font dictionary specifies an explicit width for the given glyph

Annotations
@Override
Exceptions
IOException:
if the font could not be read
readCIDToGIDMapback to summary
pack-priv final int[] readCIDToGIDMap() throws IOException
readVerticalDisplacementsback to summary
private void readVerticalDisplacements()
readWidthsback to summary
private void readWidths()