Skip to content

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

PinataLabs.Typography

A piñata donkey setting metal type on a letterpress, under the word Typography

License: Apache 2.0 Documentation

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.

Features

  • 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.

Requirements

  • The library targets net8.0, net10.0 and net11.0.
  • To build the repository, you must install the .NET 11 SDK, RC2 or later (11.0.100-rc.2). global.json pins this SDK. If it is not installed, dotnet build stops with an SDK-not-found error.

Install

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 Release

Then 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.

Quick start

Read a font description

using System.Globalization;
using PinataLabs.Typography;

FontDescription description = FontDescription.LoadDescription("path/to/font.ttf");
string name = description.FontName(CultureInfo.InvariantCulture);

Load fonts into a collection

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);

Use a system font

using PinataLabs.Typography;

if (SystemFonts.TryGet("Arial", out FontFamily arial))
{
    Font font = arial.CreateFont(16);
}

Measure text

using PinataLabs.Typography;

TextOptions options = new(font);
FontRectangle size = TextMeasurer.MeasureSize("Hello, world!", options);

Build and test

dotnet build PinataLabs.Typography.slnx -c Release
dotnet test PinataLabs.Typography.slnx -c Release

The tests run on net8.0, net10.0 and net11.0, so you must install those runtimes.

Contributing

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.

License and attribution

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.

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages