Package com.sun.pdfview.font
Class NativeFont
- java.lang.Object
-
- com.sun.pdfview.font.PDFFont
-
- com.sun.pdfview.font.OutlineFont
-
- com.sun.pdfview.font.NativeFont
-
public class NativeFont extends OutlineFont
a font object derived from a true type font.
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.font.FontRenderContext
basecontext
the font render contextprivate CmapTable
cmapTable
the cmap table from a TrueType fontprotected static char[]
controlChars
Control characters to filter out of the underlying fontprivate java.awt.Font
f
the actual font in useprivate HmtxTable
hmtxTable
the hmtx table from the TrueType fontprotected static short[]
mapIDs
the ids of our favorite CMapsprivate PostTable
postTable
the post table from a TrueType fontprivate int
unitsPerEm
the number of font units in one em
-
Constructor Summary
Constructors Constructor Description NativeFont(java.lang.String baseFont, PDFObject fontObj, PDFFontDescriptor descriptor)
create a new NativeFont object based on a description of the font from the PDF file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
fixCMapTable(TrueTypeFont ttf, CmapTable cmap)
Fix the CMap table.private boolean
fixNameTable(TrueTypeFont ttf, NameTable name)
Fix a broken font name table for a TrueType font.protected java.awt.geom.GeneralPath
getOutline(char src, float width)
Get a glyph outline by character code Note this method must always return an outlineprotected java.awt.geom.GeneralPath
getOutline(java.lang.String name, float width)
Get a glyph outline by nameprotected void
setFont(byte[] fontdata)
Set the fontprotected void
setFont(java.awt.Font f)
Set the font-
Methods inherited from class com.sun.pdfview.font.OutlineFont
getCharCount, getDefaultWidth, getFirstChar, getGlyph, getLastChar, getWidth
-
Methods inherited from class com.sun.pdfview.font.PDFFont
equals, getBaseFont, getCachedGlyph, getDescriptor, getEncoding, getFont, getGlyphs, getSubtype, getUnicodeMap, hashCode, setBaseFont, setDescriptor, setEncoding, setSubtype, setUnicodeMap, toString
-
-
-
-
Field Detail
-
controlChars
protected static final char[] controlChars
Control characters to filter out of the underlying font
-
mapIDs
protected static final short[] mapIDs
the ids of our favorite CMaps
-
f
private java.awt.Font f
the actual font in use
-
basecontext
private java.awt.font.FontRenderContext basecontext
the font render context
-
cmapTable
private CmapTable cmapTable
the cmap table from a TrueType font
-
postTable
private PostTable postTable
the post table from a TrueType font
-
unitsPerEm
private int unitsPerEm
the number of font units in one em
-
hmtxTable
private HmtxTable hmtxTable
the hmtx table from the TrueType font
-
-
Constructor Detail
-
NativeFont
public NativeFont(java.lang.String baseFont, PDFObject fontObj, PDFFontDescriptor descriptor) throws java.io.IOException
create a new NativeFont object based on a description of the font from the PDF file. If the description happens to contain an in-line true-type font file (under key "FontFile2"), use the true type font. Otherwise, parse the description for key information and use that to generate an appropriate font.- Throws:
java.io.IOException
-
-
Method Detail
-
getOutline
protected java.awt.geom.GeneralPath getOutline(java.lang.String name, float width)
Get a glyph outline by name- Specified by:
getOutline
in classOutlineFont
- Parameters:
name
- the name of the desired glyph- Returns:
- the glyph outline, or null if unavailable
-
getOutline
protected java.awt.geom.GeneralPath getOutline(char src, float width)
Get a glyph outline by character code Note this method must always return an outline- Specified by:
getOutline
in classOutlineFont
- Parameters:
src
- the character code of the desired glyph- Returns:
- the glyph outline
-
setFont
protected void setFont(java.awt.Font f)
Set the font- Parameters:
f
- the font to use
-
setFont
protected void setFont(byte[] fontdata) throws java.awt.FontFormatException, java.io.IOException
Set the font- Parameters:
fontdata
- the font data as a byte array- Throws:
java.awt.FontFormatException
java.io.IOException
-
fixNameTable
private boolean fixNameTable(TrueTypeFont ttf, NameTable name)
Fix a broken font name table for a TrueType font. Some fonts do not have Microsoft-specific name information, but Java won't work without it (grrr.). This method takes a font and adds the Microsoft data into it.- Parameters:
ttf
- the fontname
- the font's name table- Returns:
- true if the table was fixed, or false if it was left as is
-
fixCMapTable
private boolean fixCMapTable(TrueTypeFont ttf, CmapTable cmap)
Fix the CMap table. This can be necessary if characters are mapped to control characters (0x9, 0xa, 0xd) Java will not render them, even though they are valid. Also, Java tends to not like it when there is only a Format 0 CMap, which happens frequently when included Format 4 CMaps are broken. Since PDF prefers the Format 0 map, while Java prefers the Format 4 map, it is generally necessary to re-write the Format 0 map as a Format 4 map to make most PDFs work.- Parameters:
ttf
- the fontcmap
- the CMap table- Returns:
- true if the font was changed, or false if it was left as-is
-
-