java.lang.Object
org.sejda.sambox.pdmodel.font.PDFont
- All Implemented Interfaces:
COSObjectable,PDFontLike,Subsettable
- Direct Known Subclasses:
PDSimpleFont,PDType0Font
This is the base class for all PDF fonts.
- Author:
- Ben Litchfield
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract byte[]encode(int unicode) Encodes the given Unicode code point for use in a PDF content stream.final byte[]Encodes the given string for use in a PDF content stream.final byte[]encodeLeniently(String text) Similar to encode() but handles leniently cases where fonts don't have a glyph by assuming the identity mappingbooleanfloatThis will get the average font width for all characters.getDisplacement(int code) Returns the displacement vector (w0, w1) in text space, for the given character.Returns the font descriptor, may be null.Returns the font matrix, which represents the transformation from glyph space to text space.getPositionVector(int code) Returns the position vector (v), in text space, for the given character.floatDetermines the width of the space character.protected final org.apache.fontbox.afm.FontMetricsReturns the AFM if this is a Standard 14 font.protected abstract floatgetStandard14Width(int code) Returns the glyph width from the AFM if this is a Standard 14 font.floatgetStringWidth(String text) Returns the width of the given Unicode string.floatSimilar to getStringWidth() but handles leniently fonts where glyphs are missing, assuming the identity mapping of glyphsThis will get the subtype of font.protected org.apache.fontbox.cmap.CMapgetType()This will always return "Font" for fonts.floatgetWidth(int code) Returns the advance width of the given character, in glyph space.The widths of the characters.inthashCode()booleanReturns true if this font is one of the "Standard 14" fonts and receives special handling.abstract booleanReturns true if the font uses vertical writing mode.protected final org.apache.fontbox.cmap.CMap/** Reads a CMap given a COS Stream or Name.abstract intreadCode(InputStream in) Reads a character code from a content stream string.protected final voidsetFontDescriptor(PDFontDescriptor fontDescriptor) Sets the font descriptor when embedding a font.toString()toUnicode(int code) Returns the Unicode character sequence which corresponds to the given character code.Returns the Unicode character sequence which corresponds to the given character code.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.sejda.sambox.pdmodel.font.PDFontLike
getBoundingBox, getHeight, getName, getWidthFromFont, hasExplicitWidth, isDamaged, isEmbedded, isMappingFallbackUsed, isOriginalEmbeddedMissingMethods inherited from interface org.sejda.sambox.pdmodel.font.Subsettable
addToSubset, subset, willBeSubset
-
Field Details
-
DEFAULT_FONT_MATRIX
-
dict
-
-
Constructor Details
-
PDFont
Constructor.- Parameters:
fontDictionary- Font dictionary.- Throws:
IOException
-
-
Method Details
-
getStandard14AFM
protected final org.apache.fontbox.afm.FontMetrics getStandard14AFM()Returns the AFM if this is a Standard 14 font. -
getFontDescriptor
Description copied from interface:PDFontLikeReturns the font descriptor, may be null.- Specified by:
getFontDescriptorin interfacePDFontLike
-
setFontDescriptor
Sets the font descriptor when embedding a font. -
readCMap
/** Reads a CMap given a COS Stream or Name. May return null if a predefined CMap does not exist.- Parameters:
base- COSName or COSStream- Throws:
IOException
-
getCOSObject
- Specified by:
getCOSObjectin interfaceCOSObjectable- Returns:
- The
COSBasethat matches this Java object.
-
getPositionVector
Description copied from interface:PDFontLikeReturns 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.- Specified by:
getPositionVectorin interfacePDFontLike- Parameters:
code- character code- Returns:
- position vector
-
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- character code- Returns:
- displacement vector
- Throws:
IOException
-
getWidth
Description copied from interface:PDFontLikeReturns 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.- Specified by:
getWidthin interfacePDFontLike- Parameters:
code- character code- Throws:
IOException
-
getStandard14Width
protected abstract float getStandard14Width(int code) Returns the glyph width from the AFM if this is a Standard 14 font.- Parameters:
code- character code- Returns:
- width in 1/1000 text space
-
encode
Encodes the given string for use in a PDF content stream.- Parameters:
text- Any Unicode text.- Returns:
- Array of PDF content stream bytes.
- Throws:
IOException- If the text could not be encoded.
-
encodeLeniently
Similar to encode() but handles leniently cases where fonts don't have a glyph by assuming the identity mapping- Throws:
IOException
-
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- Unicode code point.- Returns:
- Array of 1 to 4 PDF content stream bytes.
- Throws:
IOException- If the text could not be encoded.
-
getStringWidth
Returns the width of the given Unicode string.- Parameters:
text- The text to get the width of.- Returns:
- The width of the string in 1/1000 units of text space.
- Throws:
IOException- If there is an error getting the width information.
-
getStringWidthLeniently
Similar to getStringWidth() but handles leniently fonts where glyphs are missing, assuming the identity mapping of glyphsUses encodeLeniently() instead of encode()
- Throws:
IOException
-
getAverageFontWidth
public float getAverageFontWidth()This will get the average font width for all characters.- Specified by:
getAverageFontWidthin interfacePDFontLike- Returns:
- The width is in 1000 unit of text space, ie 333 or 777
-
readCode
Reads a character code from a content stream string. Codes may be up to 4 bytes long.- Parameters:
in- string stream- Returns:
- character code
- Throws:
IOException- if the CMap or stream cannot be read
-
toUnicode
Returns the Unicode character sequence which corresponds to the given character code.- Parameters:
code- character codecustomGlyphList- a custom glyph list to use instead of the Adobe Glyph List- Returns:
- Unicode character(s)
- Throws:
IOException
-
toUnicode
Returns the Unicode character sequence which corresponds to the given character code.- Parameters:
code- character code- Returns:
- Unicode character(s)
- Throws:
IOException
-
getType
This will always return "Font" for fonts.- Returns:
- The type of object that this is.
-
getSubType
This will get the subtype of font. -
getWidths
The widths of the characters. This will be null for the standard 14 fonts.- Returns:
- The widths of the characters.
-
getFontMatrix
Description copied from interface:PDFontLikeReturns the font matrix, which represents the transformation from glyph space to text space.- Specified by:
getFontMatrixin interfacePDFontLike
-
getSpaceWidth
public float getSpaceWidth()Determines the width of the space character.- Returns:
- the width of the space character
-
isVertical
public abstract boolean isVertical()Returns true if the font uses vertical writing mode. -
isStandard14
public boolean isStandard14()Returns true if this font is one of the "Standard 14" fonts and receives special handling. -
equals
-
hashCode
public int hashCode() -
toString
-
getToUnicodeCMap
protected org.apache.fontbox.cmap.CMap getToUnicodeCMap() -
getTransientMetadata
-