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 |
addGlyphsToSubset(Set<Integer> glyphIds) |
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.
|
byte[] |
encodeGlyphId(int glyphId)
Returns the encoded value for the given glyph ID.
|
float |
getAverageFontWidth()
This will get the average font width for all characters.
|
String |
getBaseFont()
Returns the PostScript name of the font.
|
org.apache.fontbox.util.BoundingBox |
getBoundingBox()
Returns the font's bounding box.
|
org.apache.fontbox.cmap.CMap |
getCMap()
Returns the font's CMap.
|
org.apache.fontbox.ttf.CmapLookup |
getCmapLookup()
Returns the CMap lookup table if present.
|
org.apache.fontbox.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.
|
org.apache.fontbox.ttf.model.GsubData |
getGsubData()
Returns the GSubData if present.
|
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 |
getNormalizedPath(int code)
Returns the normalized glyph path for the given character code in a PDF.
|
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 in a PDF.
|
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 and subset into a document as a Type 0 font.
|
static PDType0Font |
load(PDDocument doc,
InputStream input)
Loads a TTF to be embedded and subset 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,
org.apache.pdfbox.io.RandomAccessRead randomAccessRead,
boolean embedSubset,
boolean vertical)
Loads a TTF to be embedded into a document as a Type 0 font.
|
static PDType0Font |
load(PDDocument doc,
org.apache.fontbox.ttf.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,
org.apache.fontbox.ttf.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, getToUnicodeCMap, getType, getWidths, hashCode, readCMap, setFontDescriptor, toUnicodepublic 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 - An input stream of a TrueType font. It will be closed before returning.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 - An input stream of a TrueType font. It will be closed before returning.embedSubset - True if the font will be subset before embedding. Set this to false when
creating a font for AcroForm.IOException - If there is an error reading the font stream.public static PDType0Font load(PDDocument doc, org.apache.pdfbox.io.RandomAccessRead randomAccessRead, boolean embedSubset, boolean vertical) throws IOException
doc - The PDF document that will hold the embedded font.randomAccessRead - source of a TrueType font.embedSubset - True if the font will be subset before embedding. Set this to false when creating a font for
AcroForm.vertical - whether to enable vertical substitutions.IOException - If there is an error reading the font stream.public static PDType0Font load(PDDocument doc, org.apache.fontbox.ttf.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 embedding. Set this to false when creating a font for
AcroForm.IOException - 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, org.apache.fontbox.ttf.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)
PDFontaddToSubset in class PDFontcodePoint - Unicode code pointpublic void subset()
throws IOException
PDFontsubset in class PDFontIOException - if the subset could not be writtenpublic boolean willBeSubset()
PDFontwillBeSubset in class PDFontpublic String getBaseFont()
public PDCIDFont getDescendantFont()
public org.apache.fontbox.cmap.CMap getCMap()
public org.apache.fontbox.cmap.CMap getCMapUCS2()
public PDFontDescriptor getFontDescriptor()
PDFontLikegetFontDescriptor in interface PDFontLikegetFontDescriptor in class PDFontpublic Matrix getFontMatrix()
PDFontLikegetFontMatrix in interface PDFontLikegetFontMatrix in class PDFontpublic boolean isVertical()
PDFontisVertical in class PDFontpublic 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. See the cyan rectangles in the
DrawPrintTextLocations.java example to see this in action.
getHeight in interface PDFontLikecode - character codeIOException - if the height could not be readprotected byte[] encode(int unicode)
throws IOException
PDFontThis method is called when embedding text in PDFs and when filling in fields.
encode in class PDFontunicode - Unicode code point.IOException - If the text could not be encoded.public boolean hasExplicitWidth(int code)
throws IOException
PDFontLikehasExplicitWidth in interface PDFontLikecode - character codeIOException - if the font could not be readpublic float getAverageFontWidth()
PDFontgetAverageFontWidth in interface PDFontLikegetAverageFontWidth in class PDFontpublic Vector getPositionVector(int code)
PDFontLikegetPositionVector in interface PDFontLikegetPositionVector in class PDFontcode - character codepublic Vector getDisplacement(int code) throws IOException
PDFontgetDisplacement in class PDFontcode - character codeIOException - if the data could not be readpublic float getWidth(int code)
throws IOException
PDFontLikeIf 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.
getWidth in interface PDFontLikegetWidth in class PDFontcode - character codeIOException - if the width could not be readprotected float getStandard14Width(int code)
PDFontgetStandard14Width in class PDFontcode - character codepublic float getWidthFromFont(int code)
throws IOException
PDFontLikegetWidthFromFont in interface PDFontLikecode - character codeIOException - if the font could not be readpublic boolean isEmbedded()
PDFontLikeisEmbedded in interface PDFontLikepublic String toUnicode(int code)
PDFontpublic String getName()
PDFontLikegetName in interface PDFontLikepublic org.apache.fontbox.util.BoundingBox getBoundingBox()
throws IOException
PDFontLikegetBoundingBox in interface PDFontLikeIOException - if the bounding box could not be readpublic int readCode(InputStream in) throws IOException
PDFontreadCode in class PDFontin - 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 - if the data could not be readpublic boolean isStandard14()
PDFontisStandard14 in class PDFontpublic boolean isDamaged()
PDFontLikeisDamaged in interface PDFontLikepublic GeneralPath getPath(int code) throws IOException
PDVectorFontgetPath in interface PDVectorFontcode - character code in a PDF. Not to be confused with unicode.IOException - if the font could not be readpublic GeneralPath getNormalizedPath(int code) throws IOException
PDVectorFontgetNormalizedPath in interface PDVectorFontcode - 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
PDVectorFonthasGlyph in interface PDVectorFontcode - character code in a PDF. Not to be confused with unicode.IOException - if the font could not be readpublic org.apache.fontbox.ttf.model.GsubData getGsubData()
public byte[] encodeGlyphId(int glyphId)
glyphId - the ID of the glyph to be encodedpublic org.apache.fontbox.ttf.CmapLookup getCmapLookup()
Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.