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

public Class PDType3Font

extends PDSimpleFont
Class Inheritance
Imports
java.awt.geom.GeneralPath, java.io.IOException, .InputStream, java.util.List, .Objects, org.apache.commons.logging.Log, .LogFactory, org.apache.fontbox.FontBoxFont, org.apache.fontbox.util.BoundingBox, org.apache.pdfbox.cos.COSArray, .COSBase, .COSDictionary, .COSName, .COSStream, org.apache.pdfbox.pdmodel.PDResources, .ResourceCache, org.apache.pdfbox.pdmodel.common.PDRectangle, org.apache.pdfbox.pdmodel.font.encoding.DictionaryEncoding, .Encoding, .GlyphList, org.apache.pdfbox.util.Matrix, .Vector

A PostScript Type 3 Font.
Author
Ben Litchfield

Field Summary

Modifier and TypeField and Description
private COSDictionary
private BoundingBox
private Matrix
private static final Log
private final ResourceCache
private PDResources
Inherited from org.apache.pdfbox.pdmodel.font.PDSimpleFont:
encodingglyphList

Constructor Summary

AccessConstructor and Description
public
PDType3Font(COSDictionary
The font dictionary according to the PDF specification.
fontDictionary
)

Constructor.

public
PDType3Font(COSDictionary
The font dictionary according to the PDF specification.
fontDictionary
,
ResourceCache
Resource cache, can be null.
resourceCache
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
private boolean
protected byte[]
encode(int
Unicode code point.
unicode
)

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

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

private BoundingBox
public BoundingBox
getBoundingBox()

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

Returns the font's bounding box.

public PDType3CharProc

Returns:

the stream to be used to render the glyph
getCharProc
(int
character code
code
)

Returns the stream of the glyph for the given character code

public COSDictionary

Returns:

the dictionary containing all glyph streams.
getCharProcs
()

Returns the dictionary containing all streams to be used to render the glyphs.

public Vector
getDisplacement(int
character code
code
)

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getDisplacement.

Returns the displacement vector (w0, w1) in text space, for the given character.

public PDRectangle

Returns:

The fonts bounding box.
getFontBBox
()

This will get the fonts bounding box from its dictionary.

public FontBoxFont
getFontBoxFont()

Implements abstract org.apache.pdfbox.pdmodel.font.PDSimpleFont.getFontBoxFont.

Returns the embedded or system font used for rendering.

public Matrix
getFontMatrix()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.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 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 GeneralPath
getPath(String
glyph name
name
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDSimpleFont.getPath.

Returns the path for the character with the given name.

public PDResources

Returns:

the resources bound to be used when parsing the type3 stream
getResources
()

Returns the optional resources of the type3 stream.

public float
getWidth(int
character code
code
)

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getWidth.

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

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

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(String
glyph name
name
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDSimpleFont.hasGlyph.

Returns true if the font contains the character with the given name.

public boolean
isDamaged()

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

Returns true if the embedded font file is damaged.

public boolean

Returns:

true because type 3 fonts are embedded by design.
isEmbedded
()

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

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

protected Boolean
isFontSymbolic()

Overrides org.apache.pdfbox.pdmodel.font.PDSimpleFont.isFontSymbolic.

Internal implementation of isSymbolic, allowing for the fact that the result may be indeterminate.

public boolean
isStandard14()

Overrides org.apache.pdfbox.pdmodel.font.PDSimpleFont.isStandard14.

Returns true if this font is one of the "Standard 14" fonts and receives special handling.

public int
readCode(InputStream
string stream
in
)

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.readCode.

Reads a character code from a content stream string.

protected final void
readEncoding()

Overrides org.apache.pdfbox.pdmodel.font.PDSimpleFont.readEncoding.

Reads the Encoding from the Font dictionary or the embedded or substituted font file.

protected Encoding
readEncodingFromFont()

Implements abstract org.apache.pdfbox.pdmodel.font.PDSimpleFont.readEncodingFromFont.

Called by readEncoding() if the encoding needs to be extracted from the font file.

Inherited from org.apache.pdfbox.pdmodel.font.PDSimpleFont:
addToSubsetgetEncodinggetGlyphListgetStandard14WidthgetSymbolicFlaghasExplicitWidthisNonZeroBoundingBoxisSymbolicisVerticalsubsettoUnicodetoUnicodewillBeSubset

Field Detail

charProcsback to summary
private COSDictionary charProcs
fontBBoxback to summary
private BoundingBox fontBBox
fontMatrixback to summary
private Matrix fontMatrix
LOGback to summary
private static final Log LOG

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

Log instance.

resourceCacheback to summary
private final ResourceCache resourceCache
resourcesback to summary
private PDResources resources

Constructor Detail

PDType3Fontback to summary
public PDType3Font(COSDictionary fontDictionary) throws IOException

Constructor.

Parameters
fontDictionary:COSDictionary

The font dictionary according to the PDF specification.

Exceptions
IOException:
if the font could not be created
PDType3Fontback to summary
public PDType3Font(COSDictionary fontDictionary, ResourceCache resourceCache) throws IOException

Constructor.

Parameters
fontDictionary:COSDictionary

The font dictionary according to the PDF specification.

resourceCache:ResourceCache

Resource cache, can be null.

Exceptions
IOException:
if the font could not be created

Method Detail

checkFontMatrixValuesback to summary
private boolean checkFontMatrixValues(COSArray matrix)
encodeback to summary
protected byte[] encode(int unicode) throws IOException

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

Doc from org.apache.pdfbox.pdmodel.font.PDFont.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
Exceptions
IOException:
If the text could not be encoded.
generateBoundingBoxback to summary
private BoundingBox generateBoundingBox()
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
getCharProcback to summary
public PDType3CharProc getCharProc(int code)

Returns the stream of the glyph for the given character code

Parameters
code:int

character code

Returns:PDType3CharProc

the stream to be used to render the glyph

getCharProcsback to summary
public COSDictionary getCharProcs()

Returns the dictionary containing all streams to be used to render the glyphs.

Returns:COSDictionary

the dictionary containing all glyph streams.

getDisplacementback to summary
public Vector getDisplacement(int code) throws IOException

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getDisplacement.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.getDisplacement.

Returns the displacement vector (w0, w1) in text space, for the given character. For horizontal text only the x component is used, for vertical text only the y component.

Parameters
code:int

character code

Returns:Vector

displacement vector

Annotations
@Override
Exceptions
IOException:
if the data could not be read
getFontBBoxback to summary
public PDRectangle getFontBBox()

This will get the fonts bounding box from its dictionary.

Returns:PDRectangle

The fonts bounding box.

getFontBoxFontback to summary
public FontBoxFont getFontBoxFont()

Implements abstract org.apache.pdfbox.pdmodel.font.PDSimpleFont.getFontBoxFont.

Doc from org.apache.pdfbox.pdmodel.font.PDSimpleFont.getFontBoxFont.

Returns the embedded or system font used for rendering. This is never null.

Returns:FontBoxFont

the embedded or system font used for rendering

Annotations
@Override
getFontMatrixback to summary
public Matrix getFontMatrix()

Overrides org.apache.pdfbox.pdmodel.font.PDFont.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
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
getPathback to summary
public GeneralPath getPath(String name) throws IOException

Implements abstract org.apache.pdfbox.pdmodel.font.PDSimpleFont.getPath.

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

Returns the path for the character with the given name. For some fonts, GIDs may be used instead of names when calling this method. *

Parameters
name:String

glyph name

Returns:GeneralPath

glyph path of the character with the given name

Annotations
@Override
Exceptions
IOException:
if the path could not be read
getResourcesback to summary
public PDResources getResources()

Returns the optional resources of the type3 stream.

Returns:PDResources

the resources bound to be used when parsing the type3 stream

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

Overrides org.apache.pdfbox.pdmodel.font.PDFont.getWidth.

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
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(String name) throws IOException

Implements abstract org.apache.pdfbox.pdmodel.font.PDSimpleFont.hasGlyph.

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

Returns true if the font contains the character with the given name.

Parameters
name:String

glyph name

Returns:boolean

true if the font contains the character with the given name

Annotations
@Override
Exceptions
IOException:
if the path 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 because type 3 fonts are embedded by design.

Annotations
@Override
isFontSymbolicback to summary
protected Boolean isFontSymbolic()

Overrides org.apache.pdfbox.pdmodel.font.PDSimpleFont.isFontSymbolic.

Doc from org.apache.pdfbox.pdmodel.font.PDSimpleFont.isFontSymbolic.

Internal implementation of isSymbolic, allowing for the fact that the result may be indeterminate.

Returns:Boolean

true if isSymbolic

Annotations
@Override
isStandard14back to summary
public boolean isStandard14()

Overrides org.apache.pdfbox.pdmodel.font.PDSimpleFont.isStandard14.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.isStandard14.

Returns true if this font is one of the "Standard 14" fonts and receives special handling.

Returns:boolean

true if this font is one of the "Standard 14" fonts

Annotations
@Override
readCodeback to summary
public int readCode(InputStream in) throws IOException

Implements abstract org.apache.pdfbox.pdmodel.font.PDFont.readCode.

Doc from org.apache.pdfbox.pdmodel.font.PDFont.readCode.

Reads a character code from a content stream string. Codes may be up to 4 bytes long.

Parameters
in:InputStream

string stream

Returns:int

character code

Annotations
@Override
Exceptions
IOException:
if the CMap or stream cannot be read
readEncodingback to summary
protected final void readEncoding() throws IOException

Overrides org.apache.pdfbox.pdmodel.font.PDSimpleFont.readEncoding.

Doc from org.apache.pdfbox.pdmodel.font.PDSimpleFont.readEncoding.

Reads the Encoding from the Font dictionary or the embedded or substituted font file. Must be called at the end of any subclass constructors.

Annotations
@Override
Exceptions
IOException:
if the font file could not be read
readEncodingFromFontback to summary
protected Encoding readEncodingFromFont() throws IOException

Implements abstract org.apache.pdfbox.pdmodel.font.PDSimpleFont.readEncodingFromFont.

Doc from org.apache.pdfbox.pdmodel.font.PDSimpleFont.readEncodingFromFont.

Called by readEncoding() if the encoding needs to be extracted from the font file.

Returns:Encoding

encoding of the font

Annotations
@Override
Exceptions
IOException:
if the font file could not be read.