FontSubsetter Class
Subsets the outlines of a font to the glyphs a document uses, keeping the glyph identifiers: the glyphs that are not kept are empty, so that what refers to a glyph by its identifier (a PDF content stream, a shaped text) is unchanged.
public static class FontSubsetterRemarks
- TrueType outlines (
FontSubsetter.SubsetTrueType): an sfnt with theglyfandlocatables rebuilt from the kept glyphs and the components of the composite glyphs among them, the metrics tables as they are, the instructions on request, and aposttable without glyph names. - CFF outlines (
FontSubsetter.SubsetCff): a CID-keyedCFFtable whose CIDs are the glyph identifiers (OpenType specification, "CFF"; Adobe Technical Note #5176): the charstrings of the glyphs that are not kept areendchar, the subroutines are kept whole.
Methods
| Name | Description |
|---|---|
| GetClosure(FontFace, IEnumerable<int>) | Gets the glyphs a subset keeps: the requested glyphs, the glyph 0 (.notdef) and the components of the composite glyphs. |
| SubsetCff(FontFace, IEnumerable<int>, string) | Subsets the CFF table of a font into a CID-keyed CFF table whose CIDs are the glyph identifiers. |
| SubsetTrueType(FontFace, IEnumerable<int>, bool) | Subsets a font with TrueType outlines. |
GetClosure(FontFace, IEnumerable<int>)
FontSubsetter.csGets the glyphs a subset keeps: the requested glyphs, the glyph 0 (.notdef) and the components of the composite glyphs.
public static SortedSet<int> GetClosure(FontFace face, IEnumerable<int> glyphs)Parameters
faceFontFace- The face.
glyphsIEnumerable<int>- The glyphs a document uses; the identifiers that are not glyphs of the face are ignored.
Returns
SortedSet<int> The glyphs, sorted.
SubsetCff(FontFace, IEnumerable<int>, string)
FontSubsetter.csSubsets the CFF table of a font into a CID-keyed CFF table whose CIDs are the glyph identifiers.
public static byte[] SubsetCff(FontFace face, IEnumerable<int> glyphs, string fontName)Parameters
faceFontFace- The face: its outlines are CFF outlines.
glyphsIEnumerable<int>- The glyphs to keep; the glyph 0 is always kept.
fontNamestring- The name of the font in the table.
Returns
byte[] The CFF table.
Exceptions
ArgumentException- The face does not have CFF outlines.
InvalidFontException- The CFF table is malformed.
SubsetTrueType(FontFace, IEnumerable<int>, bool)
FontSubsetter.csSubsets a font with TrueType outlines.
public static byte[] SubsetTrueType(FontFace face, IEnumerable<int> glyphs, bool keepHinting = true)Parameters
faceFontFace- The face: its outlines are TrueType outlines.
glyphsIEnumerable<int>- The glyphs to keep; the closure (
FontSubsetter.GetClosure) is computed. keepHintingbool- Whether to keep the instructions (
cvt,fpgm,prepand the instructions of the glyphs).
Returns
byte[] The font file.
Exceptions
ArgumentException- The face does not have TrueType outlines.
InvalidFontException- A table the subset needs is missing or malformed.