글꼴 테이블 검사
폰트 테이블 검사
이 가이드는 명명된 테이블 속성을 읽고, 원시 바이너리 테이블 데이터를 가져오며, 수정된 테이블 바이트를 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)는 네 문자 태그로 식별되는 모든 테이블의 전체 바이너리 내용을 반환하여, 저수준 검사 또는 사용자 지정 파싱을 가능하게 합니다.
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")수정된 Table Bytes 쓰기
TtfFont.set_table_bytes(tag, data)은 테이블의 binary content를 대체하여, GSUB 규칙을 패치하거나 name 레코드를 업데이트하는 등 사용자 정의 table 수정을 가능하게 합니다.
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)팁 및 모범 사례
- 커닝 data에 접근하기 전에
tables.kern is not None을 확인하십시오 TtfTableSet.get_raw(tag)과set_raw(tag, data)은get_table_bytes/set_table_bytes의 별칭입니다.- 일관성 문제를 피하기 위해 tables를 수동으로 제거하는 대신
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에 대한 별칭 |