COSObjectable
PDSimpleFont
public abstract class PDFont extends java.lang.Object implements COSObjectable
Modifier and Type | Field | Description |
---|---|---|
protected org.apache.fontbox.cmap.CMap |
cmap |
This is only used if this is a font object and it has an encoding and it is
a type0 font with a cmap.
|
protected static java.util.Map<java.lang.String,org.apache.fontbox.cmap.CMap> |
cmapObjects |
|
protected COSDictionary |
font |
The cos dictionary for this font.
|
protected PDMatrix |
fontMatrix |
The font matrix.
|
protected static java.lang.String |
resourceRootCMAP |
|
protected org.apache.fontbox.cmap.CMap |
toUnicodeCmap |
The CMap holding the ToUnicode mapping.
|
Constructor | Description |
---|---|
PDFont() |
Constructor.
|
PDFont(COSDictionary fontDictionary) |
Constructor.
|
Modifier and Type | Method | Description |
---|---|---|
void |
clear() |
Calling this will release all cached information.
|
static void |
clearResources() |
This will clear AFM resources that are stored statically.
|
protected java.lang.String |
cmapEncoding(int code,
int length,
boolean isCIDFont,
org.apache.fontbox.cmap.CMap sourceCmap) |
Encode the given value using the CMap of the font.
|
protected abstract void |
determineEncoding() |
Determines the encoding for the font.
|
abstract void |
drawString(java.lang.String string,
int[] codePoints,
java.awt.Graphics g,
float fontSize,
java.awt.geom.AffineTransform at,
float x,
float y) |
This will draw a string on a canvas using the font.
|
void |
drawString(java.lang.String string,
java.awt.Graphics g,
float fontSize,
java.awt.geom.AffineTransform at,
float x,
float y) |
Deprecated.
|
java.lang.String |
encode(byte[] c,
int offset,
int length) |
This will perform the encoding of a character if needed.
|
int |
encodeToCID(byte[] c,
int offset,
int length) |
|
boolean |
equals(java.lang.Object other) |
|
protected org.apache.fontbox.afm.FontMetric |
getAFM() |
This will get an AFM object if one exists.
|
abstract float |
getAverageFontWidth() |
This will get the average font width for all characters.
|
protected float |
getAverageFontWidthFromAFMFile() |
This will attempt to get the average font width from an AFM file.
|
java.lang.String |
getBaseFont() |
The PostScript name of the font.
|
int |
getCodeFromArray(byte[] data,
int offset,
int length) |
Used for multibyte encodings.
|
COSBase |
getCOSObject() |
Convert this standard java object to a COS object.
|
protected COSBase |
getEncoding() |
cache the
COSName.ENCODING object from
the font's dictionary since it is called so often. |
int |
getFirstChar() |
The code for the first char or -1 if there is none.
|
abstract PDRectangle |
getFontBoundingBox() |
This will get the fonts bounding box.
|
PDFontDescriptor |
getFontDescriptor() |
This will get the font descriptor for this font.
|
Encoding |
getFontEncoding() |
This will get or create the encoder.
|
abstract float |
getFontHeight(byte[] c,
int offset,
int length) |
This will get the font height for a character.
|
PDMatrix |
getFontMatrix() |
This will get the matrix that is used to transform glyph space to
text space.
|
abstract float |
getFontWidth(byte[] c,
int offset,
int length) |
This will get the font width for a character.
|
float |
getFontWidth(int charCode) |
Determines the width of the given character.
|
protected float |
getFontWidthFromAFMFile(int code) |
This will attempt to get the font width from an AFM file.
|
int |
getLastChar() |
The code for the last char or -1 if there is none.
|
abstract float |
getSpaceWidth() |
Determines the width of the space character.
|
protected static java.lang.String |
getStringFromArray(byte[] c,
int offset,
int length) |
Map the given byte(s) to a string.
|
float |
getStringWidth(java.lang.String string) |
This will get the width of this string for this font.
|
java.lang.String |
getSubType() |
This will get the subtype of font, Type1, Type3, ...
|
org.apache.fontbox.cmap.CMap |
getToUnicodeCMap() |
Returns the toUnicode mapping if present.
|
java.lang.String |
getType() |
This will always return "Font" for fonts.
|
java.util.List<java.lang.Float> |
getWidths() |
The widths of the characters.
|
int |
hashCode() |
|
protected boolean |
hasToUnicode() |
Determines if a font as a ToUnicode entry.
|
boolean |
isSymbolicFont() |
Determines if the font is a symbolic font.
|
protected boolean |
isType0Font() |
Determines if the font is a type 0 font.
|
protected boolean |
isType1Font() |
Determines if the font is a type 1 font.
|
boolean |
isType3Font() |
Determines if the font is a type 3 font.
|
protected org.apache.fontbox.cmap.CMap |
parseCmap(java.lang.String cmapRoot,
java.io.InputStream cmapStream) |
|
void |
setBaseFont(java.lang.String baseFont) |
Set the PostScript name of the font.
|
protected void |
setEncoding(COSBase encodingValue) |
Set the encoding object from the fonts dictionary.
|
void |
setFirstChar(int firstChar) |
Set the first character this font supports.
|
void |
setFontDescriptor(PDFontDescriptorDictionary fdDictionary) |
This will set the font descriptor.
|
void |
setFontEncoding(Encoding enc) |
The will set the encoding for this font.
|
protected void |
setHasToUnicode(boolean hasToUnicodeValue) |
Sets hasToUnicode to the given value.
|
void |
setLastChar(int lastChar) |
Set the last character this font supports.
|
void |
setWidths(java.util.List<java.lang.Float> widthsList) |
Set the widths of the characters code.
|
protected COSDictionary font
protected PDMatrix fontMatrix
protected org.apache.fontbox.cmap.CMap cmap
protected org.apache.fontbox.cmap.CMap toUnicodeCmap
protected static java.util.Map<java.lang.String,org.apache.fontbox.cmap.CMap> cmapObjects
protected static final java.lang.String resourceRootCMAP
public PDFont()
public PDFont(COSDictionary fontDictionary)
fontDictionary
- The font dictionary according to the PDF specification.public static void clearResources()
public PDFontDescriptor getFontDescriptor()
public void setFontDescriptor(PDFontDescriptorDictionary fdDictionary)
fdDictionary
- The font descriptor.protected abstract void determineEncoding()
public COSBase getCOSObject()
getCOSObject
in interface COSObjectable
public abstract float getFontWidth(byte[] c, int offset, int length) throws java.io.IOException
c
- The character code to get the width for.offset
- The offset into the array.length
- The length of the data.java.io.IOException
- If an error occurs while parsing.public abstract float getFontHeight(byte[] c, int offset, int length) throws java.io.IOException
c
- The character code to get the height for.offset
- The offset into the array.length
- The length of the data.java.io.IOException
- If an error occurs while parsing.public float getStringWidth(java.lang.String string) throws java.io.IOException
string
- The string to get the width of.java.io.IOException
- If there is an error getting the width information.public abstract float getAverageFontWidth() throws java.io.IOException
java.io.IOException
- If an error occurs while parsing.public void drawString(java.lang.String string, java.awt.Graphics g, float fontSize, java.awt.geom.AffineTransform at, float x, float y) throws java.io.IOException
string
- The string to draw.g
- The graphics to draw onto.fontSize
- The size of the font to draw.at
- The transformation matrix with all information for scaling and shearing of the font.x
- The x coordinate to draw at.y
- The y coordinate to draw at.java.io.IOException
- If there is an error drawing the specific string.public abstract void drawString(java.lang.String string, int[] codePoints, java.awt.Graphics g, float fontSize, java.awt.geom.AffineTransform at, float x, float y) throws java.io.IOException
string
- The string to draw.codePoints
- The codePoints of the given string.g
- The graphics to draw onto.fontSize
- The size of the font to draw.at
- The transformation matrix with all information for scaling and shearing of the font.x
- The x coordinate to draw at.y
- The y coordinate to draw at.java.io.IOException
- If there is an error drawing the specific string.public int getCodeFromArray(byte[] data, int offset, int length)
data
- The array of data.offset
- The offset into the array.length
- The number of bytes to use.protected float getFontWidthFromAFMFile(int code) throws java.io.IOException
code
- The character code we are trying to get.java.io.IOException
- if we cannot find the width.protected float getAverageFontWidthFromAFMFile() throws java.io.IOException
java.io.IOException
- if we cannot find the width.protected org.apache.fontbox.afm.FontMetric getAFM()
protected COSBase getEncoding()
COSName.ENCODING
object from
the font's dictionary since it is called so often.
Use this method instead of
font.getDictionaryObject(COSName.ENCODING);
protected void setEncoding(COSBase encodingValue)
encodingValue
- the given encoding.protected java.lang.String cmapEncoding(int code, int length, boolean isCIDFont, org.apache.fontbox.cmap.CMap sourceCmap) throws java.io.IOException
code
- the code to encode.length
- the byte length of the given code.isCIDFont
- indicates that the used font is a CID font.java.io.IOException
- if something went wrongpublic java.lang.String encode(byte[] c, int offset, int length) throws java.io.IOException
c
- The character to encode.offset
- The offset into the array to get the datalength
- The number of bytes to read.java.io.IOException
- If there is an error during the encoding.public int encodeToCID(byte[] c, int offset, int length) throws java.io.IOException
java.io.IOException
protected static java.lang.String getStringFromArray(byte[] c, int offset, int length)
c
- the byte arrayoffset
- the offset of the byte(s)length
- the number of bytes, usually 1 or 2protected org.apache.fontbox.cmap.CMap parseCmap(java.lang.String cmapRoot, java.io.InputStream cmapStream)
public void setFontEncoding(Encoding enc)
enc
- The font encoding.public Encoding getFontEncoding()
public java.lang.String getType()
public java.lang.String getSubType()
protected boolean isType1Font()
public boolean isType3Font()
protected boolean isType0Font()
public boolean isSymbolicFont()
public java.lang.String getBaseFont()
public void setBaseFont(java.lang.String baseFont)
baseFont
- The postscript name for the font.public int getFirstChar()
public void setFirstChar(int firstChar)
firstChar
- The first character.public int getLastChar()
public void setLastChar(int lastChar)
lastChar
- The last character.public java.util.List<java.lang.Float> getWidths()
public void setWidths(java.util.List<java.lang.Float> widthsList)
widthsList
- The widths of the character codes.public PDMatrix getFontMatrix()
public abstract PDRectangle getFontBoundingBox() throws java.io.IOException
java.io.IOException
- If there is an error getting the bounding box.public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public float getFontWidth(int charCode)
charCode
- the code of the given characterprotected boolean hasToUnicode()
protected void setHasToUnicode(boolean hasToUnicodeValue)
hasToUnicodeValue
- the given value for hasToUnicodepublic abstract float getSpaceWidth()
public org.apache.fontbox.cmap.CMap getToUnicodeCMap()
public void clear()