phelps.awt.font

Class NFontType1

public class NFontType1 extends NFontSimple implements Cloneable

Adobe PostScript Type 1 font formats (PFA, PFB, "PDF", CFF, and CID). Also, already created Multiple Master instances are in "PDF" format.

Features:

Implementation notes:

Version: $Revision: 1.71 $ $Date: 2004/01/14 04:55:36 $

See Also: "Adobe Type 1 Font Format"

Field Summary
static StringFORMAT
Type 1 format (non Compact).
static StringFORMAT_CFF
Compact Font Format aka Type 2 aka Type 1C.
static StringSUBFORMAT_CFF_CID
CID-keyed CFF.
static StringSUBFORMAT_DECRYPTED
Decrypted and no segments and no trialing 512 "0"s.
static StringSUBFORMAT_PDF
Encrypted and no segments, as found in PDF files.
static StringSUBFORMAT_PFA
Encrypted portion as ASCII hex character pairs.
static StringSUBFORMAT_PFB
Encrypted and segmented.
Constructor Summary
NFontType1(byte[] data, Map<Object,Object> afm)
Creates instance of Type 1 font given data, automatically determining subformat (PFA, PFB, PDF, CFF, or CID).
Method Summary
booleancanDisplayEchar(char ech)
NFontType1deriveFont(float pointsize)
NFontType1deriveFont(Encoding encoding, CMap toUnicode)
NFontType1deriveFont(boolean[] keep)
Creates font with subset of characters.
voiddrawEstring(Graphics2D g, String estr, float x, float y, int mode)
voiddrawString(Graphics2D g, String estr, float x, float y)
doubleecharWidth(char ech)
intgetCharstringType()
static intgetClen(byte[] data)
StringgetCopyright()
StringgetFamily()
intgetFlags()
StringgetFormat()
StringgetName()
intgetNumGlyphs()
intgetPaintType()
chargetSpaceChar()
StringgetSubformat()
intgetWeight()
static voidmain(String[] argv)
static byte[]normalize(byte[] data)
Normalizes Type 1 (not CFF) data by removing PFB/PFA wrapping, decrypting, and removing trailing 512 00s, if any.
static byte[]toPDF(byte[] data)
Converts normalized data into format used in PDF (encrypted, no segments).
byte[]toPDF()
Exports instantiated font, probably subsetted, in PDF format (encrypted, no segments).
static byte[]toPFA(byte[] data)
Converts normalized data into PFB format This consists of appending 512 00s, encrypting, and writing the encrypted portion as ASCII hex digits.
static byte[]toPFB(byte[] data)
Converts normalized data into PFB format This consists of appending 512 00s, encrypting, and wrapping in PFB.

Field Detail

FORMAT

public static final String FORMAT
Type 1 format (non Compact).

FORMAT_CFF

public static final String FORMAT_CFF
Compact Font Format aka Type 2 aka Type 1C.

SUBFORMAT_CFF_CID

public static final String SUBFORMAT_CFF_CID
CID-keyed CFF.

SUBFORMAT_DECRYPTED

public static final String SUBFORMAT_DECRYPTED
Decrypted and no segments and no trialing 512 "0"s.

SUBFORMAT_PDF

public static final String SUBFORMAT_PDF
Encrypted and no segments, as found in PDF files.

SUBFORMAT_PFA

public static final String SUBFORMAT_PFA
Encrypted portion as ASCII hex character pairs.

SUBFORMAT_PFB

public static final String SUBFORMAT_PFB
Encrypted and segmented.

Constructor Detail

NFontType1

public NFontType1(byte[] data, Map<Object,Object> afm)
Creates instance of Type 1 font given data, automatically determining subformat (PFA, PFB, PDF, CFF, or CID).

Note: Data from non-byte[] sources can be easily converted, from a java.io.File with Files or from a java.io.InputStream with InputStreams. data may be mutated.

Method Detail

canDisplayEchar

public boolean canDisplayEchar(char ech)

deriveFont

public NFontType1 deriveFont(float pointsize)

deriveFont

public NFontType1 deriveFont(Encoding encoding, CMap toUnicode)

deriveFont

public NFontType1 deriveFont(boolean[] keep)
Creates font with subset of characters. Can save a little memory, but quite useful when embedding fonts in PDF to reduce size (save the new font data with NFontType1 or NFontType1). Multiple character positions can map to the same glyph; many TeX fonts use this to have a mapping for the original position and if that position is in 0..32 that can't be rendered by other rasterizers, again at higher position. If keep is null, subset consists of all characters defined in current encoding. After subsetting, this fact is indicated by prefixing font name with six random capital letters and a plus sign.

Parameters: keep is a vector of flags such that keep[char_num]==true iff that character is a member of the subset.

drawEstring

public void drawEstring(Graphics2D g, String estr, float x, float y, int mode)

drawString

public void drawString(Graphics2D g, String estr, float x, float y)

echarWidth

public double echarWidth(char ech)

getCharstringType

public int getCharstringType()

getClen

public static int getClen(byte[] data)

getCopyright

public String getCopyright()

getFamily

public String getFamily()

getFlags

public int getFlags()

getFormat

public String getFormat()

getName

public String getName()

getNumGlyphs

public int getNumGlyphs()

getPaintType

public int getPaintType()

getSpaceChar

public char getSpaceChar()

getSubformat

public String getSubformat()

getWeight

public int getWeight()

main

public static void main(String[] argv)

normalize

public static byte[] normalize(byte[] data)
Normalizes Type 1 (not CFF) data by removing PFB/PFA wrapping, decrypting, and removing trailing 512 00s, if any. If the length the clear text portion (clen) is unknown, pass -1 and it will be computed.

toPDF

public static byte[] toPDF(byte[] data)
Converts normalized data into format used in PDF (encrypted, no segments).

toPDF

public byte[] toPDF()
Exports instantiated font, probably subsetted, in PDF format (encrypted, no segments).

toPFA

public static byte[] toPFA(byte[] data)
Converts normalized data into PFB format This consists of appending 512 00s, encrypting, and writing the encrypted portion as ASCII hex digits. (Does not translate from CFF.)

toPFB

public static byte[] toPFB(byte[] data)
Converts normalized data into PFB format This consists of appending 512 00s, encrypting, and wrapping in PFB. (Does not translate from CFF.)