Package org.apache.pdfbox.pdmodel.font
Class PDSimpleFont
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.font.PDFont
-
- org.apache.pdfbox.pdmodel.font.PDSimpleFont
-
- All Implemented Interfaces:
COSObjectable
- Direct Known Subclasses:
PDCIDFont,PDTrueTypeFont,PDType0Font,PDType1CFont,PDType1Font,PDType3Font
public abstract class PDSimpleFont extends PDFont
This class contains implementation details of the simple pdf fonts.- Version:
- $Revision: 1.18 $
- Author:
- Ben Litchfield
-
-
Field Summary
-
Fields inherited from class org.apache.pdfbox.pdmodel.font.PDFont
cmap, cmapObjects, font, fontMatrix, resourceRootCMAP, toUnicodeCmap
-
-
Constructor Summary
Constructors Constructor Description PDSimpleFont()Constructor.PDSimpleFont(COSDictionary fontDictionary)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddetermineEncoding()Determines the encoding for the font.voiddrawString(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.floatgetAverageFontWidth()This will get the average font width for all characters.java.awt.FontgetawtFont()Looks up, creates, returns the AWT Font.PDRectanglegetFontBoundingBox()This will get the fonts bounding box.floatgetFontHeight(byte[] c, int offset, int length)This will get the font height for a character.floatgetFontWidth(byte[] c, int offset, int length)This will get the font width for a character.floatgetSpaceWidth()Determines the width of the space character.COSBasegetToUnicode()This will get the ToUnicode object.protected booleanisFontSubstituted()This will get the value for isFontSubstituted, which indicates if the font was substituted due to a problem with the embedded one.protected voidsetIsFontSubstituted(boolean isSubstituted)This will set the value for isFontSubstituted.voidsetToUnicode(COSBase unicode)This will set the ToUnicode object.protected voidwriteFont(java.awt.Graphics2D g2d, java.awt.geom.AffineTransform at, float x, float y, java.awt.font.GlyphVector glyphs)This will draw a string on a canvas using the font.-
Methods inherited from class org.apache.pdfbox.pdmodel.font.PDFont
clear, clearResources, cmapEncoding, drawString, encode, encodeToCID, equals, getAFM, getAverageFontWidthFromAFMFile, getBaseFont, getCodeFromArray, getCOSObject, getEncoding, getFirstChar, getFontDescriptor, getFontEncoding, getFontMatrix, getFontWidth, getFontWidthFromAFMFile, getLastChar, getStringFromArray, getStringWidth, getSubType, getToUnicodeCMap, getType, getWidths, hashCode, hasToUnicode, isSymbolicFont, isType0Font, isType1Font, isType3Font, parseCmap, setBaseFont, setEncoding, setFirstChar, setFontDescriptor, setFontEncoding, setHasToUnicode, setLastChar, setWidths
-
-
-
-
Constructor Detail
-
PDSimpleFont
public PDSimpleFont()
Constructor.
-
PDSimpleFont
public PDSimpleFont(COSDictionary fontDictionary)
Constructor.- Parameters:
fontDictionary- The font dictionary according to the PDF specification.
-
-
Method Detail
-
getawtFont
public java.awt.Font getawtFont() throws java.io.IOExceptionLooks up, creates, returns the AWT Font.- Returns:
- returns the awt font to bes used for rendering
- Throws:
java.io.IOException- if something went wrong.
-
drawString
public 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.IOExceptionThis will draw a string on a canvas using the font.- Specified by:
drawStringin classPDFont- Parameters:
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.- Throws:
java.io.IOException- If there is an error drawing the specific string.
-
getFontHeight
public float getFontHeight(byte[] c, int offset, int length) throws java.io.IOExceptionThis will get the font height for a character.- Specified by:
getFontHeightin classPDFont- Parameters:
c- The character code to get the width for.offset- The offset into the array.length- The length of the data.- Returns:
- The width is in 1000 unit of text space, ie 333 or 777
- Throws:
java.io.IOException- If an error occurs while parsing.
-
getFontWidth
public float getFontWidth(byte[] c, int offset, int length) throws java.io.IOExceptionThis will get the font width for a character.- Specified by:
getFontWidthin classPDFont- Parameters:
c- The character code to get the width for.offset- The offset into the array.length- The length of the data.- Returns:
- The width is in 1000 unit of text space, ie 333 or 777
- Throws:
java.io.IOException- If an error occurs while parsing.
-
getAverageFontWidth
public float getAverageFontWidth() throws java.io.IOExceptionThis will get the average font width for all characters.- Specified by:
getAverageFontWidthin classPDFont- Returns:
- The width is in 1000 unit of text space, ie 333 or 777
- Throws:
java.io.IOException- If an error occurs while parsing.
-
getToUnicode
public COSBase getToUnicode()
This will get the ToUnicode object.- Returns:
- The ToUnicode object.
-
setToUnicode
public void setToUnicode(COSBase unicode)
This will set the ToUnicode object.- Parameters:
unicode- The unicode object.
-
getFontBoundingBox
public PDRectangle getFontBoundingBox() throws java.io.IOException
This will get the fonts bounding box.- Specified by:
getFontBoundingBoxin classPDFont- Returns:
- The fonts bouding box.
- Throws:
java.io.IOException- If there is an error getting the bounding box.
-
writeFont
protected void writeFont(java.awt.Graphics2D g2d, java.awt.geom.AffineTransform at, float x, float y, java.awt.font.GlyphVector glyphs)This will draw a string on a canvas using the font.- Parameters:
g2d- The graphics to draw onto.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.glyphs- The GlyphVector containing the glyphs to be drawn.
-
determineEncoding
protected void determineEncoding()
Determines the encoding for the font. This method as to be overwritten, as there are different possibilities to define a mapping.- Specified by:
determineEncodingin classPDFont
-
isFontSubstituted
protected boolean isFontSubstituted()
This will get the value for isFontSubstituted, which indicates if the font was substituted due to a problem with the embedded one.- Returns:
- true if the font was substituted
-
setIsFontSubstituted
protected void setIsFontSubstituted(boolean isSubstituted)
This will set the value for isFontSubstituted.- Parameters:
isSubstituted- true if the font was substituted
-
getSpaceWidth
public float getSpaceWidth()
Determines the width of the space character.- Specified by:
getSpaceWidthin classPDFont- Returns:
- the width of the space character
-
-