はじめに

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

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


主な特徴

EOTフォントの読み込み

パスまたはバイトオブジェクトからEOTファイルをロードするにはFontLoader.openを使用します。メソッドは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}")

クイックスタート

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

pip install aspose-font-foss

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 で入手可能で、aspose-font-foss としてパッケージ化されています。


はじめに

関連リソース