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

public Class PDType1CFont

extends PDSimpleFont
implements PDVectorFont
Class Inheritance
All Implemented Interfaces
org.apache.pdfbox.pdmodel.font.PDVectorFont
Imports
java.awt.geom.AffineTransform, .GeneralPath, .Point2D, java.io.IOException, .InputStream, java.util.HashMap, .List, .Map, org.apache.commons.logging.Log, .LogFactory, org.apache.fontbox.EncodedFont, .FontBoxFont, org.apache.fontbox.cff.CFFFont, .CFFParser, .CFFType1Font, org.apache.fontbox.util.BoundingBox, org.apache.pdfbox.cos.COSDictionary, .COSName, org.apache.pdfbox.io.RandomAccessRead, org.apache.pdfbox.pdmodel.common.PDRectangle, .PDStream, org.apache.pdfbox.pdmodel.font.encoding.Encoding, .StandardEncoding, .Type1Encoding, org.apache.pdfbox.util.Matrix

Type 1-equivalent CFF font.
Authors
Villu Ruusmann, John Hewson

Field Summary

Modifier and TypeField and Description
private Float
private final CFFType1Font
private BoundingBox
private Matrix
private final AffineTransform
private final FontBoxFont
private final Map<String, Float>
private final boolean
private final boolean
private static final Log
Inherited from org.apache.pdfbox.pdmodel.font.PDSimpleFont:
encodingglyphList

Constructor Summary

AccessConstructor and Description
public
PDType1CFont(COSDictionary
the corresponding dictionary
fontDictionary
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public String
codeToName(int code)

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
private float
public float
public final String

Returns:

the PostScript name of the font
getBaseFont
()

Returns the PostScript name of the font.

public BoundingBox
getBoundingBox()

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

Returns the font's bounding box.

public CFFType1Font

Returns:

the cffFont
getCFFType1Font
()

Returns the embedded Type 1-equivalent CFF font.

public FontBoxFont
getFontBoxFont()

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

Returns the embedded or system font used for rendering.

public final 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 final 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".

private String
getNameInFont(String name)

Maps a PostScript glyph name to the name in the underlying font, for example when using a TTF font we might map "W" to "uni0057".

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

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

Returns the path for the character with the given name.

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 float
getStringWidth(String
The text to get the width of.
string
)

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

Returns the width of the given Unicode string.

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
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
isEmbedded()

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

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

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

Field Detail

avgWidthback to summary
private Float avgWidth
cffFontback to summary
private final CFFType1Font cffFont
fontBBoxback to summary
private BoundingBox fontBBox
fontMatrixback to summary
private Matrix fontMatrix
fontMatrixTransformback to summary
private final AffineTransform fontMatrixTransform
genericFontback to summary
private final FontBoxFont genericFont
glyphHeightsback to summary
private final Map<String, 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.PDSimpleFont.LOG.

Constructor Detail

PDType1CFontback to summary
public PDType1CFont(COSDictionary fontDictionary) throws IOException

Constructor.

Parameters
fontDictionary:COSDictionary

the corresponding dictionary

Exceptions
IOException:
it something went wrong

Method Detail

codeToNameback to summary
public String codeToName(int code)
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() throws IOException
getAverageCharacterWidthback to summary
private float getAverageCharacterWidth()
getAverageFontWidthback to summary
public float getAverageFontWidth()

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

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

Doc from org.apache.pdfbox.pdmodel.font.PDFont.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 final String getBaseFont()

Returns the PostScript name of the font.

Returns:String

the PostScript name of the font

getBoundingBoxback to summary
public BoundingBox getBoundingBox() throws IOException

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
Exceptions
IOException:
if the bounding box could not be read
getCFFType1Fontback to summary
public CFFType1Font getCFFType1Font()

Returns the embedded Type 1-equivalent CFF font.

Returns:CFFType1Font

the cffFont

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 final 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 final 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
getNameInFontback to summary
private String getNameInFont(String name) throws IOException

Maps a PostScript glyph name to the name in the underlying font, for example when using a TTF font we might map "W" to "uni0057".

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(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
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
getStringWidthback to summary
public float getStringWidth(String string) throws IOException

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

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

Returns the width of the given Unicode string.

Parameters
string:String

The text to get the width of.

Returns:float

The width of the string in 1/1000 units of text space.

Annotations
@Override
Exceptions
IOException:
If there is an error getting the width information.
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
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 if the font file is embedded in the PDF

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