PinataLabs.Typography is a cross-platform .NET library that loads fonts and lays out and measures text. It is written in C# and has no native dependencies.
Read the documentation for guides, the API reference and troubleshooting.
- Read font descriptions: name, family, subfamily and other string metadata.
- Load OpenType fonts with CFF1, CFF2 and TrueType outlines.
- Load TrueType fonts and TrueType collections (
.ttc). - Load WOFF and WOFF2 fonts.
- Load all compatible fonts installed on the machine (Windows, Linux and macOS).
- Choose a face by weight, width and slope with CSS font matching.
- Variable fonts at any instance:
fvar,avar,gvar,cvar, CFF2 blends,HVAR,VVAR,MVAR, and GPOS and feature variations. - Line breaking based on UAX #14.
- The Unicode algorithms and character properties are also published without any font code, as
PinataLabs.Typography.Unicode. It reports the Unicode version of its data asUnicodeInfo.Version. - Left-to-right, right-to-left and bidirectional text.
- Ligatures, and the OpenType glyph substitution (GSUB) and glyph positioning (GPOS) features.
- Measure the size, advance and bounds of laid-out text.
- Shape a run into glyph IDs with clusters, advances and offsets, matching HarfBuzz 15.
- Line breaking, bidi paragraphs (UAX #9) and script and direction itemization as public APIs.
- Read TrueType, CFF and Type 1 font programs by glyph ID, and subset CFF and TrueType fonts with their glyph IDs kept.
- Read PDF font descriptor metrics and OS/2 embedding permissions.
- Map glyph names to Unicode with the Adobe Glyph List and the PDF standard encodings.
- Trimmable and Native AOT compatible on
net8.0and later.
- The library targets
netstandard2.1,net8.0,net10.0andnet11.0. - To build the repository, you must install the .NET 11 SDK, RC2 or later (
11.0.100-rc.2).global.jsonpins this SDK. If it is not installed,dotnet buildstops with an SDK-not-found error.
The package is not yet published to NuGet. To use the library, build it from source:
git clone https://github.com/PinataLabs/Typography
cd Typography
dotnet build PinataLabs.Typography.slnx -c ReleaseThen add a project reference to src/PinataLabs.Typography/PinataLabs.Typography.csproj, or create local packages with dotnet pack src/PinataLabs.Typography.Unicode -c Release and dotnet pack src/PinataLabs.Typography -c Release and install PinataLabs.Typography from that folder. PinataLabs.Typography depends on PinataLabs.Typography.Unicode, so the folder needs both packages.
using System.Globalization;
using PinataLabs.Typography;
FontDescription description = FontDescription.LoadDescription("path/to/font.ttf");
string name = description.FontName(CultureInfo.InvariantCulture);using PinataLabs.Typography;
FontCollection fonts = new();
FontFamily family = fonts.Add("path/to/font.ttf");
fonts.Add("path/to/other-font.woff2");
Font font = family.CreateFont(12);using PinataLabs.Typography;
if (SystemFonts.TryGet("Arial", out FontFamily arial))
{
Font font = arial.CreateFont(16);
}using PinataLabs.Typography;
TextOptions options = new(font);
FontRectangle size = TextMeasurer.MeasureSize("Hello, world!", options);using PinataLabs.Typography;
// The glyphs of the run, in visual order. The advances and offsets are in font design units, and each
// glyph has the UTF-16 index of its first character, so the "ffi" of "office" is one glyph at index 1.
ShapedGlyph[] glyphs = TextShaper.Shape(font, "office");dotnet build PinataLabs.Typography.slnx -c Release
dotnet test PinataLabs.Typography.slnx -c ReleaseThe tests run on net8.0, net10.0 and net11.0, so you must install those runtimes.
Read the contribution guide before you open an issue or a pull request. Report bugs and suggest changes in GitHub Issues. This project follows the Code of Conduct.
PinataLabs.Typography is licensed under the Apache License, Version 2.0.
This project is derived from SixLabors.Fonts, Copyright (c) Six Labors, licensed under the Apache License, Version 2.0. It was forked at commit 32bef429 and has been modified by PinataLabs. It also includes build files from SixLabors SharedInfrastructure. PinataLabs.Typography is not affiliated with or endorsed by Six Labors. See NOTICE for the full attribution.
