Introduction
Font files are structured around tables — each table stores a specific category of data such as glyph outlines, character mappings, naming metadata, or horizontal metrics. Understanding and accessing these tables is essential for tasks like font analysis, metadata editing, quality assurance, and format conversion.
Aspose.Font FOSS for Python (aspose-font) gives you direct access to the full set of OpenType and TrueType tables through a clean Python API. The library is released under the MIT license with zero external dependencies, so you can integrate it into any project without licensing concerns.
This post walks through the key table classes available in the library — from reading header metadata to inspecting glyph data and modifying name records — all backed by the TtfTableSet container on TtfFont.
Key Features
Loading a Font and Accessing Tables
Every font loaded with FontLoader exposes its parsed tables through the ttf_tables property on TtfFont. The TtfTableSet object provides typed access to each standard table, plus raw bytes access via get_raw() for custom or unrecognized tables.
import aspose_font
font = aspose_font.FontLoader.open("MyFont.ttf")
tables = font.ttf_tables
# Typed table access
head = tables.head
name = tables.name
cmap = tables.cmap
# Raw bytes for any table tag
raw_os2 = tables.get_raw("OS/2")
Reading the Head Table
The HeadTable stores fundamental font-wide parameters: units per em, revision, bounding box, creation date, and style flags. These values are critical for rendering engines and font validators.
import aspose_font
font = aspose_font.FontLoader.open("MyFont.ttf")
head = font.ttf_tables.head
print(f"Units per em: {head.units_per_em}")
print(f"Revision: {head.font_revision}")
print(f"Bounding box: ({head.x_min}, {head.y_min}) to ({head.x_max}, {head.y_max})")
print(f"Mac style flags: {head.mac_style}")
print(f"Glyph data format: {head.glyph_data_format}")
Working with the Name Table
The NameTable holds all human-readable metadata: font family name, style, copyright, license, designer, and description. You can query records by name ID, retrieve localized names, or modify entries for rebranding.
import aspose_font
font = aspose_font.FontLoader.open("MyFont.ttf")
name_table = font.ttf_tables.name
# Read the font family name (name ID 1)
family = name_table.best_name(1, ["en"])
print(f"Family: {family}")
# List all localized versions of the full name (name ID 4)
localized = name_table.localized_names(4)
for lang, value in localized.items():
print(f" {lang}: {value}")
# Replace the font family name
name_table.replace_name(1, "MyCustomFamily")
Inspecting the CMap Table
The CmapTable maps Unicode codepoints to glyph IDs. It may contain multiple subtables for different platform and encoding combinations. Use best_subtable() to get the most suitable mapping for your use case.
import aspose_font
font = aspose_font.FontLoader.open("MyFont.ttf")
cmap = font.ttf_tables.cmap
# Get the best Unicode subtable
subtable = cmap.best_subtable()
print(f"Platform: {subtable.platform_id}, Encoding: {subtable.encoding_id}")
# Look up the glyph ID for 'A'
gid = subtable.get_gid(ord("A"))
print(f"Glyph ID for 'A': {gid}")
Reading OS/2 and Horizontal Metrics
The Os2Table provides OS/2 and Windows-specific metrics including typographic ascender/descender, embedding flags, and Panose classification. The HheaTable and HmtxTable supply horizontal layout metrics used for text shaping.
import aspose_font
font = aspose_font.FontLoader.open("MyFont.ttf")
os2 = font.ttf_tables.os2
hhea = font.ttf_tables.hhea
print(f"Typo ascender: {os2.s_typo_ascender}")
print(f"Typo descender: {os2.s_typo_descender}")
print(f"Embedding flags (fsType): {os2.fs_type}")
print(f"Panose: {os2.panose.hex()}")
print(f"Hhea ascender: {hhea.ascender}")
print(f"Max advance width: {hhea.advance_width_max}")
print(f"Number of hmetrics: {hhea.number_of_hmetrics}")
Kerning and Glyph Data
The KernTable stores kerning pairs for horizontal spacing adjustments. The GlyfTable contains the actual glyph outline data for TrueType fonts. You can also use PostTable to resolve glyph names.
import aspose_font
font = aspose_font.FontLoader.open("MyFont.ttf")
# Kerning lookup
kern = font.ttf_tables.kern
if kern:
pairs = kern.pairs
print(f"Total kern pairs: {len(pairs)}")
# Look up a specific pair by glyph IDs
adjustment = kern.get(36, 57)
print(f"Kern adjustment: {adjustment}")
# Glyph name from post table
post = font.ttf_tables.post
if post:
glyph_name = post.glyph_name(0)
print(f"Glyph 0 name: {glyph_name}")
Quick Start
pip install aspose-font>=1.0.0
import aspose_font
# Load any TTF or OTF font
font = aspose_font.FontLoader.open("MyFont.ttf")
tables = font.ttf_tables
# Print basic table info
print(f"Font: {font.font_name}")
print(f"Family: {font.font_family}")
print(f"Glyphs: {font.num_glyphs}")
print(f"Units/em: {tables.head.units_per_em}")
# Read name table entries
name_table = tables.name
for name_id in [0, 1, 2, 4, 5, 6]:
value = name_table.best_name(name_id, ["en"])
if value:
print(f" Name ID {name_id}: {value}")
# Check character coverage
cmap = tables.cmap
subtable = cmap.best_subtable()
for char in "ABCabc012":
gid = subtable.get_gid(ord(char))
print(f" '{char}' -> glyph {gid}")
Supported Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| TTF | .ttf | ✓ | ✓ |
| OTF | .otf | ✓ | ✓ |
| CFF | .cff | ✓ | ✓ |
| WOFF | .woff | ✓ | ✓ |
| WOFF2 | .woff2 | ✓ | ✓ |
| EOT | .eot | ✓ | — |
| TYPE1 | .pfb/.pfa | ✓ | — |
Open Source & Licensing
Aspose.Font FOSS for Python is released under the MIT license. The source code is available on GitHub and the package is published on PyPI as aspose-font. You are free to use, modify, and distribute it in both personal and commercial projects without restriction.