Font Subsetting

What is font subsetting

Font subsetting is a process of taking specific characters from a font file. These characters though may be represented by a few glyphs. We will explain this moment further.

As it was told in the article about glyphs, font file includes as it called glyphsets. Their size varies dramatically and can be more than 5000 glyphs large. With subsetting you can create a file from only a few of them.

Why would you need to create a subset?

Let’s describe situations when subsetting would give you some benefit.

A simplified image of font subset

So the logo made in the subset of Dancing Script subset would look like this.

Logo from the glyphs of the generated subset

Subset web font

Web fonts consist of two important parts. They are characters (letters, numbers, punctuation) and Open Type features. The characters are placed in specific blocks relying on their functionality or language. Each of them has its own code(Unicode) mapped to a hex number. The Open Type features refer more to glyphs (variations of these characters).

Web font is one of the formats created especially for web projects, pages, sites, etc. It is aimed to make the text render properly in browsers and shorten page weight. You can learn more about WOFF and WOFF2 fonts from the article that tells about font formats.

Some also mention such terms as HTML font when talking about web fonts. This term refers to having one or more fallback options in case your font is not able to be rendered in some browser. HTML web font uses a web font installed on the user’s device as a fallback.

When talking about web fonts subsetting may have another advantages:

How to create a font subset with Aspose?

There are many ways to create a font subset. Some are programmatic ways, and some are just desktop or online applications.

Creating subsets with Aspose.Font for .NET

Aspose.Font provides a fully‑programmatic API that enables developers to generate deterministic font subsets with fine‑grained control over glyph preservation, font metadata, and output format. The workflow consists of three logical steps:

  1. Load the source font into an Font object.
  2. Define the Unicode code‑points (or explicit glyph IDs) that must be retained.
  3. Invoke the Subset operation with a FontSubsetOptions configuration and save the resulting font.

Below is a concise C# example that demonstrates how to create a minimal TTF subset containing only the characters required for the “Aspose” logo. The code is synchronous, uses the native Aspose.Font types, and can be adapted to other output formats such as WOFF or EOT by changing the FontSavingFormats enum.

 1using Aspose.Font;
 2using Aspose.Font.Ttf;
 3using System;
 4using System.Collections.Generic;
 5
 6class Program
 7{
 8    static void Main()
 9    {
10        // 1. Load the original font from disk.
11        using var sourceFont = Font.Load("Abel-Regular.ttf");
12
13        // 2. Define the exact Unicode characters needed for the logo.
14        //    This string can be built dynamically (e.g., from user input).
15        string logoText = "ASP OSE.FON T";
16
17        // Convert the characters into a set of Unicode code points.
18        var requiredCodePoints = new HashSet<int>();
19        foreach (char ch in logoText)
20        {
21            int cp = char.ConvertToUtf32(ch.ToString(), 0);
22            requiredCodePoints.Add(cp);
23        }
24
25        // 3. Configure subsetting options.
26        var subsetOptions = new FontSubsetOptions
27        {
28            // Preserve all glyphs that map to the supplied Unicode code points.
29            PreserveGlyphs = requiredCodePoints,
30            // Keep essential control glyphs (e.g., .notdef) to guarantee a valid font.
31            PreserveDefaultGlyphs = true,
32            // Optional: strip hinting tables to further reduce size.
33            RemoveHinting = true
34        };
35
36        // Execute the subsetting operation.
37        var subsetFont = sourceFont.Subset(subsetOptions);
38
39        // 4. Persist the subset font. Change the format if required.
40        subsetFont.Save("Abel-Regular.subset.ttf", FontSavingFormats.Ttf);
41
42        Console.WriteLine($"Subset created successfully. Size: {subsetFont.FileSize} bytes");
43    }
44}

Key points of the example

AspectExplanation
Font.LoadDetects the font type automatically (TTF, OTF, WOFF, etc.).
PreserveGlyphsGuarantees that every glyph required to render the specified Unicode characters is retained, including any composite glyph components.
PreserveDefaultGlyphsRetains mandatory glyphs (.notdef, .null, etc.) that are required for a well‑formed font file.
RemoveHintingStrips TrueType hinting tables, providing additional size savings when hinting is not needed.
FontSavingFormatsAllows output in any supported format (TTF, WOFF, WOFF2, EOT, etc.) without code changes.

By integrating this snippet into a build pipeline or an interactive tool, developers can automate the generation of highly optimized web‑font subsets, thereby reducing page‑load times and bandwidth consumption while preserving exact visual fidelity for the required characters.

Font subsetter cross-platform application

As an expert in managing fonts among the variety of different useful solutions Aspose.Font has also a cross-platform application that can help you to create a subset from your font.

The functionality is pretty simple. With it, you can combine glyphs of a few font files into a single one, or just make a much smaller, clearer file. You can pick out lower letters, numbers, punctuation, or type in the needed characters. It supports TTF, WOFF, EOT, CFF and Type 1 formats.

Let’s imagine we want to have our logo made of letters from the Abel Regular font. Its file is not that big, just 35 kb. and contains only 259 glyphs but yet we still want to make it as small as possible.

Picking needed characters from a font

After loading the font from the device or holder, it is possible to choose the needed characters. We need just 9 of them for our logo.

If needed there are a few buttons to make the process faster so you could choose upper or lower letters, numbers, mathematical symbols, or punctuation in one click.

Subsetting options of the application

In a moment you will be able to download the result. In our case, the generated font file is 2 kb.-large. So we’ve got the 15 times smaller file. Let’s compare the two documents using Viewer application

Comparison of two font files

As you may notice, the number of glyphs of the generated file is 10 and not 9 as we needed for our logo. The answer to this inconsistency is in the aforementioned thesis that one character may be represented by a few glyphs. So apparently one of the letters or the dot symbol has another variation of its look.

So that is obvious that with a much bigger file, you can get much more notable results. It somehow seems as useful as compressing the content(text files, images) with archives, but in comparison to compression, the quality of the characters of the subset does not change a bit.

Licensing limitations associated with font subsetting

When it comes to subsetting fonts, it is crucial to be aware of the licensing limitations associated with font usage. Font licensing terms may vary depending on the font foundry or designer. Let’s take a look at common considerations regarding licensing limitations when subsetting fonts:

The article here described one of the many applications for managing fonts. To see what else we can offer for such a purpose, go to Font Applications where you can find online converters, viewers, mergers, different generators, and many more.

Have any questions about Aspose.Font?



Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.