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).
- Line breaking based on UAX #14.
- 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.
- The library targets
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 a local package with dotnet pack src/PinataLabs.Typography -c Release and install PinataLabs.Typography from that folder.
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);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.
