public final class TTFSubsetter
extends java.lang.Object
Originally developed by Wolfgang Glas for Sketch.
Modifier and Type | Field and Description |
---|---|
private java.util.SortedSet<java.lang.Integer> |
glyphIds |
private boolean |
hasAddedCompoundReferences |
private java.util.List<java.lang.String> |
keepTables |
private static org.apache.commons.logging.Log |
LOG |
private static byte[] |
PAD_BUF |
private java.lang.String |
prefix |
private TrueTypeFont |
ttf |
private CmapLookup |
unicodeCmap |
private java.util.SortedMap<java.lang.Integer,java.lang.Integer> |
uniToGID |
Constructor and Description |
---|
TTFSubsetter(TrueTypeFont ttf)
Creates a subsetter for the given font.
|
TTFSubsetter(TrueTypeFont ttf,
java.util.List<java.lang.String> tables)
Creates a subsetter for the given font.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int unicode)
Add the given character code to the subset.
|
void |
addAll(java.util.Set<java.lang.Integer> unicodeSet)
Add the given character codes to the subset.
|
private void |
addCompoundReferences()
Resolve compound glyph references.
|
private byte[] |
buildCmapTable() |
private byte[] |
buildGlyfTable(long[] newOffsets) |
private byte[] |
buildHeadTable() |
private byte[] |
buildHheaTable() |
private byte[] |
buildHmtxTable() |
private byte[] |
buildLocaTable(long[] newOffsets) |
private byte[] |
buildMaxpTable() |
private byte[] |
buildNameTable() |
private byte[] |
buildOS2Table() |
private byte[] |
buildPostTable() |
private long |
copyBytes(java.io.InputStream is,
java.io.OutputStream os,
long newOffset,
long lastOffset,
int count) |
java.util.Map<java.lang.Integer,java.lang.Integer> |
getGIDMap()
Returns the map of new -> old GIDs.
|
private int |
getNewGlyphId(java.lang.Integer oldGid) |
private int |
log2(int num) |
void |
setPrefix(java.lang.String prefix)
Sets the prefix to add to the font's PostScript name.
|
private boolean |
shouldCopyNameRecord(NameRecord nr) |
private long |
toUInt32(byte[] bytes) |
private long |
toUInt32(int high,
int low) |
private long |
writeFileHeader(java.io.DataOutputStream out,
int nTables) |
private void |
writeFixed(java.io.DataOutputStream out,
double f) |
private void |
writeLongDateTime(java.io.DataOutputStream out,
java.util.Calendar calendar) |
private void |
writeSInt16(java.io.DataOutputStream out,
short i) |
private void |
writeTableBody(java.io.OutputStream os,
byte[] bytes) |
private long |
writeTableHeader(java.io.DataOutputStream out,
java.lang.String tag,
long offset,
byte[] bytes) |
void |
writeToStream(java.io.OutputStream os)
Write the subfont to the given output stream.
|
private void |
writeUint16(java.io.DataOutputStream out,
int i) |
private void |
writeUint32(java.io.DataOutputStream out,
long l) |
private void |
writeUint8(java.io.DataOutputStream out,
int i) |
private static final org.apache.commons.logging.Log LOG
private static final byte[] PAD_BUF
private final TrueTypeFont ttf
private final CmapLookup unicodeCmap
private final java.util.SortedMap<java.lang.Integer,java.lang.Integer> uniToGID
private final java.util.List<java.lang.String> keepTables
private final java.util.SortedSet<java.lang.Integer> glyphIds
private java.lang.String prefix
private boolean hasAddedCompoundReferences
public TTFSubsetter(TrueTypeFont ttf) throws java.io.IOException
ttf
- the font to be subsetjava.io.IOException
public TTFSubsetter(TrueTypeFont ttf, java.util.List<java.lang.String> tables) throws java.io.IOException
ttf
- the font to be subsettables
- optional tables to keep if presentjava.io.IOException
public void setPrefix(java.lang.String prefix)
public void add(int unicode)
unicode
- character codepublic void addAll(java.util.Set<java.lang.Integer> unicodeSet)
unicodeSet
- character code setpublic java.util.Map<java.lang.Integer,java.lang.Integer> getGIDMap() throws java.io.IOException
java.io.IOException
private long writeFileHeader(java.io.DataOutputStream out, int nTables) throws java.io.IOException
out
- The data output stream.nTables
- The number of table.java.io.IOException
- Upon errors.private long writeTableHeader(java.io.DataOutputStream out, java.lang.String tag, long offset, byte[] bytes) throws java.io.IOException
java.io.IOException
private void writeTableBody(java.io.OutputStream os, byte[] bytes) throws java.io.IOException
java.io.IOException
private byte[] buildHeadTable() throws java.io.IOException
java.io.IOException
private byte[] buildHheaTable() throws java.io.IOException
java.io.IOException
private boolean shouldCopyNameRecord(NameRecord nr)
private byte[] buildNameTable() throws java.io.IOException
java.io.IOException
private byte[] buildMaxpTable() throws java.io.IOException
java.io.IOException
private byte[] buildOS2Table() throws java.io.IOException
java.io.IOException
private byte[] buildLocaTable(long[] newOffsets) throws java.io.IOException
java.io.IOException
private void addCompoundReferences() throws java.io.IOException
java.io.IOException
private byte[] buildGlyfTable(long[] newOffsets) throws java.io.IOException
java.io.IOException
private int getNewGlyphId(java.lang.Integer oldGid)
private byte[] buildCmapTable() throws java.io.IOException
java.io.IOException
private byte[] buildPostTable() throws java.io.IOException
java.io.IOException
private byte[] buildHmtxTable() throws java.io.IOException
java.io.IOException
private long copyBytes(java.io.InputStream is, java.io.OutputStream os, long newOffset, long lastOffset, int count) throws java.io.IOException
java.io.IOException
public void writeToStream(java.io.OutputStream os) throws java.io.IOException
os
- the stream used for writing. It will be closed by this method.java.io.IOException
- if something went wrong.java.lang.IllegalStateException
- if the subset is empty.private void writeFixed(java.io.DataOutputStream out, double f) throws java.io.IOException
java.io.IOException
private void writeUint32(java.io.DataOutputStream out, long l) throws java.io.IOException
java.io.IOException
private void writeUint16(java.io.DataOutputStream out, int i) throws java.io.IOException
java.io.IOException
private void writeSInt16(java.io.DataOutputStream out, short i) throws java.io.IOException
java.io.IOException
private void writeUint8(java.io.DataOutputStream out, int i) throws java.io.IOException
java.io.IOException
private void writeLongDateTime(java.io.DataOutputStream out, java.util.Calendar calendar) throws java.io.IOException
java.io.IOException
private long toUInt32(int high, int low)
private long toUInt32(byte[] bytes)
private int log2(int num)