소개

Compact Font Format (CFF)는 PostScript 호환 아웃라인 엔진을 갖춘 OpenType 글꼴 내부에서 사용되는 바이너리 글리프 설명 형식입니다. Aspose.Font FOSS for Python는 CFF 데이터 구조를 읽고 검사하기 위해 aspose_font.cff 네임스페이스 아래에 전용 클래스 집합을 제공합니다: CffFont, CffCharset, CffEncoding, CffDict, CffIndex, 및 Type2Interpreter. 이 게시물에서는 라이브러리를 사용하여 CFF 글꼴을 로드하고, 내부 테이블을 탐색하며, charstring 프로그램을 해석하는 방법을 단계별로 살펴봅니다.

이 패키지는 MIT 라이선스를 사용합니다. 다음과 같이 설치하십시오:

pip install aspose-font-foss

주요 기능

CFF 글꼴 로드

FontLoader.open()는 CFF 형식을 자동으로 감지합니다 — 독립형 .cff 파일이나 CFF 아웃라인 테이블을 포함한 OTF 파일을 전달하십시오. 반환된 객체는 CffFont이며 (OTF 파일의 경우 TtfFont의 cff_font 속성을 통해 접근할 수 있습니다).

from aspose_font.loader import FontLoader

# Load a standalone CFF file
font = FontLoader.open("OpenSans.cff")

# Load a standalone CFF file (auto-detected from format)
font = FontLoader.open("OpenSans.cff")
print(font.font_name, font.num_glyphs)

CFF 문자 집합 — 글리프 ID를 이름에 매핑

CffCharset은(는) 글리프 ID(GID)를 PostScript 글리프 이름에 매핑합니다. 표준 ISO Adobe 문자 집합을 얻으려면 standard()을(를) 사용하고, 바이너리 CFF 데이터에서 문자 집합을 파싱하려면 from_reader()를 사용하십시오. name_for() 메서드는 GID에 대한 PostScript 이름을 반환하고, gid_for()는 역조회 를 수행합니다.

from aspose_font.cff.charset import CffCharset

charset = CffCharset.standard()
print(charset.name_for(1))    # ".notdef" or similar
print(charset.gid_for("A"))   # GID for the PostScript name "A"

CFF 인코딩 — Unicode에서 GID로 매핑

CffEncoding은(는) 문자 코드를 글리프 ID에 매핑하는 CFF 인코딩 테이블을 처리합니다. standard()은 표준 인코딩을 반환하고, expert()은 전문가 인코딩을 반환하며, from_reader()은 C CFF 바이너리 데이터에서 사용자 정의 인코딩을 파싱합니다. Unicode 코드 포인트로 GID를 조회하려면 unicode_to_gid()를 사용하고, 모든 매핑된 코드 포인트를 열거하려면 get_all_codepoints()를 사용하십시오.

from aspose_font.cff.encoding import CffEncoding

encoding = CffEncoding.standard()
gid = encoding.unicode_to_gid(0x41)  # Unicode for 'A'
all_codepoints = encoding.get_all_codepoints()
print(f"Standard encoding covers {len(all_codepoints)} code points")

CFF 사전 파싱

CFF 글꼴은 최상위 및 개인 메타데이터를 사전에 저장합니다. CffDict.from_bytes()은 원시 CFF DICT 블롭을 파싱하고 연산자 키를 통해 get() 및 set() 접근을 제공합니다. TopDict.from_dict()은 최상위 CFF 사전에 특화되어 있으며, PrivateDict.from_dict()는 개인 DICT에 대해 동일하게 동작합니다.

from aspose_font.cff.dict_ import CffDict

# Parse a raw CFF DICT from bytes
raw_dict_bytes = b"..."  # CFF-encoded DICT bytes
d = CffDict.from_bytes(raw_dict_bytes)
vals = d.get(21)  # retrieve values for operator 21 (PostScript CharstringType)

CFF 인덱스 구조

CffIndex은(는) charstrings, subrs, 이름 테이블에 사용되는 가변 길이 바이트 문자열의 길이 접두사 배열인 CFF INDEX 데이터 구조를 나타냅니다. from_reader()은 바이너리 리더에서 INDEX를 파싱하며, 결과는 정수 인덱스로 서브스크립트할 수 있습니다.

from aspose_font.cff.index import CffIndex
from aspose_font._io import BinaryReader  # internal API — may change between releases
import io

raw_index = b"..."  # raw CFF INDEX bytes
reader = BinaryReader(io.BytesIO(raw_index))
index = CffIndex.from_reader(reader)
print(f"INDEX entries: {len(index)}")

Type 2 Charstring 해석

Type2Interpreter는 Type 2 charstring 프로그램( CFF 글꼴에서 사용되는 압축된 PostScript-유사 형식)을 실행하고 윤곽 명령의 GlyphPath을 생성합니다. charstring 바이트와 연관된 private dictionary를 사용하여 interpret()를 호출하십시오. 이를 통해 전체 PostScript 인터프리터 없이 CFF charstring에서 원시 글리프 윤곽을 추출할 수 있습니다.

from aspose_font.cff.type2 import Type2Interpreter

interpreter = Type2Interpreter()
glyph_path = interpreter.interpret(charstring_bytes, private_dict)
for cmd in glyph_path.commands:
    print(type(cmd).__name__, cmd)

빠른 시작

pip install aspose-font-foss
from aspose_font.loader import FontLoader

# Load an OTF with embedded CFF outlines
font = FontLoader.open("OpenSans-Regular.otf")

glyph_id = font.encoding.unicode_to_gid(0x41)
glyph = font.glyph_accessor.get_glyph_by_id(glyph_id)
print(f"Path commands for 'A': {len(glyph.path.commands)}")

지원되는 형식

형식확장자읽기쓰기
CFF.cff✓✓
OTF.otf✓✓
TTF.ttf✓✓
WOFF.woff✓✓
WOFF2.woff2✓✓
EOT.eot✓✓
TYPE1.pfb / .pfa✓✓

오픈 소스 및 라이선스

Aspose.Font FOSS for Python은 MIT 라이선스를 갖습니다. 소스 코드는 GitHub에 있으며, aspose-font-foss/Aspose.Font-FOSS-for-Python에서 확인할 수 있습니다. aspose-font-foss으로 패키징되었습니다.


시작하기

관련 리소스