org.apache.fop.fonts.truetype

## Class TTFSubSetFile

- java.lang.Object
- - org.apache.fop.fonts.truetype.OpenFont
  - - org.apache.fop.fonts.truetype.TTFFile
    - - org.apache.fop.fonts.truetype.TTFSubSetFile

    public class TTFSubSetFile
    extends TTFFile

Reads a TrueType file and generates a subset that can be used to embed a TrueType CID font. TrueType tables needed for embedded CID fonts are: "head", "hhea", "loca", "maxp", "cvt ", "prep", "glyf", "hmtx" and "fpgm". The TrueType spec can be found at the Microsoft Typography site: http://www.microsoft.com/truetype/

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.fop.fonts.truetype.OpenFont

`OpenFont.PostScriptVersion`

### Field Summary

Fields
`protected int` `currentPos`
`protected int[]` `glyphOffsets` Stores the glyph offsets so that we can end strings at glyph boundaries
`protected int` `locaOffset`
`protected Map<OFTableName,OFDirTabEntry>` `newDirTabs` The dir tab entries in the new subset font.
`protected Map<OFTableName,Integer>` `offsets`
`protected byte[]` `output`
`protected int` `realSize`

### Fields inherited from class org.apache.fop.fonts.truetype.OpenFont

`advancedTableReader, cid, dirTabs, embedFontName, familyNames, fontFile, fullName, lastLoca, locaFormat, log, mtxTab, nhmtx, notice, numberOfGlyphs, postScriptName, subFamilyName, svgs, TRACE_ENABLED, unicodeMappings, useAdvanced, useKerning`

### Constructor Summary

Constructors
Constructor and Description
`TTFSubSetFile()` Default Constructor
`TTFSubSetFile(boolean useKerning, boolean useAdvanced)` Constructor

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected int[]` `buildSubsetIndexToOrigIndexMap(Map<Integer,Integer> glyphs)`
`protected void` `createCheckSumAdjustment()`
`protected boolean` `createCvt(FontFileReader in)` Copy the cvt table as is from original font to subset font
`protected void` `createDirectory()` Create the directory table
`protected boolean` `createFpgm(FontFileReader in)` Copy the fpgm table as is from original font to subset font
`protected void` `createHead(FontFileReader in)` Copy the head table as is from original font to subset font and set indexToLocaFormat to long and set checkSumAdjustment to 0, store offset to checkSumAdjustment in checkSumAdjustmentOffset
`protected void` `createHhea(FontFileReader in, int size)` Copy the hhea table as is from original font to subset font and fill in size of hmtx table
`protected void` `createHmtx(FontFileReader in, Map<Integer,Integer> glyphs)` Create the hmtx table by copying metrics from original font to subset font.
`protected void` `createLoca(int size)` Create an empty loca table without updating checksum
`protected void` `createMaxp(FontFileReader in, int size)` Copy the maxp table as is from original font to subset font and set num glyphs to size
`protected boolean` `createName(FontFileReader in)` Copy the name table as is from the original.
`protected boolean` `createOS2(FontFileReader in)` Copy the OS/2 table as is from the original.
`protected void` `createPost(FontFileReader in)`
`protected boolean` `createPrep(FontFileReader in)` Copy the prep table as is from original font to subset font
`protected static int` `getCheckSum(byte[] data, int start, int size)`
`byte[]` `getFontSubset()` Returns a subset of the fonts (readFont() MUST be called first in order to create the subset).
`protected void` `pad4()` Create a padding in the fontfile to align on a 4-byte boundary
`void` `readFont(FontFileReader in, String name, String header, Map<Integer,Integer> glyphs)` Reads a font and creates a subset of the font.
`protected void` `scanGlyphs(FontFileReader in, Map<Integer,Integer> subsetGlyphs)`
`void` `stream(TTFOutputStream ttfOut)` Streams a font.
`protected void` `updateCheckSum(int tableStart, int tableSize, OFTableName tableName)`
`protected void` `writeBytes(byte[] b)`
`protected void` `writeULong(int pos, int s)` Appends a ULONG to the output array, at the given position without changing currentPos
`protected void` `writeUShort(int s)` Appends a USHORT to the output array, updates currentPost but not realSize
`protected void` `writeUShort(int pos, int s)` Appends a USHORT to the output array, at the given position without changing currentPos

### Methods inherited from class org.apache.fop.fonts.truetype.TTFFile

`getLastGlyfLocation, initializeFont, readIndexToLocation, readName, updateBBoxAndOffset`

### Methods inherited from class org.apache.fop.fonts.truetype.OpenFont

`checkTTC, convertTTFUnit2PDFUnit, createCMaps, determineAscDesc, getAnsiKerning, getBBox, getBBoxRaw, getBoundingBoxes, getCapHeight, getCharSetName, getCharWidth, getCharWidthRaw, getCMaps, getCopyrightNotice, getDirectoryEntry, getEmbedFontName, getFamilyNames, getFirstChar, getFlags, getFontBBox, getFullName, getGDEF, getGPOS, getGSUB, getItalicAngle, getKerning, getLastChar, getLowerCaseAscent, getLowerCaseDescent, getMtx, getNumGlyphs, getPadSize, getPostScriptName, getStemV, getStrikeoutPosition, getStrikeoutThickness, getSubFamilyName, getTTCnames, getUnderlinePosition, getUnderlineThickness, getWeightClass, getWidths, getXHeight, guessVerticalMetricsFromGlyphBBox, handleCharacterSpacing, hasAdvancedTable, initAnsiWidths, isCFF, isEmbeddable, main, printStuff, readCMAP, readDirTabs, readFont, readFont, readFont, readFontHeader, readHorizontalHeader, readHorizontalMetrics, readKerning, readOS2, readPCLT, readPostScript, seekTab`

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

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

### Field Detail

#### output

    protected byte[] output

#### realSize

    protected int realSize

#### currentPos

    protected int currentPos

#### offsets

    protected Map<OFTableName,Integer> offsets

#### locaOffset

    protected int locaOffset

#### glyphOffsets

    protected int[] glyphOffsets

Stores the glyph offsets so that we can end strings at glyph boundaries

#### newDirTabs

    protected Map<OFTableName,OFDirTabEntry> newDirTabs

The dir tab entries in the new subset font.

### Constructor Detail

#### TTFSubSetFile

    public TTFSubSetFile()

Default Constructor

#### TTFSubSetFile

    public TTFSubSetFile(boolean useKerning,
                         boolean useAdvanced)

Constructor

Parameters:
  `useKerning` - true if kerning data should be loaded
  `useAdvanced` - true if advanced typographic tables should be loaded

### Method Detail

#### createDirectory

    protected void createDirectory()

Create the directory table

#### createLoca

    protected void createLoca(int size)
                       throws IOException

Create an empty loca table without updating checksum

Throws:
  `IOException`

#### createCvt

    protected boolean createCvt(FontFileReader in)
                         throws IOException

Copy the cvt table as is from original font to subset font

Throws:
  `IOException`

#### createFpgm

    protected boolean createFpgm(FontFileReader in)
                          throws IOException

Copy the fpgm table as is from original font to subset font

Throws:
  `IOException`

#### createName

    protected boolean createName(FontFileReader in)
                          throws IOException

Copy the name table as is from the original.

Throws:
  `IOException`

#### createOS2

    protected boolean createOS2(FontFileReader in)
                         throws IOException

Copy the OS/2 table as is from the original.

Throws:
  `IOException`

#### createMaxp

    protected void createMaxp(FontFileReader in,
                              int size)
                       throws IOException

Copy the maxp table as is from original font to subset font and set num glyphs to size

Throws:
  `IOException`

#### createPost

    protected void createPost(FontFileReader in)
                       throws IOException

Throws:
  `IOException`

#### createPrep

    protected boolean createPrep(FontFileReader in)
                          throws IOException

Copy the prep table as is from original font to subset font

Throws:
  `IOException`

#### createHhea

    protected void createHhea(FontFileReader in,
                              int size)
                       throws IOException

Copy the hhea table as is from original font to subset font and fill in size of hmtx table

Throws:
  `IOException`

#### createHead

    protected void createHead(FontFileReader in)
                       throws IOException

Copy the head table as is from original font to subset font and set indexToLocaFormat to long and set checkSumAdjustment to 0, store offset to checkSumAdjustment in checkSumAdjustmentOffset

Throws:
  `IOException`

#### buildSubsetIndexToOrigIndexMap

    protected int[] buildSubsetIndexToOrigIndexMap(Map<Integer,Integer> glyphs)

#### createHmtx

    protected void createHmtx(FontFileReader in,
                              Map<Integer,Integer> glyphs)
                       throws IOException

Create the hmtx table by copying metrics from original font to subset font. The glyphs Map contains an Integer key and Integer value that maps the original metric (key) to the subset metric (value)

Throws:
  `IOException`

#### readFont

    public void readFont(FontFileReader in,
                         String name,
                         String header,
                         Map<Integer,Integer> glyphs)
                  throws IOException

Reads a font and creates a subset of the font.

Parameters:
  `in` - FontFileReader to read from
  `name` - Name to be checked for in the font file
  `glyphs` - Map of glyphs (glyphs has old index as (Integer) key and new index as (Integer) value)
Throws:
  `IOException` - in case of an I/O problem

#### getFontSubset

    public byte[] getFontSubset()

Returns a subset of the fonts (readFont() MUST be called first in order to create the subset).

Returns:
  byte array

#### stream

    public void stream(TTFOutputStream ttfOut)
                throws IOException

Description copied from class: `OpenFont`
Streams a font.

Overrides:
  `stream` in class `OpenFont`
Parameters:
  `ttfOut` - The interface for streaming TrueType tables.
Throws:
  `IOException` - file write error

#### scanGlyphs

    protected void scanGlyphs(FontFileReader in,
                              Map<Integer,Integer> subsetGlyphs)
                       throws IOException

Throws:
  `IOException`

#### writeBytes

    protected void writeBytes(byte[] b)

#### writeUShort

    protected void writeUShort(int s)

Appends a USHORT to the output array, updates currentPost but not realSize

#### writeUShort

    protected void writeUShort(int pos,
                               int s)

Appends a USHORT to the output array, at the given position without changing currentPos

#### writeULong

    protected void writeULong(int pos,
                              int s)

Appends a ULONG to the output array, at the given position without changing currentPos

#### pad4

    protected void pad4()

Create a padding in the fontfile to align on a 4-byte boundary

#### updateCheckSum

    protected void updateCheckSum(int tableStart,
                                  int tableSize,
                                  OFTableName tableName)

#### getCheckSum

    protected static int getCheckSum(byte[] data,
                                     int start,
                                     int size)

#### createCheckSumAdjustment

    protected void createCheckSumAdjustment()