CffFont Class

A font program in the Compact Font Format (Adobe Technical Note #5176) on its own, not in an OpenType font: a .cff file, or a program embedded in a PDF document (/FontFile3, Type1C and CIDFontType0C). It gives the names (or the CIDs) of the glyphs, the built-in encoding, the font matrix and the outlines.

public sealed class CffFont

Remarks

Only the first font of the program is read. The glyphs of a CID-keyed font are found by their CIDs, the glyphs of the other fonts by their names or their codes. The seac operator (a base character and an accent, Adobe Technical Note #5177, appendix C) is drawn from the glyphs the standard encoding gives to its codes.

The object is immutable and can be used from several threads.

Properties

NameDescription
FontMatrixGets the matrix from the units of the outlines to text space, as the six values a b c d e f: the one of the font dictionary of a CID-keyed font multiplied by the one of the Top DICT, or 0.001 0 0 0.001 0 0 by default.
GlyphCountGets the number of glyphs of the font.
IsCidKeyedGets a value indicating whether the font is CID-keyed: its glyphs are found by their CIDs, not by their names.

FontMatrix

CffFont.cs

Gets the matrix from the units of the outlines to text space, as the six values a b c d e f: the one of the font dictionary of a CID-keyed font multiplied by the one of the Top DICT, or 0.001 0 0 0.001 0 0 by default.

public IReadOnlyList<double> FontMatrix { get; }

Property value

IReadOnlyList<double>

GlyphCount

CffFont.cs

Gets the number of glyphs of the font.

public int GlyphCount { get; }

Property value

int

IsCidKeyed

CffFont.cs

Gets a value indicating whether the font is CID-keyed: its glyphs are found by their CIDs, not by their names.

public bool IsCidKeyed { get; }

Property value

bool

Methods

NameDescription
DecodeOutline(int, OutlineSink, GlyphBudget)Decodes the outline of a glyph, in the units of the outlines (see CffFont.FontMatrix). A glyph identifier that is not a glyph of the font draws nothing.
GetGlyphByCid(int)Gets the glyph of a CID: through the charset of a CID-keyed font, the CID itself otherwise.
GetGlyphByCode(int)Gets the glyph of a code in the built-in encoding of a font that is not CID-keyed (the standard encoding when the program has none).
GetGlyphByName(string)Gets the glyph of a name in the charset of a font that is not CID-keyed.
GetGlyphName(int)Gets the name of a glyph in the charset of a font that is not CID-keyed.
Load(ReadOnlySpan<byte>)Reads a CFF font program.

DecodeOutline(int, OutlineSink, GlyphBudget)

CffFont.cs

Decodes the outline of a glyph, in the units of the outlines (see CffFont.FontMatrix). A glyph identifier that is not a glyph of the font draws nothing.

public void DecodeOutline(int glyphId, OutlineSink sink, ref GlyphBudget budget)

Parameters

glyphId int
The glyph.
sink OutlineSink
The receiver of the contours.
budget GlyphBudget
The limits of the work of the decoding (the operators of the charstrings, the subroutine calls).

Exceptions

InvalidFontException
The charstring of the glyph is malformed, or it exceeds the budget.

GetGlyphByCid(int)

CffFont.cs

Gets the glyph of a CID: through the charset of a CID-keyed font, the CID itself otherwise.

public int GetGlyphByCid(int cid)

Parameters

cid int
The CID.

Returns

int The glyph, or 0 (.notdef) when a CID-keyed font has no glyph for the CID.

GetGlyphByCode(int)

CffFont.cs

Gets the glyph of a code in the built-in encoding of a font that is not CID-keyed (the standard encoding when the program has none).

public int GetGlyphByCode(int code)

Parameters

code int
The code, from 0 to 255.

Returns

int The glyph, or 0 (.notdef) when the code has none.

GetGlyphByName(string)

CffFont.cs

Gets the glyph of a name in the charset of a font that is not CID-keyed.

public int GetGlyphByName(string name)

Parameters

name string
The name of the glyph, such as A.

Returns

int The glyph, or 0 (.notdef) when the font has no glyph of that name.

GetGlyphName(int)

CffFont.cs

Gets the name of a glyph in the charset of a font that is not CID-keyed.

public string? GetGlyphName(int glyphId)

Parameters

glyphId int
The glyph.

Returns

string? The name, or null for a CID-keyed font or a glyph without a name.

Load(ReadOnlySpan<byte>)

CffFont.cs

Reads a CFF font program.

public static CffFont Load(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>
The bytes of the program, starting with the CFF header. They are copied.

Returns

CffFont The font.

Exceptions

InvalidFontException
The program is not a valid CFF program.