}
/**
- * Sets the identity character map for this font. It maps all available Unicode characters
+ * Sets the character map for this font. It maps all available Unicode characters
* to their glyph indices inside the font.
- * @param cmap the identity character map
+ * @param cmap the character map
*/
public void setCMap(CMapSegment[] cmap) {
this.cmap = new CMapSegment[cmap.length];
}
/**
- * Returns the identity character map for this font. It maps all available Unicode characters
+ * Returns the character map for this font. It maps all available Unicode characters
* to their glyph indices inside the font.
- * @return the identity character map
+ * @return the character map
*/
public CMapSegment[] getCMap() {
CMapSegment[] copy = new CMapSegment[cmap.length];
}
/**
- * Sets the embedding mode for this font, currently not supported for type1 fonts.
+ * Sets the embedding mode for this font, currently not supported for Type 1 fonts.
* @param embeddingMode the new embedding mode.
*/
public void setEmbeddingMode(EmbeddingMode embeddingMode) {
/**
* This enumerates the embedding mode of fonts; full; subset; auto (auto defaults to full for
- * type1 fonts and subset for truetype fonts.
+ * Type 1 fonts and subset for TrueType fonts.
*/
public enum EmbeddingMode {
- /** Default option: assumes FULL for type1 fonts and SUBSET for truetype fonts. */
+ /** Default option: assumes FULL for Type 1 fonts and SUBSET for TrueType fonts. */
AUTO,
/** Full font embedding: This means the whole of the font is written to file. */
FULL,
/**
* Returns the name of this embedding mode.
- * @return String - lower case.
+ * @return the name of this embedding mode in lower case.
*/
public String getName() {
return this.toString().toLowerCase();
}
/**
- * Returns {@link EmbeddingMode} by name.
- * @param value String - the name of the embedding mode (not case sensitive).
- * @return embedding mode constant.
+ * Returns the embedding mode corresponding to the given name.
+ * @param value the name of an embedding mode (not case sensitive)
+ * @return the corresponding embedding mode
*/
public static EmbeddingMode getValue(String value) {
for (EmbeddingMode mode : EmbeddingMode.values()) {
return value;
}
- /** {@inheritDoc} */
+ @Override
public String toString() {
return name;
}
void setEmbedResourceName(String name);
/**
- * Set the embedding mode for this font.
- * @param embeddingMode the embedding mode.
+ * Sets the embedding mode.
+ * @param embeddingMode the embedding mode
*/
void setEmbeddingMode(EmbeddingMode embeddingMode);
"ccaron", "dcroat"
};
- /** The FontFileReader used to read this truetype font */
+ /** The FontFileReader used to read this TrueType font. */
protected FontFileReader fontFile;
+
/** Set to true to get even more debug output than with level DEBUG */
public static final boolean TRACE_ENABLED = false;
}
/**
- * Key-value helper class (immutable)
+ * Key-value helper class.
*/
final class UnicodeMapping implements Comparable {
/**
* Streams a font.
- * @param ttfOut The interface for streaming True Type tables.
+ * @param ttfOut The interface for streaming TrueType tables.
* @exception IOException file write error
*/
public void stream(TTFOutputStream ttfOut) throws IOException {
}
/**
- * This returns the order in which the tables in a truetype font should be written to file.
+ * Returns the order in which the tables in a TrueType font should be written to file.
* @param directoryTabs the map that is to be sorted.
* @return TTFTablesNames[] an array of table names sorted in the order they should appear in
* the TTF file.
import java.io.IOException;
/**
- * This is an interface for streaming individual glyphs from the glyf table in a True Type font.
+ * An interface for writing individual glyphs from the glyf table of a TrueType font to an output stream.
*/
public interface TTFGlyphOutputStream {
+
/**
* Begins the streaming of glyphs.
- * @throws IOException file write exception
*/
void startGlyphStream() throws IOException;
/**
- * Streams an individual glyph at offset from a byte array.
- * @param byteArray byte[] the font byte array.
- * @param offset int the starting position to stream from.
- * @param length int the number of bytes to stream.
- * @throws IOException file write exception.
+ * Streams an individual glyph from the given byte array.
+ *
+ * @param glyphData the source of the glyph data to stream from
+ * @param offset the position in the glyph data where the glyph starts
+ * @param size the size of the glyph data in bytes
*/
- void streamGlyph(byte[] byteArray, int offset, int length) throws IOException;
+ void streamGlyph(byte[] glyphData, int offset, int size) throws IOException;
/**
* Ends the streaming of glyphs.
- * @throws IOException file write exception.
*/
void endGlyphStream() throws IOException;
+
}
import java.io.IOException;
/**
- * This is an interface for streaming True Type font.
+ * An interface for writing a TrueType font to an output stream.
*/
public interface TTFOutputStream {
+
/**
- * Starts writing the font to file.
- * @throws IOException file write exception.
+ * Starts writing the font.
*/
void startFontStream() throws IOException;
/**
- * Returns an object for streaming True Type tables.
- * @return {@link TTFTableOutputStream}
+ * Returns an object for streaming TrueType tables.
*/
TTFTableOutputStream getTableOutputStream();
/**
- * Returns an object for streaming True Type glyphs in the glyf table.
- * @return {@link TTFGlyphOutputStream}
+ * Returns an object for streaming TrueType glyphs in the glyf table.
*/
TTFGlyphOutputStream getGlyphOutputStream();
/**
- * Ends writing the font to file.
- * @throws IOException file write exception.
+ * Ends writing the font.
*/
void endFontStream() throws IOException;
+
}
= new HashMap<TTFTableName, TTFDirTabEntry>();
private int determineTableCount() {
- int numTables = 4; //4 req'd tables: head,hhea,hmtx,maxp,
+ int numTables = 4; //4 req'd tables: head,hhea,hmtx,maxp
if (isCFF()) {
throw new UnsupportedOperationException(
"OpenType fonts with CFF glyphs are not supported");
writeUShort((numTables * 16) - searchRange);
realSize += 2;
- // Create space for the table entries (these must be in ASCII alphabetical order[A-Z]then[a-z])
+ // Create space for the table entries (these must be in ASCII alphabetical order[A-Z] then[a-z])
writeTableName(TTFTableName.OS2);
if (hasCvt()) {
/**
* Copy the name table as is from the original.
- * @param in FontFileReader
- * @return boolean
- * @throws IOException exception
*/
private boolean createName(FontFileReader in) throws IOException {
return copyTable(in, TTFTableName.NAME);
/**
* Copy the OS/2 table as is from the original.
- * @param in
- * @return
- * @throws IOException
*/
private boolean createOS2(FontFileReader in) throws IOException {
return copyTable(in, TTFTableName.OS2);
endOffset1 = (currentPos - startPos + glyphLength);
}
- // Store the glyph boundary positions relative to the start the font
+ // Store the glyph boundary positions relative to the start of the font
glyphOffsets[i] = currentPos;
currentPos += glyphLength;
realSize += glyphLength;
/**
- * This class holds the True Type Format table names as in the Directory Table of a TTF font file.
- * This class must also support custom tables found in fonts (thus an enum wasn't used).
+ * Represents table names as found in a TrueType font's Table Directory.
+ * TrueType fonts may have custom tables so we cannot use an enum.
*/
public final class TTFTableName {
- /** The first table in a True Type font file containing metadata about other tables. */
+
+ /** The first table in a TrueType font file containing metadata about other tables. */
public static final TTFTableName DIRECTORY_TABLE = new TTFTableName("dirTable");
- /** Embedded bitmap data */
+ /** Embedded bitmap data. */
public static final TTFTableName EBDT = new TTFTableName("EBDT");
- /** Embedded bitmap location data */
+ /** Embedded bitmap location data. */
public static final TTFTableName EBLC = new TTFTableName("EBLC");
- /** Embedded bitmap scaling data */
+ /** Embedded bitmap scaling data. */
public static final TTFTableName EBSC = new TTFTableName("EBSC");
- /** A font forge specific table */
+ /** A FontForge specific table. */
public static final TTFTableName FFTM = new TTFTableName("FFTM");
/** Divides glyphs into various classes that make using the GPOS/GSUB tables easier. */
public static final TTFTableName GDEF = new TTFTableName("GDEF");
- /** Provides kerning information, mark-to-base, etc. for opentype fonts */
+ /** Provides kerning information, mark-to-base, etc. for opentype fonts. */
public static final TTFTableName GPOS = new TTFTableName("GPOS");
- /** Provides ligature information, swash, etc. for opentype fonts */
+ /** Provides ligature information, swash, etc. for opentype fonts. */
public static final TTFTableName GSUB = new TTFTableName("GSUB");
- /** Linear threshold table */
+ /** Linear threshold table. */
public static final TTFTableName LTSH = new TTFTableName("LTSH");
- /** OS/2 and Windows specific metrics */
+ /** OS/2 and Windows specific metrics. */
public static final TTFTableName OS2 = new TTFTableName("OS/2");
- /** PCL 5 data*/
+ /** PCL 5 data. */
public static final TTFTableName PCLT = new TTFTableName("PCLT");
- /** Vertical Device Metrics table */
+ /** Vertical Device Metrics table. */
public static final TTFTableName VDMX = new TTFTableName("VDMX");
- /** character to glyph mapping */
+ /** Character to glyph mapping. */
public static final TTFTableName CMAP = new TTFTableName("cmap");
- /** Control Value Table */
+ /** Control Value Table. */
public static final TTFTableName CVT = new TTFTableName("cvt ");
- /** font program */
+ /** Font program. */
public static final TTFTableName FPGM = new TTFTableName("fpgm");
- /** grid-fitting and scan conversion procedure (grayscale) */
+ /** Grid-fitting and scan conversion procedure (grayscale). */
public static final TTFTableName GASP = new TTFTableName("gasp");
- /** glyph data */
+ /** Glyph data. */
public static final TTFTableName GLYF = new TTFTableName("glyf");
- /** horizontal device metrics */
+ /** Horizontal device metrics. */
public static final TTFTableName HDMX = new TTFTableName("hdmx");
- /** font header */
+ /** Font header. */
public static final TTFTableName HEAD = new TTFTableName("head");
- /** horizontal header */
+ /** Horizontal header. */
public static final TTFTableName HHEA = new TTFTableName("hhea");
- /** horizontal metrics */
+ /** Horizontal metrics. */
public static final TTFTableName HMTX = new TTFTableName("hmtx");
- /** kerning */
+ /** Kerning. */
public static final TTFTableName KERN = new TTFTableName("kern");
- /** index to location */
+ /** Index to location. */
public static final TTFTableName LOCA = new TTFTableName("loca");
- /** maximum profile */
+ /** Maximum profile. */
public static final TTFTableName MAXP = new TTFTableName("maxp");
- /** naming table */
+ /** Naming table. */
public static final TTFTableName NAME = new TTFTableName("name");
- /** PostScript information */
+ /** PostScript information. */
public static final TTFTableName POST = new TTFTableName("post");
- /** CVT Program */
+ /** CVT Program. */
public static final TTFTableName PREP = new TTFTableName("prep");
- /** Vertical Metrics header */
+ /** Vertical Metrics header. */
public static final TTFTableName VHEA = new TTFTableName("vhea");
- /** Vertical Metrics */
+ /** Vertical Metrics. */
public static final TTFTableName VMTX = new TTFTableName("vmtx");
private final String name;
}
/**
- * Returns the name of the table as it should be in the Table Directory.
- * @return String
+ * Returns the name of the table as it should be in the Directory Table.
*/
public String getName() {
return name;
}
/**
- * Returns the appropriate TTFTableName object when given the string representation.
- * @param tableName table name as in the Directory Table.
+ * Returns an instance of this class corresponding to the given string representation.
+ * @param tableName table name as in the Table Directory
* @return TTFTableName
*/
public static TTFTableName getValue(String tableName) {
import java.io.IOException;
/**
- * An interface for streaming full True Type tables from a TTF file.
+ * An interface for writing a TrueType table to an output stream.
*/
public interface TTFTableOutputStream {
/**
- * Streams a table defined in byteArray at offset of length bytes.
- * @param byteArray The source of the table to stream from.
- * @param offset The position in byteArray to begin streaming from.
- * @param length The number of bytes to stream.
- * @throws IOException write error.
+ * Streams a table from the given byte array.
+ *
+ * @param ttfData the source of the table to stream from
+ * @param offset the position in the byte array where the table starts
+ * @param size the size of the table in bytes
*/
- void streamTable(byte[] byteArray, int offset, int length) throws IOException;
+ void streamTable(byte[] ttfData, int offset, int size) throws IOException;
}
* This class streams glyphs from the "glyf" table in a True Type font.
*/
public class PSTTFGlyphOutputStream implements TTFGlyphOutputStream {
+
/** This counts the total number of bytes written that have been streamed. */
- private int byteCounter = 0;
+ private int byteCounter;
/** This is a place-holder for the offset of the last string boundary. */
- private int lastStringBoundary = 0;
+ private int lastStringBoundary;
private PSTTFGenerator ttfGen;
/**
this.ttfGen = ttfGen;
}
- /** {@inheritDoc} */
- public void startGlyphStream() throws IOException {
+ public void startGlyphStream() throws IOException {
ttfGen.startString();
}
- /** {@inheritDoc} */
- public void streamGlyph(byte[] byteArray, int offset, int length) throws IOException {
- if (length > PSTTFGenerator.MAX_BUFFER_SIZE) {
- throw new UnsupportedOperationException("The glyph is " + length + " there may be an "
- + "error in the font file.");
+ public void streamGlyph(byte[] glyphData, int offset, int size) throws IOException {
+ if (size > PSTTFGenerator.MAX_BUFFER_SIZE) {
+ throw new UnsupportedOperationException("The glyph is " + size
+ + " bytes. There may be an error in the font file.");
}
- if (length + (byteCounter - lastStringBoundary) < PSTTFGenerator.MAX_BUFFER_SIZE) {
- ttfGen.streamBytes(byteArray, offset, length);
+ if (size + (byteCounter - lastStringBoundary) < PSTTFGenerator.MAX_BUFFER_SIZE) {
+ ttfGen.streamBytes(glyphData, offset, size);
} else {
ttfGen.endString();
lastStringBoundary = byteCounter;
ttfGen.startString();
- ttfGen.streamBytes(byteArray, offset, length);
+ ttfGen.streamBytes(glyphData, offset, size);
}
- byteCounter += length;
+ byteCounter += size;
}
- /** {@inheritDoc} */
public void endGlyphStream() throws IOException {
ttfGen.endString();
}
+
}
*
*/
public class PSTTFTableOutputStream implements TTFTableOutputStream {
+
private PSTTFGenerator ttfGen;
+
/**
* Constructor.
* @param ttfGen PSGenerator the streamer class used for streaming bytes.
this.ttfGen = ttfGen;
}
- /** {@inheritDoc} */
- public void streamTable(byte[] byteArray, int offset, int length) throws IOException {
+ public void streamTable(byte[] ttfData, int offset, int size) throws IOException {
int offsetPosition = offset;
// Need to split the table into MAX_BUFFER_SIZE chunks
- for (int i = 0; i < length / PSTTFGenerator.MAX_BUFFER_SIZE; i++) {
- streamString(byteArray, offsetPosition, PSTTFGenerator.MAX_BUFFER_SIZE);
+ for (int i = 0; i < size / PSTTFGenerator.MAX_BUFFER_SIZE; i++) {
+ streamString(ttfData, offsetPosition, PSTTFGenerator.MAX_BUFFER_SIZE);
offsetPosition += PSTTFGenerator.MAX_BUFFER_SIZE;
}
- if (length % PSTTFGenerator.MAX_BUFFER_SIZE > 0) {
- streamString(byteArray, offsetPosition, length % PSTTFGenerator.MAX_BUFFER_SIZE);
+ if (size % PSTTFGenerator.MAX_BUFFER_SIZE > 0) {
+ streamString(ttfData, offsetPosition, size % PSTTFGenerator.MAX_BUFFER_SIZE);
}
}