Extracting TrueType and OpenType font license restrictions with Java

When working with digital fonts in software applications, document generation engines, or web platforms, respecting font licensing restrictions is critical. Font vendors embed licensing and usage rules directly into font files to define how fonts can be embedded, installed, or modified. Using Aspose.Font for Java, developers can inspect embedded OS/2 table metrics and programmatically extract licensing restrictions from TrueType (.ttf) and OpenType (.otf) font files.

 

Understanding font licensing modes

TrueType and OpenType font specifications store embedding permissions in the fsType flag within the font’s OS/2 table. Aspose.Font for Java categorizes these embedded licensing restrictions into distinct modes via the LicenseFlags class:

  • Installable embedding: The font may be embedded and permanently installed on remote systems or for use by other users.
  • Editable embedding: The font may be embedded and temporarily loaded on other systems. Editing is permitted, including formatting new text using the embedded font, and changes may be saved.
  • Preview and print embedding: The font may be embedded and temporarily loaded on other systems strictly for viewing or printing the document.
  • Restricted license embedding: The font must not be modified, embedded, or exchanged in any manner without first obtaining explicit permission from the legal owner.

Extracting TTF license restrictions in Java

To read licensing permissions using Aspose.Font for Java:

  • Load the font file using FontFileDefinition and FontDefinition specifying FontType.TTF.
  • Retrieve the OS/2 table from the font’s table collection (getTtfTables().getOs2Table()).
  • Get license flags using getLicenseFlags().
  • Evaluate embedding rights using helper methods such as isEditableEmbedding(), isInstallableEmbedding(), isPreviewAndPrintEmbedding(), or isRestrictedLicenseEmbedding().

String fileName = Utils.getDataDir() + "Montserrat-Regular.ttf"; // Font file name with full path

FontDefinition fd = new FontDefinition(FontType.TTF, new FontFileDefinition("ttf", new FileSystemStreamSource(fileName)));
TtfFont font = (TtfFont) Font.open(fd);

LicenseFlags licenseFlags = null;
if (font.getTtfTables().getOs2Table() != null)
{
    licenseFlags = font.getTtfTables().getOs2Table().getLicenseFlags();
}

if (licenseFlags == null || licenseFlags.isFSTypeAbsent())
{
    System.out.println(MessageFormat.format("Font {0} has no embedded license restrictions", font.getFontName()));
}
else
{
    if (licenseFlags.isEditableEmbedding())
    {
        System.out.println(MessageFormat.format("Font {0} may be embedded, and may be temporarily loaded on other systems."
            + " In addition, editing is permitted, including ability to format new text"
            + " using the embedded font, and changes may be saved.", font.getFontName()));
    }
    else if (licenseFlags.isInstallableEmbedding())
    {
        System.out.println(MessageFormat.format("Font {0} may be embedded, and may be permanently installed"
            + " for use on a remote systems, or for use by other users.", font.getFontName()));
    }
    else if (licenseFlags.isPreviewAndPrintEmbedding())
    {
        System.out.println(MessageFormat.format("Font {0} may be embedded, and may be temporarily loaded"
            + " on other systems for purposes of viewing or printing the document.", font.getFontName()));
    }
    else if (licenseFlags.isRestrictedLicenseEmbedding())
    {
        System.out.println(MessageFormat.format("Font {0} must not be modified, embedded or exchanged in any manner"
            + " without first obtaining explicit permission of the legal owner.", font.getFontName()));
    }
}

Installation and Setup

Include Aspose.Font for Java in your project via Maven.

Package Manager Console Command

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository>

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-font</artifactId>
    <version>Latest</version>
</dependency>

FAQ

1. Do Type1 fonts support extracting licensing restrictions using LicenseFlags?

No. Standard Type1 font formats (.pfb/.pfa) do not contain an OS/2 table. The fsType flag and OS/2 table structure are specific to TrueType (.ttf) and OpenType (.otf) font formats.

2. What does it mean if licenseFlags.isFSTypeAbsent() returns true?

If isFSTypeAbsent() returns true (or if licenseFlags is null), it indicates that no embedded licensing restriction flags are present in the font file’s OS/2 table.

3. How do I check if a font permits editing document content?

You can check licenseFlags.isEditableEmbedding(). If true, the font permits temporary loading and editing, allowing users to format new text with the embedded font and save changes.