Font Table Inspection

Font Table Inspection

TrueType and OpenType fonts are composed of binary tables, each identified by a 4-byte tag. TtfTableSet exposes named Python properties for common tables, and TtfFont provides raw byte access for all tables.


Reading Named Tables

TtfTableSet exposes head, hhea, maxp, os2, name, post, cmap, loca, hmtx, and kern tables.

from aspose_font.loader import FontLoader
from aspose_font.ttf.font import TtfFont

ttf_font: TtfFont = FontLoader.open("Roboto-Regular.ttf")
tables = ttf_font.ttf_tables

print("head table:", tables.head is not None)
print("kern table:", tables.kern is not None)

Reading Raw Table Bytes

from aspose_font.loader import FontLoader
from aspose_font.ttf.font import TtfFont

ttf_font: TtfFont = FontLoader.open("Roboto-Regular.ttf")
raw_name = ttf_font.get_table_bytes("name")
print(f"name table: {len(raw_name)} bytes")

Writing Modified Table Bytes

from aspose_font.loader import FontLoader
from aspose_font.ttf.font import TtfFont

ttf_font: TtfFont = FontLoader.open("Roboto-Regular.ttf")
modified_bytes = b"..."  # your modified table
ttf_font.set_table_bytes("GSUB", modified_bytes)

Tips and Best Practices

  • Check tables.kern is not None before accessing kerning data
  • TtfTableSet.get_raw(tag) and set_raw(tag, data) are aliases for get_table_bytes / set_table_bytes
  • Use FontCleaner.clean_for_web() rather than manually removing tables to avoid consistency issues

API Reference Summary

Class / MethodDescription
TtfFont.ttf_tablesAccess named table properties
TtfFont.get_table_bytes(tag)Read raw binary table data
TtfFont.set_table_bytes(tag, data)Write modified table data
TtfTableSet.get_raw(tag)Alias for get_table_bytes
TtfTableSet.set_raw(tag, data)Alias for set_table_bytes