|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.pdfbox.pdmodel.font.PDFont
public abstract class PDFont
This is the base class for all PDF fonts.
Field Summary | |
---|---|
protected 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 Map<String,CMap> |
cmapObjects
|
protected COSDictionary |
font
The cos dictionary for this font. |
protected PDMatrix |
fontMatrix
The font matrix. |
protected static String |
resourceRootCMAP
|
protected CMap |
toUnicodeCmap
The CMap holding the ToUnicode mapping |
Constructor Summary | |
---|---|
PDFont()
Constructor. |
|
PDFont(COSDictionary fontDictionary)
Constructor. |
Method Summary | |
---|---|
static void |
clearResources()
This will clear AFM resources that are stored statically. |
protected String |
cmapEncoding(int code,
int length,
boolean isCIDFont,
CMap sourceCmap)
Encode the given value using the CMap of the font. |
protected abstract void |
determineEncoding()
Determines the encoding for the font. |
void |
drawString(String string,
Graphics g,
float fontSize,
AffineTransform at,
float x,
float y)
Deprecated. use drawString(String, int[], Graphics, float, AffineTransform, float, float) instead |
abstract void |
drawString(String string,
int[] codePoints,
Graphics g,
float fontSize,
AffineTransform at,
float x,
float y)
This will draw a string on a canvas using the font. |
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(Object other)
|
protected 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. |
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 width 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. |
float |
getStringWidth(String string)
This will get the width of this string for this font. |
String |
getSubType()
This will get the subtype of font, Type1, Type3, ... |
String |
getType()
This will always return "Font" for fonts. |
List<Float> |
getWidths()
The widths of the characters. |
int |
hashCode()
|
protected boolean |
hasToUnicode()
Determines if a font as a ToUnicode entry. |
protected boolean |
isType0Font()
Determines if the font is a type 0 font. |
protected boolean |
isType1Font()
Determines if the font is a type 1 font. |
protected CMap |
parseCmap(String cmapRoot,
InputStream cmapStream)
|
void |
setBaseFont(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(List<Float> widthsList)
Set the widths of the characters code. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected COSDictionary font
protected PDMatrix fontMatrix
protected CMap cmap
protected CMap toUnicodeCmap
protected static Map<String,CMap> cmapObjects
protected static final String resourceRootCMAP
Constructor Detail |
---|
public PDFont()
public PDFont(COSDictionary fontDictionary)
fontDictionary
- The font dictionary according to the PDF specification.Method Detail |
---|
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 IOException
c
- The character code to get the width for.offset
- The offset into the array.length
- The length of the data.
IOException
- If an error occurs while parsing.public abstract float getFontHeight(byte[] c, int offset, int length) throws IOException
c
- The character code to get the width for.offset
- The offset into the array.length
- The length of the data.
IOException
- If an error occurs while parsing.public float getStringWidth(String string) throws IOException
string
- The string to get the width of.
IOException
- If there is an error getting the width information.public abstract float getAverageFontWidth() throws IOException
IOException
- If an error occurs while parsing.public void drawString(String string, Graphics g, float fontSize, AffineTransform at, float x, float y) throws IOException
drawString(String, int[], Graphics, float, AffineTransform, float, float)
instead
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.
IOException
- If there is an error drawing the specific string.public abstract void drawString(String string, int[] codePoints, Graphics g, float fontSize, AffineTransform at, float x, float y) throws 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.
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 IOException
code
- The character code we are trying to get.
IOException
- if we cannot find the width.protected float getAverageFontWidthFromAFMFile() throws IOException
IOException
- if we cannot find the width.protected 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)
encoding
- the given encoding.protected String cmapEncoding(int code, int length, boolean isCIDFont, CMap sourceCmap) throws IOException
code
- the code to encode.length
- the byte length of the given code.isCIDFont
- indicates that the used font is a CID font.
IOException
- if something went wrongpublic String encode(byte[] c, int offset, int length) throws IOException
c
- The character to encode.offset
- The offset into the array to get the datalength
- The number of bytes to read.
IOException
- If there is an error during the encoding.public int encodeToCID(byte[] c, int offset, int length) throws IOException
IOException
protected CMap parseCmap(String cmapRoot, InputStream cmapStream)
public void setFontEncoding(Encoding enc)
enc
- The font encoding.public Encoding getFontEncoding()
public String getType()
public String getSubType()
protected boolean isType1Font()
protected boolean isType0Font()
public String getBaseFont()
public void setBaseFont(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 List<Float> getWidths()
public void setWidths(List<Float> widthsList)
widths
- The widths of the character codes.public PDMatrix getFontMatrix()
public abstract PDRectangle getFontBoundingBox() throws IOException
IOException
- If there is an error getting the bounding box.public boolean equals(Object other)
equals
in class Object
public int hashCode()
hashCode
in class Object
public float getFontWidth(int charCode)
charCode
- the code of the given character
protected boolean hasToUnicode()
protected void setHasToUnicode(boolean hasToUnicodeValue)
hasToUnicode
- the given value for hasToUnicode
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |