Meziantou.Framework.Fonts 1.0.12

Prefix Reserved
dotnet add package Meziantou.Framework.Fonts --version 1.0.12
                    
NuGet\Install-Package Meziantou.Framework.Fonts -Version 1.0.12
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Meziantou.Framework.Fonts" Version="1.0.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meziantou.Framework.Fonts" Version="1.0.12" />
                    
Directory.Packages.props
<PackageReference Include="Meziantou.Framework.Fonts" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Meziantou.Framework.Fonts --version 1.0.12
                    
#r "nuget: Meziantou.Framework.Fonts, 1.0.12"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Meziantou.Framework.Fonts@1.0.12
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Meziantou.Framework.Fonts&version=1.0.12
                    
Install as a Cake Addin
#tool nuget:?package=Meziantou.Framework.Fonts&version=1.0.12
                    
Install as a Cake Tool

Meziantou.Framework.Fonts

The fully managed OpenType font reader and text shaper of Meziantou.Framework.Imaging and Meziantou.Framework.WebPlatform.

Its public API (FontLoader, FontFace, TextShaper, GlyphBuffer, ...) is the one these packages use: to load fonts and draw text, Meziantou.Framework.Imaging is the simpler entry point. Update the packages that use it together.

What it covers:

  • TrueType and OpenType fonts and font collections, WOFF 1.0 and WOFF 2.0
  • PostScript Type 1 fonts (PFB and PFA files), converted to OpenType fonts with CFF outlines when they are loaded, with the kerning and the metrics of their AFM file (FontLoader.LoadType1)
  • TrueType, CFF and CFF2 outlines, variable fonts (fvar, avar 1 and 2, gvar, HVAR, VVAR, MVAR)
  • Color fonts: COLR versions 0 and 1, CPAL, sbix, CBDT, and the documents of the SVG table
  • Horizontal and vertical metrics, BASE baselines
  • Hinting (GlyphHinter): outlines fitted to the pixel grid of a size, along the vertical axis without the instructions of the font (any outline format), or with the TrueType instructions (fpgm, prep, cvt , glyph programs) run by a bounded interpreter whose points are those of FreeType's version 40 interpreter for black and white pixels
  • Text shaping with GSUB and GPOS, and the shaping models of complex scripts (Arabic, Hebrew, Indic, Khmer, Myanmar, Thai and Lao, Hangul, and the universal shaping engine)
  • Apple Advanced Typography: the morx, kerx, feat and trak tables of the fonts made for Apple systems
  • The fonts installed on Windows, macOS and Linux (SystemFontCollection): an index of their faces by family and by name, read without loading the fonts, the font matching of CSS to choose a face of a family, and the characters each face has, read when they are first needed
  • AFM files (Adobe Font Metrics, AfmFontMetrics): the metrics of a PostScript font without its glyphs, such as the 14 standard fonts of PDF: global metrics, widths, bounding boxes and ligatures of the characters, kerning pairs and tracks, composite characters; the metrics of the 14 standard fonts of PDF are embedded (AfmFontMetrics.GetStandardFont)

The types are in the Meziantou.Framework.Fonts namespace:

// The fonts of the machine are scanned once per process; only the tables that describe a face are read.
var fonts = SystemFontCollection.Default;
if (fonts.Match("Arial", weight: 700, isItalic: false) is { } face)
{
    using var stream = File.OpenRead(face.FilePath);
    var font = FontLoader.Load(stream, new PooledFontEnvironment(FontResourceLimits.Default, 64 * 1024 * 1024))[face.FaceIndex];
    Console.WriteLine($"{font.FamilyName} {font.SubfamilyName}: {font.UnitsPerEm} units per em");
}

The characters of a face, from its character map, are read from its file the first time SystemFontDescriptor.Covers asks for one, and kept with the collection within a bounded amount of memory: scanning the fonts reads none of them.

// The characters of a face are read from its file the first time they are asked for, then kept with the collection.
var grinningFace = new Rune(0x1F600);
var emojiFont = SystemFontCollection.Default.Fonts.FirstOrDefault(face => face.Covers(grinningFace));
Console.WriteLine($"U+1F600: {emojiFont?.FamilyName ?? "no installed font"}");

An AFM file gives the metrics of text without loading a font:

// An AFM file gives the metrics of a PostScript font without its glyphs, here two characters of Helvetica.
var metrics = AfmFontMetrics.Parse("""
    StartFontMetrics 4.1
    FontName Helvetica
    StartCharMetrics 2
    C 65 ; WX 667 ; N A ; B 14 0 654 718 ;
    C 86 ; WX 667 ; N V ; B 20 0 647 718 ;
    EndCharMetrics
    StartKernData
    StartKernPairs 1
    KPX A V -70
    EndKernPairs
    EndKernData
    EndFontMetrics
    """);

// The metrics are in 1/1000 of the point size: the width of "AV" at 12 points, with its kerning.
var units = metrics.GetWidth("A")!.Value.X + metrics.GetKerning("A", "V").X + metrics.GetWidth("V")!.Value.X;
var width = units * 12 / 1000;
Assert.Equal(15.168, width);

The multiple master (AMFM) and composite (ACFM) metrics files are not supported.

The installed fonts are found in the fonts directory of Windows, in the fonts installed for the user and in the files the registry lists; in the Library/Fonts directories of macOS and in the fonts it downloads on demand; and on Linux in the directories of the configuration of fontconfig (fonts.conf and the files it includes) and in the XDG font directories. SystemFontCollection.Create indexes chosen directories instead.

It is written from the specifications and checked against HarfBuzz and FreeType.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Meziantou.Framework.Fonts:

Package Downloads
Meziantou.Framework.Imaging

Fully managed, performance-oriented image library for .NET: PNG, APNG, GIF, JPEG, WebP, QOI, BMP, TGA, Netpbm, TIFF, ICO/CUR, ANI, AVIF, HEIC and JPEG 2000 decoding/encoding, JPEG XL decoding and lossless/lossy encoding, lossless JPEG recompression as JPEG XL, animation-aware processing, vector drawing, ICC color conversion, and bounded-memory streaming.

Meziantou.Framework.WebPlatform

Spec-compliant HTML, XML, SVG and CSS parser exposing the browser DOM API (WHATWG DOM, HTML, URL, Encoding, Selectors, CSSOM, DOM XPath).

Meziantou.Framework.Pdf

Fully managed PDF library for .NET, written from ISO 32000-2: an object model, a reader that recovers broken files (cross-reference tables and streams, object streams, incremental updates), the standard filters (CCITT and JBIG2 included), full and incremental writers, a document API (pages, content builder, standard 14 fonts and embedded font subsets, shadings, patterns, forms and transparency, images, metadata, outlines, links, text extraction), a renderer of the pages to images, and PAdES digital signatures and their verification.

Meziantou.Framework.VectorGraphics

Retained vector scene (shapes, paths, texts, groups, gradients), deterministic SVG writer and text measurement with the metrics of Helvetica or any OpenType font. The drawing model of Meziantou.Framework.Charts and Meziantou.Framework.Diagrams.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.12 0 11/15/2026
1.0.11 68 11/14/2026
1.0.10 120 11/13/2026
1.0.9 560 11/8/2026
1.0.8 800 11/5/2026
1.0.7 230 11/1/2026
1.0.6 190 10/31/2026
1.0.5 326 10/29/2026
1.0.4 268 10/28/2026
1.0.3 498 10/25/2026
1.0.2 195 10/24/2026
1.0.1 365 10/21/2026
1.0.0 261 10/19/2026