フォントテーブルの検査

フォントテーブルの検査

フォントテーブルの検査

このガイドでは、名前付きテーブルプロパティの読み取り、未加工のバイナリテーブルデータの取得、そして変更されたテーブルバイトを TrueType フォントに書き戻す方法を示します。

TrueType と OpenType フォントはバイナリテーブルで構成されており、各テーブルは4バイトのタグで識別されます。TtfTableSet は一般的なテーブル向けに名前付き Python プロパティを公開し、TtfFont はすべてのテーブルに対して生バイトアクセスを提供します。


名前付きテーブルの読み取り

TtfTableSet は head、hhea、maxp、os2、name、post、cmap、loca、hmtx、そして kern テーブルを公開します。

from aspose_font import FontLoader
from aspose_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)

未加工テーブルバイトの読み取り

TtfFont.get_table_bytes(tag) は、4文字のタグで識別される任意のテーブルの完全なバイナリ内容を返し、低レベルの検査やカスタムパースを可能にします。

from aspose_font import FontLoader
from aspose_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")

修正されたテーブルバイトの書き込み

TtfFont.set_table_bytes(tag, data) はテーブルのバイナリコンテンツを置き換え、GSUB ルールのパッチ適用や name レコードの更新など、カスタムテーブルの変更を可能にします。

from aspose_font import FontLoader
from aspose_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)

ヒントとベストプラクティス

  • カーニングデータにアクセスする前に tables.kern is not None を確認してください
  • TtfTableSet.get_raw(tag) と set_raw(tag, data) は get_table_bytes / set_table_bytes のエイリアスです
  • 一貫性の問題を避けるため、テーブルを手動で削除するのではなく FontCleaner.clean_for_web() を使用してください

API Reference の概要

クラス / メソッド説明
TtfFont.ttf_tables名前付きテーブルプロパティにアクセス
TtfFont.get_table_bytes(tag)生バイナリテーブルデータを読み取る
TtfFont.set_table_bytes(tag, data)変更されたテーブルデータを書き込む
TtfTableSet.get_raw(tag)get_table_bytes のエイリアス
TtfTableSet.set_raw(tag, data)set_table_bytes のエイリアス

参照

 日本語