Package org.apache.fontbox.ttf
Class TTFSubsetter
java.lang.Object
org.apache.fontbox.ttf.TTFSubsetter
Subsetter for TrueType (TTF) fonts.
Originally developed by Wolfgang Glas for Sketch.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate static final org.apache.commons.logging.Logprivate static final byte[]private Stringprivate final TrueTypeFontprivate final CmapLookup -
Constructor Summary
ConstructorsConstructorDescriptionTTFSubsetter(TrueTypeFont ttf) Creates a subsetter for the given font.TTFSubsetter(TrueTypeFont ttf, List<String> tables) Creates a subsetter for the given font. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int unicode) Add the given character code to the subset.voidAdd the given character codes to the subset.private voidResolve compound glyph references.private byte[]private byte[]buildGlyfTable(long[] newOffsets) private byte[]private byte[]private byte[]private byte[]buildLocaTable(long[] newOffsets) private byte[]private byte[]private byte[]private byte[]private longcopyBytes(InputStream is, OutputStream os, long newOffset, long lastOffset, int count) Returns the map of new -> old GIDs.private intgetNewGlyphId(Integer oldGid) private intlog2(int num) voidSets the prefix to add to the font's PostScript name.private booleanprivate longtoUInt32(byte[] bytes) private longtoUInt32(int high, int low) private longwriteFileHeader(DataOutputStream out, int nTables) private voidwriteFixed(DataOutputStream out, double f) private voidwriteLongDateTime(DataOutputStream out, Calendar calendar) private voidwriteSInt16(DataOutputStream out, short i) private voidwriteTableBody(OutputStream os, byte[] bytes) private longwriteTableHeader(DataOutputStream out, String tag, long offset, byte[] bytes) voidWrite the subfont to the given output stream.private voidwriteUint16(DataOutputStream out, int i) private voidwriteUint32(DataOutputStream out, long l) private voidwriteUint8(DataOutputStream out, int i)
-
Field Details
-
LOG
private static final org.apache.commons.logging.Log LOG -
PAD_BUF
private static final byte[] PAD_BUF -
ttf
-
unicodeCmap
-
uniToGID
-
keepTables
-
glyphIds
-
prefix
-
hasAddedCompoundReferences
private boolean hasAddedCompoundReferences
-
-
Constructor Details
-
TTFSubsetter
Creates a subsetter for the given font.- Parameters:
ttf- the font to be subset- Throws:
IOException
-
TTFSubsetter
Creates a subsetter for the given font.- Parameters:
ttf- the font to be subsettables- optional tables to keep if present- Throws:
IOException
-
-
Method Details
-
setPrefix
Sets the prefix to add to the font's PostScript name. -
add
public void add(int unicode) Add the given character code to the subset.- Parameters:
unicode- character code
-
addAll
Add the given character codes to the subset.- Parameters:
unicodeSet- character code set
-
getGIDMap
Returns the map of new -> old GIDs.- Throws:
IOException
-
writeFileHeader
- Parameters:
out- The data output stream.nTables- The number of table.- Returns:
- The file offset of the first TTF table to write.
- Throws:
IOException- Upon errors.
-
writeTableHeader
private long writeTableHeader(DataOutputStream out, String tag, long offset, byte[] bytes) throws IOException - Throws:
IOException
-
writeTableBody
- Throws:
IOException
-
buildHeadTable
- Throws:
IOException
-
buildHheaTable
- Throws:
IOException
-
shouldCopyNameRecord
-
buildNameTable
- Throws:
IOException
-
buildMaxpTable
- Throws:
IOException
-
buildOS2Table
- Throws:
IOException
-
buildLocaTable
- Throws:
IOException
-
addCompoundReferences
Resolve compound glyph references.- Throws:
IOException
-
buildGlyfTable
- Throws:
IOException
-
getNewGlyphId
-
buildCmapTable
- Throws:
IOException
-
buildPostTable
- Throws:
IOException
-
buildHmtxTable
- Throws:
IOException
-
copyBytes
private long copyBytes(InputStream is, OutputStream os, long newOffset, long lastOffset, int count) throws IOException - Throws:
IOException
-
writeToStream
Write the subfont to the given output stream.- Parameters:
os- the stream used for writing. It will be closed by this method.- Throws:
IOException- if something went wrong.IllegalStateException- if the subset is empty.
-
writeFixed
- Throws:
IOException
-
writeUint32
- Throws:
IOException
-
writeUint16
- Throws:
IOException
-
writeSInt16
- Throws:
IOException
-
writeUint8
- Throws:
IOException
-
writeLongDateTime
- Throws:
IOException
-
toUInt32
private long toUInt32(int high, int low) -
toUInt32
private long toUInt32(byte[] bytes) -
log2
private int log2(int num)
-