Create TTF subset

.NET API Solution to generate TrueType font subset

 

Aspose.Font API Solution has a rich functionality to work with fonts. Conversion, manipulations with glyphs, detection of Latin symbols, and many more. Here we will explore font subsetting functionality.

Font subsetting is a powerful technique to optimize web performance and provide language-specific support while minimizing file size and loading time. With the increasing diversity of online content and the need to cater to multilingual audiences, font subsets offer a practical solution for web designers and developers. Let’s explore the benefits of subsetting fonts wider:

  • Including the entire character set of a font in a web page or application can result in large file sizes, leading to slower loading times and increased bandwidth usage. By creating font subsets, you can significantly reduce file sizes, to improve web performance and loading time.

  • Font subsets contain only the necessary characters required to render specific content. By excluding unused characters you make it easier to manage font files when using design tools. Font subsets also allow designers to have more control over the typography and visual identity of their web projects. With them, designers can ensure consistency and maintain the intended aesthetic of the project.

  • Different languages and scripts require specific sets of characters, accents, diacritics, and ligatures. So the tailored subset ensures that the necessary glyphs are included and the local page is rendered well.

  • Font subsets can be customized to include specific characters necessary to ensure that accessibility standards are met and make their web projects more inclusive.

So generating smaller font files gives you many benefits and there are several tools offered by Aspose. You can create a subset using cross-platform Font Generator or code everything yourself like on the C# example below that uses Aspose.Font API Solution.

To run the examples you need:

  • Aspose.Font for .NET API which is a feature-rich, powerful and easy-to-use document manipulation and conversion API for C# platform.

  • Open the NuGet package manager, and search for Aspose.Font and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Font

Steps to generate fonts using C#:

This code demonstrates how to use the IFontCharactersMerger interface to create a subset by merging specific glyphs from an original font into a new font and then saving the resulting font as a TTF file.

  1. Specify the input font.
  2. Create a subset made of desired glyphs using the IFontCharactersMerger.MergeFonts() Method.
  3. Save the resulting font using the Save() Method.

C# Code for creating subset

    using Aspose.Font.Ttf;
    using Aspose.Font.TtfHelpers;
    // Original font to take glyphs from
    TtfFont srcFont;

    //To create a font we use functionality of the IFontCharactersMerger interface.
    IFontCharactersMerger merger = HelpersFactory.GetFontCharactersMerger(srcFont, srcFont);

    TtfFont destFont = merger.MergeFonts(new uint[] { 'a', 'c', 'e' }, new uint[0], "TestFont");

    //Save resultant font
    destFont.Save("TestFont.ttf");



FAQ

1. What is a font subset?

A font subset refers to a smaller in comparison to the original font file that includes only the characters used in a particular document or web page, which can significantly reduce the file size of the document or webpage.

2. Can I create a font subset online?

Yes, there is a cross-platform Aspose Font Generator developed specifically for such a task.

3. How does subsetting functionality work in Aspose.Font?

In Aspose.Font subsetting functionality is realized through the merging functionality. It lets you create subsets from a few fonts or a single one.