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
A representation, with parser, of an Adobe Type 1 font.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
PostScript reader (not a parser, as the name would seem to indicate). -
Field Summary
FieldsModifier and TypeFieldDescription(package private) AffineTransform
(package private) int
(package private) String[]
(package private) int
(package private) int
(package private) int
the current position in the postscript stack(package private) float[]
the stack of postscript commands (used by callothersubr)(package private) int
the current position in the Type1 stack(package private) float[]
the Type1 stack of command values(package private) byte[][]
-
Constructor Summary
ConstructorsConstructorDescriptionType1Font
(String baseName, PDFObject src, PDFFontDescriptor descriptor) create a new Type1Font based on a font data stream and an encoding. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
buildAccentChar
(float x, float y, char a, char b, 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 int
findSlashName
(byte[] d, String name) get the index into the byte array of a slashed name, like "/name".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 namefloat
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 boolean
isASCII
(byte[] data, int start) Determine if data is in ASCII or binary format.private void
parse
(byte[] cs, GeneralPath gp, FlPoint pt, FlPoint wid) parse glyph data into a GeneralPath, and return the advance width.protected void
parseFont
(byte[] font, int start, int len) Read a font from it's data, start position and lengthprivate GeneralPath
parseGlyph
(byte[] cs, FlPoint advance, AffineTransform at) Decrypt a glyph stored in byte formprivate float
pop()
pop the next item off the stackprivate byte[][]
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 datareadChars
(byte[] d) get the character definitions of the font.private String[]
readEncoding
(byte[] d) parse the encoding portion of the font definitionprivate byte[][]
readSubrs
(byte[] d) read the subroutines out of the font definitionMethods 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 Details
-
chr2name
String[] chr2name -
password
int password -
subrs
byte[][] subrs -
lenIV
int lenIV -
name2outline
-
name2width
-
at
-
stack
float[] stackthe Type1 stack of command values -
sloc
int slocthe current position in the Type1 stack -
psStack
float[] psStackthe stack of postscript commands (used by callothersubr) -
psLoc
int psLocthe current position in the postscript stack -
callcount
int callcount
-
-
Constructor Details
-
Type1Font
create 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:
IOException
-
-
Method Details
-
parseFont
protected void parseFont(byte[] font, int start, int len) Read a font from it's data, start position and length -
readEncoding
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
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
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
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
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
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
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:
getWidth
in classOutlineFont
-
parseGlyph
Decrypt a glyph stored in byte form -
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
-