Table of Contents

Class SubsetOptions

Namespace
Egami.Fonts
Assembly
Egami.Fonts.dll
public sealed record SubsetOptions : IEquatable<SubsetOptions>
Inheritance
SubsetOptions
Implements
Inherited Members

Examples

// Keep only the glyphs a page uses, as a PDF writer embeds them: renumbered from 0, with the map to write the text with.
GlyphRun run = new Font(face, 12).Shape("Invoice 2026-10");
FontSubset subset = FontSubsetter.Subset(face, run.Glyphs.ToArray(), new SubsetOptions
{
    FontNamePrefix = "ABCDEF+",
    KeepCmap = false,
});
byte[] fontFile2 = subset.Data.ToArray();
ushort first = subset.GlyphMap[run.Glyphs[0]];

// The face's embedding permissions are reported, never enforced: the writer decides.
bool restricted = face.Embedding.HasFlag(FontEmbedding.Restricted);

Properties

Default

Gets the default options: the input's format, dense renumbering, a character map, no extra tables, no name prefix.

public static SubsetOptions Default { get; }

Property Value

SubsetOptions

FontNamePrefix

Gets the prefix put before the PostScript and CFF font names, such as the six-letter PDF subset tag "ABCDEF+".

public string? FontNamePrefix { get; init; }

Property Value

string

Format

Gets the output format. Defaults to Auto.

public SubsetFormat Format { get; init; }

Property Value

SubsetFormat

KeepCmap

Gets whether a character map for the kept glyphs is written (sfnt output only; PDF CIDFontType2 needs none). Defaults to true.

public bool KeepCmap { get; init; }

Property Value

bool

KeepTables

Gets tables copied unchanged, such as 'GSUB'; the caller answers for glyph ids inside them.

public IReadOnlyList<FontTag> KeepTables { get; init; }

Property Value

IReadOnlyList<FontTag>

LayoutClosure

Gets whether the subset can be shaped again as the full face would be: the kept glyphs gain every glyph GSUB can substitute for them (GetClosure(IEnumerable<ushort>, IEnumerable<FontTag>?) with DefaultClosureFeatures), and GSUB, GPOS and GDEF are copied unchanged. Copied layout tables hold the old glyph ids, so this needs RetainGlyphIds and sfnt output. Defaults to false, as a PDF needs only the glyphs drawn. To follow other features, pass the glyphs of GetClosure(IEnumerable<ushort>, IEnumerable<FontTag>?) with them, and keep the three tables with KeepTables.

public bool LayoutClosure { get; init; }

Property Value

bool

Examples

// Keep what the text's characters can become (ligatures, contextual forms) and the layout tables, so the subset shapes
// the text as the full face does; the copied tables use the old glyph ids, so the ids are kept.
ushort[] glyphs = [.. "office".Select(c => face.GetGlyph(c))];
FontSubset subset = FontSubsetter.Subset(face, glyphs, new SubsetOptions { RetainGlyphIds = true, LayoutClosure = true });
GlyphRun shaped = new Font(subset.ToTypeface(), 12).Shape("office");

Remarks

The tables of a variable face are copied with their variation data, so in the static subset GPOS positions and feature variations are those of the default instance, whatever Variations says.

RetainGlyphIds

Gets whether glyphs keep their ids, with empty glyphs in the gaps, rather than being renumbered densely in ascending order. Defaults to false.

public bool RetainGlyphIds { get; init; }

Property Value

bool

Variations

Gets the position a variable face's subset is written at, applied over the face's own position, or null (the default) for the face's position. A variable face's subset is always a static font: glyf with gvar's deltas applied and rounded, hmtx from the varied metrics, OS/2 and post with MVAR's values, CFF2 written as CFF with blends resolved, and the variation tables left out, so PDF viewers draw the position rather than the default instance.

public IReadOnlyList<FontVariation>? Variations { get; init; }

Property Value

IReadOnlyList<FontVariation>