Table of Contents

Enum FontMetrics

Namespace
Egami.Fonts
Assembly
Egami.Fonts.dll

Where a font's advances come from.

public enum FontMetrics

Fields

Compatible = 2

GDI's compatible widths: the advances black-and-white hinting gives, from the hdmx table when it has the size, else the rounded design advance where the LTSH table says the glyph scales linearly, else the glyph's instructions run for a monochrome rasterizer. Whole pixels, cached per face and size; faces that cannot be hinted keep their design advances, rounded. Glyph origins snap to whole pixels.

Design = 0

The design advances, scaled: fractional pixels, the same at every size.

GridFitted = 1

The hinted advances at a whole number of pixels per em: each glyph's right phantom point less its left after the font's instructions run for HintingTarget. Measuring and drawing both use them, and glyph origins snap to whole pixels. Faces that cannot be hinted keep their design advances, rounded. With GdiPlus these are the advances Graphics.DrawString draws with its default StringFormat.

GridFittedToDesign = 3

GridFitted advances, except that a run they would make more than 2.1 pixels wider than designed keeps its design advances, rounded up to sixteenths of a pixel, as Graphics.DrawString lays out such lines with StringFormat.GenericTypographic (glyph origins still snap to whole pixels).

Examples

// The font's own TrueType instructions, run for GDI+, with its hinted advances: glyphs on whole pixels, spacing as Windows
// lays out ClearType text. Together with GDI+'s filter, sampling and gamma (1 + TextContrast/10 = 1.4), this is the closest
// Egami gets to System.Drawing's ClearTypeGridFit.
var label = new Font(face, 16)
{
    Hinting = FontHinting.Full,
    HintingTarget = TrueTypeTarget.GdiPlus,
    Metrics = FontMetrics.GridFitted,
    Edging = FontEdging.Lcd,
};
var gdiPlus = new CanvasOptions
{
    PixelGeometry = PixelGeometry.RgbHorizontal,
    LcdFilter = LcdFilter.Gdi,
    LcdSampling = LcdSampling.Gdi,
    TextGamma = 1.4f,
};
using (RasterCanvas<Rgb8> canvas = button.CreateCanvas(gdiPlus))
{
    // Measuring uses the same hinted advances, so centring is exact.
    float width = label.MeasureText("Start the course").Advance;
    canvas.DrawText("Start the course", new Vector2(MathF.Round((200 - width) / 2), 26), label, Rgba8.White);
}