はじめに

Embedded OpenType (EOT) は、もともとウェブページに TrueType フォントを埋め込むために開発されたコンパクトなフォント形式です。EOT ファイルは TTF または OTF フォントを、フォントサイズ、バージョン、文字セット、埋め込み権限などを記述したメタデータフィールドを含む固定長ヘッダーでラップします。モダンなウェブ開発は主に WOFF/WOFF2 に移行していますが、EOT ファイルはレガシー文書やエンタープライズアプリケーションで依然として使用されています。

Aspose.Font FOSS for Python は、EotFont クラスとその companion EotHeader を通じて EOT フォントの内部に直接アクセスできるようにします。FontLoader.open を使用して EOT ファイルをロードし、ヘッダー フィールドを読み取り、内部の TtfFont を走査し、Font.save を使用して結果をバイト列またはファイルにシリアライズできます。ライブラリは PyPI に aspose-font として公開されており、MIT ライセンスの下でライセンスされています。 必須の商用依存関係はなく、標準の Python 3 ランタイムで動作します。


主な特徴

EOT フォントの読み込み

FontLoader.open を使用して、パスまたはバイトオブジェクトから EOT ファイルをロードします。メソッドは EOT シグネチャを検出したときに EotFont インスタンスを返します:

from aspose_font import FontLoader, EotFont

font = FontLoader.open("fonts/sample.eot")
assert isinstance(font, EotFont)

print(font.font_name)     # e.g. "Roboto"
print(font.font_family)   # e.g. "Roboto"
print(font.num_glyphs)    # number of glyphs in the inner font

FontLoader.open はファイル拡張子とヘッダーマジックを読み取り、フォーマットを自動的に検出します。一般的なフォントファイルでは font_type 引数は不要です。


EotHeader メタデータの読み取り

EotFont はヘッダー フィールドをクラスのプロパティとして直接公開します。これらは EOT バイナリ仕様で定義されたフィールドに対応しています:

from aspose_font import FontLoader, EotFont, EotSerializer

# Load EOT — FontLoader returns an EotFont instance for .eot files
loaded = FontLoader.open("fonts/sample.eot")

# Serialize back to bytes to confirm the font loaded correctly
eot_bytes = EotSerializer.serialize(loaded)
print(f"EOT data loaded: {len(eot_bytes)} bytes")

# Base Font properties work on any loaded font
print("Font name:", loaded.font_name)
print("Glyphs   :", loaded.num_glyphs)

EotFont クラスは以下のヘッダー メタデータをプロパティとして公開します:

  • eot_version (int) — EOT 形式バージョン(例: 0x00020002)
  • flags (int) — 埋め込み許可フラグ
  • charset (int) — 文字セット識別子(0 = ANSI、1 = DEFAULT)
  • italic (int) — イタリック フラグ(0 または 1)
  • weight (int) — フォントの太さ(例: Regular は 400、Bold は 700)
  • fs_type (int) — OS/2 fsType 埋め込みビット

flags と fs_type を使用して、フォントがサブセット化または埋め込みを許可しているかを判断します。これはフォントを再配布パイプラインで処理する際に関連します。

内部 TtfFont へのアクセス

すべての EotFont は標準的な TrueType フォントをラップしています。inner_font プロパティは TtfFont インスタンスを返し、完全な TrueType テーブルセットへのアクセスを提供します:

from aspose_font import FontLoader

loaded = FontLoader.open("fonts/sample.eot")

# Metrics are accessible directly from the loaded font
metrics = loaded.metrics
print("Units per em :", metrics.units_per_em)
print("Ascender     :", metrics.ascender)
print("Descender    :", metrics.descender)
print("Line gap     :", metrics.line_gap)

EotFont の inner_font プロパティはラップされた TtfFont インスタンスを返し、完全な TrueType テーブルセット、カーンペア、エンコーディングテーブルへのアクセスを提供します。


EOT をバイト列にシリアライズ

EotSerializer.serialize は任意の Font オブジェクトを生の EOT バイト文字列に変換します:

from aspose_font import FontLoader, EotFont, EotSerializer

font = FontLoader.open("fonts/sample.eot")
assert isinstance(font, EotFont)

eot_bytes = EotSerializer.serialize(font)
with open("output/sample_copy.eot", "wb") as fh:
    fh.write(eot_bytes)

print(f"Serialized {len(eot_bytes)} bytes")

TTF を EOT に変換

EotSerializer.serialize は任意の Font インスタンスを受け入れるため、TTF を読み込んで直接 EOT バイト列にシリアライズできます:

from aspose_font import FontLoader, EotFont, EotSerializer

ttf = FontLoader.open("fonts/Roboto-Regular.ttf")
eot_bytes = EotSerializer.serialize(ttf)

with open("output/Roboto-Regular.eot", "wb") as fh:
    fh.write(eot_bytes)

reloaded = FontLoader.open("output/Roboto-Regular.eot")
assert isinstance(reloaded, EotFont)
print("Converted and verified:", reloaded.font_name)

フォントメトリクスとカーニングペア

このEotFontはFontインターフェースを完全に継承しているため、メトリクスやエンコーディングはinner_fontを経由せずに直接利用できます:

from aspose_font import FontLoader

loaded = FontLoader.open("fonts/sample.eot")

metrics = loaded.metrics
print(f"Ascender : {metrics.ascender}")
print(f"Descender: {metrics.descender}")
print(f"Line gap : {metrics.line_gap}")
print(f"Underline: {metrics.underline_position}")

for pair in loaded.get_kern_pairs():
    print(f"  Kern: {pair}")

クイックスタート

ライブラリをインストールする:

.venv/bin/pip install aspose-font

EOT フォントを読み込み、検査する:

from aspose_font import FontLoader, EotFont, EotSerializer

loaded = FontLoader.open("sample.eot")

# Base font info
print(f"Font name : {loaded.font_name}")
print(f"Glyphs    : {loaded.num_glyphs}")

# Metrics
metrics = loaded.metrics
print(f"UPM       : {metrics.units_per_em}")
print(f"Ascender  : {metrics.ascender}")

# Serialize the loaded font back to EOT bytes
eot_bytes = EotSerializer.serialize(loaded)
print(f"Serialized: {len(eot_bytes)} bytes")

サポートされているフォーマット

形式拡張子読み取り書き込み
TTF.ttf✓—
OTF.otf✓—
EOT.eot✓—
CFF.cff✓—
TYPE1.pfb/.pfa✓—
WOFF.woff✓—
WOFF2.woff2✓—

上記のすべてのフォーマットはFontLoader.openを介して読み込みがサポートされています。特定のフォーマットへの書き込みは、EOT の場合はFont.saveまたはEotSerializer.serializeを使用します。


オープンソース & ライセンス

Aspose.Font FOSS for Python は MIT ライセンスの下でリリースされています。個人、商用、オープンソースのプロジェクトで無料で使用できます。ソースコードは GitHub で入手でき、パッケージは PyPI を通じて aspose-font として配布されています。


開始方法

関連リソース