GlyphHinter Class

Decodes the outlines of the glyphs of a font fitted to the pixel grid of a size: hinted outlines are sharper at small sizes, where an exactly scaled outline puts its edges across pixels.

public sealed class GlyphHinter : IDisposable

Remarks

The outlines are given in font units, like those of FontFace.DecodeOutline: multiplied by the size divided by FontFace.UnitsPerEm, their hinted coordinates are on the pixel grid, with the origin of the glyph at a whole pixel. The y axis goes up.

GlyphHinting.Full runs the TrueType instructions of the font (OpenType specification, "TrueType Instructions"), with the version 40 interpreter of FreeType hinting for black and white pixels (FT_LOAD_TARGET_MONO) as the reference. A font program or a control value program that breaks a rule of the specification makes the font unhinted; instructions of a glyph that break one make that glyph unhinted. The work of the programs is bounded: each run charges every instruction to a GlyphBudget, and the stack, the storage area, the control values, the functions and the twilight zone are sized from the font and rented from the allocator.

A hinter keeps the state of the programs of the font at its size: it is used by one operation at a time, and must be disposed to give its storage back to the allocator.

Implements

Properties

NameDescription
HintingGets how the outlines are hinted: the mode asked for, or GlyphHinting.Light when GlyphHinting.Full was asked for a font whose instructions cannot be run.
SizeGets the size the outlines are hinted for, in pixels per em.

Gets how the outlines are hinted: the mode asked for, or GlyphHinting.Light when GlyphHinting.Full was asked for a font whose instructions cannot be run.

public GlyphHinting Hinting { get; }

Property value

GlyphHinting

Gets the size the outlines are hinted for, in pixels per em.

public double Size { get; }

Property value

double

Methods

NameDescription
Create(FontFace, double, GlyphHinting, GlyphScratch, FontAllocator)Creates a hinter for a font at a size: with GlyphHinting.Full, runs the font program and the control value program.
DecodeOutline(int, OutlineSink, GlyphScratch, GlyphBudget)Decodes the hinted outline of a glyph into a sink, in font units, and gives its advance.
Dispose()Gives back the storage of the state of the instructions.

Create(FontFace, double, GlyphHinting, GlyphScratch, FontAllocator)

GlyphHinter.cs

Creates a hinter for a font at a size: with GlyphHinting.Full, runs the font program and the control value program.

public static GlyphHinter Create(FontFace face, double size, GlyphHinting hinting, GlyphScratch scratch, FontAllocator allocator)

Parameters

face FontFace
The font.
size double
The size, in pixels per em.
hinting GlyphHinting
How the outlines are hinted.
scratch GlyphScratch
The working storage of the glyphs the hinter measures to find the alignment zones of the font.
allocator FontAllocator
The storage of the state of the TrueType instructions.

Returns

GlyphHinter

Exceptions

ArgumentOutOfRangeException
size is not a positive finite number, or hinting is not a defined value.
InvalidFontException
The data of the font is malformed.
FontResourceLimitException
A program of the font exceeds the complexity limit, or its storage exceeds the allocation limit.

DecodeOutline(int, OutlineSink, GlyphScratch, GlyphBudget)

GlyphHinter.cs

Decodes the hinted outline of a glyph into a sink, in font units, and gives its advance.

public double DecodeOutline(int glyphId, OutlineSink sink, GlyphScratch scratch, ref GlyphBudget budget)

Parameters

glyphId int
The glyph.
sink OutlineSink
The sink.
scratch GlyphScratch
The working storage of the outline.
budget GlyphBudget
The budget of the glyph, which its instructions are charged to.

Returns

double The advance of the glyph, in pixels: a whole number with GlyphHinting.Full, the advance of the font scaled to the size otherwise.

Exceptions

ObjectDisposedException
The hinter is disposed.
InvalidFontException
The data of the glyph is malformed.
FontResourceLimitException
The glyph exceeds the complexity limit or the allocation limit.

Gives back the storage of the state of the instructions.

public void Dispose()