public class PDType0Font extends PDFont implements PDVectorFont
DEFAULT_FONT_MATRIX, dict
Constructor and Description |
---|
PDType0Font(COSDictionary fontDictionary)
Constructor for reading a Type0 font from a PDF file.
|
Modifier and Type | Method and Description |
---|---|
void |
addToSubset(int codePoint)
Adds the given Unicode point to the subset.
|
int |
codeToCID(int code)
Returns the CID for the given character code.
|
int |
codeToGID(int code)
Returns the GID for the given character code.
|
protected byte[] |
encode(int unicode)
Encodes the given Unicode code point for use in a PDF content stream.
|
float |
getAverageFontWidth()
This will get the average font width for all characters.
|
String |
getBaseFont()
Returns the PostScript name of the font.
|
BoundingBox |
getBoundingBox()
Returns the font's bounding box.
|
CMap |
getCMap()
Returns the font's CMap.
|
CMap |
getCMapUCS2()
Returns the font's UCS2 CMap, only present this font uses a predefined CMap.
|
PDCIDFont |
getDescendantFont()
Returns the descendant font.
|
Vector |
getDisplacement(int code)
Returns the displacement vector (w0, w1) in text space, for the given character.
|
PDFontDescriptor |
getFontDescriptor()
Returns the font descriptor, may be null.
|
Matrix |
getFontMatrix()
Returns the font matrix, which represents the transformation from glyph space to text space.
|
float |
getHeight(int code)
Returns the height of the given character, in glyph space.
|
String |
getName()
Returns the name of this font, either the PostScript "BaseName" or the Type 3 "Name".
|
GeneralPath |
getPath(int code)
Returns the glyph path for the given character code.
|
Vector |
getPositionVector(int code)
Returns the position vector (v), in text space, for the given character.
|
protected float |
getStandard14Width(int code)
Returns the glyph width from the AFM if this is a Standard 14 font.
|
float |
getWidth(int code)
Returns the advance width of the given character, in glyph space.
|
float |
getWidthFromFont(int code)
Returns the width of a glyph in the embedded font file.
|
boolean |
hasExplicitWidth(int code)
Returns true if the Font dictionary specifies an explicit width for the given glyph.
|
boolean |
hasGlyph(int code)
Returns true if this font contains a glyph for the given character code.
|
boolean |
isDamaged()
Returns true if the embedded font file is damaged.
|
boolean |
isEmbedded()
Returns true if the font file is embedded in the PDF.
|
boolean |
isStandard14()
Returns true if this font is one of the "Standard 14" fonts and receives special handling.
|
boolean |
isVertical()
Returns true if the font uses vertical writing mode.
|
static PDType0Font |
load(PDDocument doc,
File file)
Loads a TTF to be embedded into a document as a Type 0 font.
|
static PDType0Font |
load(PDDocument doc,
InputStream input)
Loads a TTF to be embedded into a document as a Type 0 font.
|
static PDType0Font |
load(PDDocument doc,
InputStream input,
boolean embedSubset)
Loads a TTF to be embedded into a document as a Type 0 font.
|
static PDType0Font |
load(PDDocument doc,
TrueTypeFont ttf,
boolean embedSubset)
Loads a TTF to be embedded into a document as a Type 0 font.
|
static PDType0Font |
loadVertical(PDDocument doc,
File file)
Loads a TTF to be embedded into a document as a vertical Type 0 font.
|
static PDType0Font |
loadVertical(PDDocument doc,
InputStream input)
Loads a TTF to be embedded into a document as a vertical Type 0 font.
|
static PDType0Font |
loadVertical(PDDocument doc,
InputStream input,
boolean embedSubset)
Loads a TTF to be embedded into a document as a vertical Type 0 font.
|
static PDType0Font |
loadVertical(PDDocument doc,
TrueTypeFont ttf,
boolean embedSubset)
Loads a TTF to be embedded into a document as a vertical Type 0 font.
|
int |
readCode(InputStream in)
Reads a character code from a content stream string.
|
void |
subset()
Replaces this font with a subset containing only the given Unicode characters.
|
String |
toString() |
String |
toUnicode(int code)
Returns the Unicode character sequence which corresponds to the given character code.
|
boolean |
willBeSubset()
Returns true if this font will be subset when embedded.
|
encode, equals, getCOSObject, getSpaceWidth, getStandard14AFM, getStringWidth, getSubType, getType, getWidths, hashCode, readCMap, setFontDescriptor, toUnicode
public PDType0Font(COSDictionary fontDictionary) throws IOException
fontDictionary
- The font dictionary according to the PDF specification.IOException
- if the descendant font is missing.public static PDType0Font load(PDDocument doc, File file) throws IOException
doc
- The PDF document that will hold the embedded font.file
- A TrueType font.IOException
- If there is an error reading the font file.public static PDType0Font load(PDDocument doc, InputStream input) throws IOException
doc
- The PDF document that will hold the embedded font.input
- A TrueType font.IOException
- If there is an error reading the font stream.public static PDType0Font load(PDDocument doc, InputStream input, boolean embedSubset) throws IOException
doc
- The PDF document that will hold the embedded font.input
- A TrueType font.embedSubset
- True if the font will be subset before embeddingIOException
- If there is an error reading the font stream.public static PDType0Font load(PDDocument doc, TrueTypeFont ttf, boolean embedSubset) throws IOException
doc
- The PDF document that will hold the embedded font.ttf
- A TrueType font.embedSubset
- True if the font will be subset before embeddingIOException
- If there is an error reading the font stream.public static PDType0Font loadVertical(PDDocument doc, File file) throws IOException
doc
- The PDF document that will hold the embedded font.file
- A TrueType font.IOException
- If there is an error reading the font file.public static PDType0Font loadVertical(PDDocument doc, InputStream input) throws IOException
doc
- The PDF document that will hold the embedded font.input
- A TrueType font.IOException
- If there is an error reading the font stream.public static PDType0Font loadVertical(PDDocument doc, InputStream input, boolean embedSubset) throws IOException
doc
- The PDF document that will hold the embedded font.input
- A TrueType font.embedSubset
- True if the font will be subset before embeddingIOException
- If there is an error reading the font stream.public static PDType0Font loadVertical(PDDocument doc, TrueTypeFont ttf, boolean embedSubset) throws IOException
doc
- The PDF document that will hold the embedded font.ttf
- A TrueType font.embedSubset
- True if the font will be subset before embeddingIOException
- If there is an error reading the font stream.public void addToSubset(int codePoint)
PDFont
addToSubset
in class PDFont
codePoint
- Unicode code pointpublic void subset() throws IOException
PDFont
subset
in class PDFont
IOException
- if the subset could not be writtenpublic boolean willBeSubset()
PDFont
willBeSubset
in class PDFont
public String getBaseFont()
public PDCIDFont getDescendantFont()
public CMap getCMap()
public CMap getCMapUCS2()
public PDFontDescriptor getFontDescriptor()
PDFontLike
getFontDescriptor
in interface PDFontLike
getFontDescriptor
in class PDFont
public Matrix getFontMatrix()
PDFontLike
getFontMatrix
in interface PDFontLike
getFontMatrix
in class PDFont
public boolean isVertical()
PDFont
isVertical
in class PDFont
public float getHeight(int code) throws IOException
PDFontLike
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.
getHeight
in interface PDFontLike
getHeight
in class PDFont
code
- character codeIOException
protected byte[] encode(int unicode) throws IOException
PDFont
This method is called when embedding text in PDFs and when filling in fields.
encode
in class PDFont
unicode
- Unicode code point.IOException
- If the text could not be encoded.public boolean hasExplicitWidth(int code) throws IOException
PDFontLike
hasExplicitWidth
in interface PDFontLike
code
- character codeIOException
- if the font could not be readpublic float getAverageFontWidth()
PDFont
getAverageFontWidth
in interface PDFontLike
getAverageFontWidth
in class PDFont
public Vector getPositionVector(int code)
PDFontLike
getPositionVector
in interface PDFontLike
getPositionVector
in class PDFont
code
- character codepublic Vector getDisplacement(int code) throws IOException
PDFont
getDisplacement
in class PDFont
code
- character codeIOException
public float getWidth(int code) throws IOException
PDFontLike
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.
getWidth
in interface PDFontLike
getWidth
in class PDFont
code
- character codeIOException
protected float getStandard14Width(int code)
PDFont
getStandard14Width
in class PDFont
code
- character codepublic float getWidthFromFont(int code) throws IOException
PDFontLike
getWidthFromFont
in interface PDFontLike
getWidthFromFont
in class PDFont
code
- character codeIOException
- if the font could not be readpublic boolean isEmbedded()
PDFontLike
isEmbedded
in interface PDFontLike
isEmbedded
in class PDFont
public String toUnicode(int code) throws IOException
PDFont
toUnicode
in class PDFont
code
- character codeIOException
public String getName()
PDFontLike
getName
in interface PDFontLike
getName
in class PDFont
public BoundingBox getBoundingBox() throws IOException
PDFontLike
getBoundingBox
in interface PDFontLike
getBoundingBox
in class PDFont
IOException
public int readCode(InputStream in) throws IOException
PDFont
readCode
in class PDFont
in
- string streamIOException
- if the CMap or stream cannot be readpublic int codeToCID(int code)
code
- character codepublic int codeToGID(int code) throws IOException
code
- character codeIOException
public boolean isStandard14()
PDFont
isStandard14
in class PDFont
public boolean isDamaged()
PDFontLike
isDamaged
in interface PDFontLike
isDamaged
in class PDFont
public GeneralPath getPath(int code) throws IOException
PDVectorFont
getPath
in interface PDVectorFont
code
- character code in a PDF. Not to be confused with unicode.IOException
- if the font could not be readpublic boolean hasGlyph(int code) throws IOException
PDVectorFont
hasGlyph
in interface PDVectorFont
code
- character code in a PDF. Not to be confused with unicode.IOException
Copyright © 2002–2018 The Apache Software Foundation. All rights reserved.