org.apache.fontbox.ttf

## Class TTFSubsetter

- java.lang.Object
- - org.apache.fontbox.ttf.TTFSubsetter

    public final class TTFSubsetter
    extends Object

Subsetter for TrueType (TTF) fonts.

Originally developed by Wolfgang Glas for Sketch.

Author:
  Wolfgang Glas

### Constructor Summary

Constructors
Constructor and Description
`TTFSubsetter(TrueTypeFont ttf)` Creates a subsetter for the given font.
`TTFSubsetter(TrueTypeFont ttf, List<String> tables)` Creates a subsetter for the given font.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `add(int unicode)` Add the given character code to the subset.
`void` `addAll(Set<Integer> unicodeSet)` Add the given character codes to the subset.
`void` `forceInvisible(int unicode)` Forces the glyph for the specified character code to be zero-width and contour-free, regardless of what the glyph looks like in the original font.
`Map<Integer,Integer>` `getGIDMap()` Returns the map of new -> old GIDs.
`void` `setPrefix(String prefix)` Sets the prefix to add to the font's PostScript name.
`void` `writeToStream(OutputStream os)` Write the subfont to the given output stream.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### TTFSubsetter

    public TTFSubsetter(TrueTypeFont ttf)
                 throws IOException

Creates a subsetter for the given font.

Parameters:
  `ttf` - the font to be subset
Throws:
  `IOException`

#### TTFSubsetter

    public TTFSubsetter(TrueTypeFont ttf,
                        List<String> tables)
                 throws IOException

Creates a subsetter for the given font.

Parameters:
  `ttf` - the font to be subset
  `tables` - optional tables to keep if present
Throws:
  `IOException`

### Method Detail

#### setPrefix

    public void setPrefix(String prefix)

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

    public void addAll(Set<Integer> unicodeSet)

Add the given character codes to the subset.

Parameters:
  `unicodeSet` - character code set

#### forceInvisible

    public void forceInvisible(int unicode)

Forces the glyph for the specified character code to be zero-width and contour-free, regardless of what the glyph looks like in the original font. Note that the specified character code is not added to the subset unless it is also `added` separately.

Parameters:
  `unicode` - the character code whose glyph should be invisible

#### getGIDMap

    public Map<Integer,Integer> getGIDMap()
                                   throws IOException

Returns the map of new -> old GIDs.

Throws:
  `IOException`

#### writeToStream

    public void writeToStream(OutputStream os)
                       throws IOException

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.