Package com.sun.pdfview.font
Class Type1Font
- java.lang.Object
-
- com.sun.pdfview.font.PDFFont
-
- com.sun.pdfview.font.OutlineFont
-
- com.sun.pdfview.font.Type1Font
-
- Direct Known Subclasses:
BuiltinFont
public class Type1Font extends OutlineFont
A representation, with parser, of an Adobe Type 1 font.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classType1Font.PSParserPostScript reader (not a parser, as the name would seem to indicate).
-
Field Summary
Fields Modifier and Type Field Description (package private) java.awt.geom.AffineTransformat(package private) intcallcount(package private) java.lang.String[]chr2name(package private) intlenIV(package private) java.util.Map<java.lang.String,java.lang.Object>name2outline(package private) java.util.Map<java.lang.String,FlPoint>name2width(package private) intpassword(package private) intpsLocthe current position in the postscript stack(package private) float[]psStackthe stack of postscript commands (used by callothersubr)(package private) intslocthe current position in the Type1 stack(package private) float[]stackthe Type1 stack of command values(package private) byte[][]subrs
-
Constructor Summary
Constructors Constructor Description Type1Font(java.lang.String baseName, PDFObject src, PDFFontDescriptor descriptor)create a new Type1Font based on a font data stream and an encoding.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidbuildAccentChar(float x, float y, char a, char b, java.awt.geom.GeneralPath gp)build an accented character out of two pre-defined glyphs.private byte[]decrypt(byte[] d, int start, int end, int key, int skip)decrypt an array using the Adobe Type 1 Font decryption algorithm.private intfindSlashName(byte[] d, java.lang.String name)get the index into the byte array of a slashed name, like "/name".protected java.awt.geom.GeneralPathgetOutline(char src, float width)Get a glyph outline by character code Note this method must always return an outlineprotected java.awt.geom.GeneralPathgetOutline(java.lang.String name, float width)Get a glyph outline by namefloatgetWidth(char code, java.lang.String name)Get the width of a given character This method is overridden to work if the width array hasn't been populated (as for one of the 14 base fonts)private booleanisASCII(byte[] data, int start)Determine if data is in ASCII or binary format.private voidparse(byte[] cs, java.awt.geom.GeneralPath gp, FlPoint pt, FlPoint wid)parse glyph data into a GeneralPath, and return the advance width.protected voidparseFont(byte[] font, int start, int len)Read a font from it's data, start position and lengthprivate java.awt.geom.GeneralPathparseGlyph(byte[] cs, FlPoint advance, java.awt.geom.AffineTransform at)Decrypt a glyph stored in byte formprivate floatpop()pop the next item off the stackprivate byte[][]readArray(byte[] d, java.lang.String key, java.lang.String end)read a named array out of the font definition.private byte[]readASCII(byte[] data, int start, int end)Read data formatted as ASCII strings as binary dataprivate java.util.HashMap<java.lang.String,byte[]>readChars(byte[] d)get the character definitions of the font.private java.lang.String[]readEncoding(byte[] d)parse the encoding portion of the font definitionprivate byte[][]readSubrs(byte[] d)read the subroutines out of the font definition-
Methods inherited from class com.sun.pdfview.font.OutlineFont
getCharCount, getDefaultWidth, getFirstChar, getGlyph, getLastChar
-
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
-
chr2name
java.lang.String[] chr2name
-
password
int password
-
subrs
byte[][] subrs
-
lenIV
int lenIV
-
name2outline
java.util.Map<java.lang.String,java.lang.Object> name2outline
-
name2width
java.util.Map<java.lang.String,FlPoint> name2width
-
at
java.awt.geom.AffineTransform at
-
stack
float[] stack
the Type1 stack of command values
-
sloc
int sloc
the current position in the Type1 stack
-
psStack
float[] psStack
the stack of postscript commands (used by callothersubr)
-
psLoc
int psLoc
the current position in the postscript stack
-
callcount
int callcount
-
-
Constructor Detail
-
Type1Font
public Type1Font(java.lang.String baseName, PDFObject src, PDFFontDescriptor descriptor) throws java.io.IOExceptioncreate a new Type1Font based on a font data stream and an encoding.- Parameters:
baseName- the postscript name of this fontsrc- the Font object as a stream with a dictionarydescriptor- the descriptor for this font- Throws:
java.io.IOException
-
-
Method Detail
-
parseFont
protected void parseFont(byte[] font, int start, int len)Read a font from it's data, start position and length
-
readEncoding
private java.lang.String[] readEncoding(byte[] d)
parse the encoding portion of the font definition- Parameters:
d- the font definition stream- Returns:
- an array of the glyphs corresponding to each byte
-
readSubrs
private byte[][] readSubrs(byte[] d)
read the subroutines out of the font definition- Parameters:
d- the font definition stream- Returns:
- an array of the subroutines, each as a byte array.
-
readArray
private byte[][] readArray(byte[] d, java.lang.String key, java.lang.String end)read a named array out of the font definition.this function attempts to parse an array out of a postscript definition without doing any postscript. It's actually looking for things that look like "dup id elt put", and placing the elt at the ith position in the array.
- Parameters:
d- the font definition streamkey- the name of the arrayend- a string that appears at the end of the array- Returns:
- an array consisting of a byte array for each entry
-
decrypt
private byte[] decrypt(byte[] d, int start, int end, int key, int skip)decrypt an array using the Adobe Type 1 Font decryption algorithm.- Parameters:
d- the input array of bytesstart- where in the array to start decodingend- where in the array to stop decodingkey- the decryption keyskip- how many bytes to skip initially- Returns:
- the decrypted bytes. The length of this array will be (start-end-skip) bytes long
-
readASCII
private byte[] readASCII(byte[] data, int start, int end)Read data formatted as ASCII strings as binary data- Parameters:
data- the data, formatted as ASCII stringsstart- where in the array to start decryptingend- where in the array to stop decrypting
-
isASCII
private boolean isASCII(byte[] data, int start)Determine if data is in ASCII or binary format. According to the spec, if any of the first 4 bytes are not character codes ('0' - '9' or 'A' - 'F' or 'a' - 'f'), then the data is binary. Otherwise it is ASCII
-
findSlashName
private int findSlashName(byte[] d, java.lang.String name)get the index into the byte array of a slashed name, like "/name".- Parameters:
d- the search arrayname- the name to look for, without the initial /- Returns:
- the index of the first occurance of /name in the array.
-
readChars
private java.util.HashMap<java.lang.String,byte[]> readChars(byte[] d)
get the character definitions of the font.- Parameters:
d- the font data- Returns:
- a HashMap that maps string glyph names to byte arrays of decoded font data.
-
pop
private float pop()
pop the next item off the stack
-
parse
private void parse(byte[] cs, java.awt.geom.GeneralPath gp, FlPoint pt, FlPoint wid)parse glyph data into a GeneralPath, and return the advance width. The working point is passed in as a parameter in order to allow recursion.- Parameters:
cs- the decrypted glyph datagp- a GeneralPath into which the glyph shape will be storedpt- a FlPoint object that will be used to generate the pathwid- a FlPoint into which the advance width will be placed.
-
buildAccentChar
private void buildAccentChar(float x, float y, char a, char b, java.awt.geom.GeneralPath gp)build an accented character out of two pre-defined glyphs.- Parameters:
x- the x offset of the accenty- the y offset of the accenta- the index of the accent glyphb- the index of the base glyphgp- the GeneralPath into which the combined glyph will be written.
-
getWidth
public float getWidth(char code, java.lang.String name)Get the width of a given character This method is overridden to work if the width array hasn't been populated (as for one of the 14 base fonts)- Overrides:
getWidthin classOutlineFont
-
parseGlyph
private java.awt.geom.GeneralPath parseGlyph(byte[] cs, FlPoint advance, java.awt.geom.AffineTransform at)Decrypt a glyph stored in byte form
-
getOutline
protected java.awt.geom.GeneralPath getOutline(java.lang.String name, float width)Get a glyph outline by name- Specified by:
getOutlinein 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:
getOutlinein classOutlineFont- Parameters:
src- the character code of the desired glyph- Returns:
- the glyph outline
-
-