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
a font object derived from a true type font.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate FontRenderContext
the font render contextprivate CmapTable
the cmap table from a TrueType fontprotected static final char[]
Control characters to filter out of the underlying fontprivate Font
the actual font in useprivate HmtxTable
the hmtx table from the TrueType fontprotected static final short[]
the ids of our favorite CMapsprivate PostTable
the post table from a TrueType fontprivate int
the number of font units in one em -
Constructor Summary
ConstructorsConstructorDescriptionNativeFont
(String baseFont, PDFObject fontObj, PDFFontDescriptor descriptor) create a new NativeFont object based on a description of the font from the PDF file. -
Method Summary
Modifier and TypeMethodDescriptionprivate 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 GeneralPath
getOutline
(char src, float width) Get a glyph outline by character code Note this method must always return an outlineprotected GeneralPath
getOutline
(String name, float width) Get a glyph outline by nameprotected void
setFont
(byte[] fontdata) Set the fontprotected void
Set the fontMethods 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 Details
-
controlChars
protected static final char[] controlCharsControl characters to filter out of the underlying font -
mapIDs
protected static final short[] mapIDsthe ids of our favorite CMaps -
f
the actual font in use -
basecontext
the font render context -
cmapTable
the cmap table from a TrueType font -
postTable
the post table from a TrueType font -
unitsPerEm
private int unitsPerEmthe number of font units in one em -
hmtxTable
the hmtx table from the TrueType font
-
-
Constructor Details
-
NativeFont
public NativeFont(String baseFont, PDFObject fontObj, PDFFontDescriptor descriptor) throws 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:
IOException
-
-
Method Details
-
getOutline
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
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
Set the font- Parameters:
f
- the font to use
-
setFont
Set the font- Parameters:
fontdata
- the font data as a byte array- Throws:
FontFormatException
IOException
-
fixNameTable
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
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
-