소개
Embedded OpenType (EOT) 은(는) 웹 페이지에 TrueType 폰트를 삽입하기 위해 원래 개발된 컴팩트한 폰트 형식입니다. EOT 파일은 TTF 또는 OTF 폰트를 고정 크기의 헤더로 감싸며, 이 헤더에는 폰트 크기, 버전, 문자집합, 삽입 권한을 설명하는 메타데이터 필드가 포함됩니다. 현대 웹 개발이 대부분 WOFF/WOFF2 로 전환되었지만, EOT 파일은 레거시 문서와 기업 애플리케이션에서 여전히 사용됩니다.
Aspose.Font FOSS for Python은(는) EotFont 클래스와 그 동반자인 EotHeader을 통해 EOT 폰트 내부에 직접 접근할 수 있게 합니다. FontLoader.open로 EOT 파일을 로드하고, 헤더 필드를 읽고, 내부 TtfFont를 탐색하며, 결과를 바이트로 또는 Font.save를 사용해 파일로 직렬화할 수 있습니다. 이 라이브러리는 PyPI에 aspose-font로 게시되었으며 MIT 라이선스 하에 제공됩니다. 필수적인 상업 의존성이 없으며 표준 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}")
빠른 시작
라이브러리를 설치합니다:
.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로 배포됩니다.