1. Products
  2.   Font
  3.   .NET
  4.   Fonts
 
  

Free C# .NET Library to Load, Read & Draw Fonts

Open Source C# .NET Library to Load, Read and Draw Various Types of Fonts such as TrueType, CFF, Woff, Woff2 and many more.

When it comes to working with fonts programmatically, Software developers often need robust tools and libraries to handle various font-related operations. One such powerful open-source library that has gained popularity among developers is SixLabors Fonts library. Fonts is a very useful open-source C# .NET library that provides a comprehensive set of functionalities for working with various types fonts inside C# applications. Developed by the Six Labors team, the Fonts library aims to simplify font handling tasks and make it easier for developers to work with typefaces programmatically. Whether users need to load, render, measure, or manipulate fonts, the Fonts library offers a clean and intuitive API for all these operations.

The open source Fonts library provides several features for font manipulation and customization, enabling software developers to create unique and visually appealing text elements within their applications. There are several important features part of the library, such as loading fonts from various sources (paths, streams, or embedded resources), high-quality glyph rendering capabilities, perform precise text layout and alignment, Unicode text handling, organize fonts into collections and many more.

The Fonts library is built on .NET Standard, making it compatible with multiple platforms and frameworks, including .NET Core, .NET Framework, Xamarin, and Mono. The library offers a simple and intuitive API, making it accessible for developers of all skill levels. Whether you are building a desktop application, a web service, or a mobile app, Fonts library provides a solid foundation for all your font management needs. So, give it a try and unlock the world of creative Fonts in your applications with open source Fonts library.

Previous Next

Getting Started with Fonts

The recommended way to install Fonts is using NuGet. Please use the following command a smooth installation.

Install Fonts via NuGet

 PM > Install-Package SixLabors.Fonts –PreRelease

You can also install it manually; download the latest release files directly from GitHub repository.

Load & Read Font Detail inside C# Apps

The open source Fonts library allows software developers to load various types of fonts and display its complete details inside C# applications. The library supports loading fonts from various sources, including file paths, streams, embedded resources and more. This flexibility allows developers to seamlessly integrate font loading into their applications. The library support working with TrueType fonts, OpenType fonts with with CFF1 outlines, Woff, Woff2 and so on. The following example shows how to read the description about TTF font using C# commands.

How to Read Font Description using C# API?

FontDescription description = null;

using(var fs = File.OpenRead("Font.ttf")){
    description = FontDescription.Load(fs); // once it has loaded the data the stream is no longer required and can be disposed of
}

string name = description.FontName(CultureInfo.InvariantCulture);

Font Collections Support via C#

The open source library Fonts allows software developers to organize fonts into collections, making it easier to manage and switch between different font families and styles. With just a couple of lines of code developers can create custom font collections. The library has also provided support for advanced OpenType features glyph substitution (GSUB) and glyph positioning (GPOS) as well. The following example shows how developers can work with font collections inside C# applications.

How to Work with sFont Collection via C# code?

using SixLabors.Fonts;

FontCollection collection = new();
collection.Add("path/to/font.ttf");
collection.Add("path/to/font2.ttf");
collection.Add("path/to/emojiFont.ttf");
collection.AddCollection("path/to/font.ttc");

if(collection.TryFind("Font Name", out FontFamily family))
if(collection.TryFind("Emoji Font Name", out FontFamily emojiFamily))
{
    // family will not be null here
    Font font = family.CreateFont(12, FontStyle.Italic);

    // TextOptions provides comprehensive customization options support
    TextOptions options = new(font)
    {
        // Will be used if a particular code point doesn't exist in the font passed into the constructor. (e.g. emoji)
        FallbackFontFamilies  = new [] { emojiFamily }
    };

    FontRectangle rect = TextMeasurer.Measure("Text to measure", options);
}