CFF 글꼴 작업

CFF 글꼴 작업하기

이 가이드는 Aspose.Font FOSS for Python를 사용하여 CFF 글꼴 내부 — 문자 집합, 인코딩 테이블, 사전 및 인덱스 구조 — 를 로드하고 검사하는 방법을 보여줍니다.

Compact Font Format (CFF) 글꼴은 글리프 윤곽을 Type 2 charstring 프로그램으로 저장합니다. Aspose.Font FOSS for Python는 aspose_font.cff 네임스페이스에 CFF 문자 집합, 인코딩 테이블, 사전 및 인덱스를 읽기 위한 전용 클래스를 제공합니다.


CFF 문자 집합

CffCharset는 글리프 ID를 PostScript 글리프 이름에 매핑합니다. 내장된 ISO Adobe 문자 집합을 얻으려면 CffCharset.standard()을 호출하고, 이후 name_for()와 gid_for()을 사용하여 글리프 ID와 이름 간을 변환합니다.

from aspose_font.cff import CffCharset

charset = CffCharset.standard()
name = charset.name_for(1)   # PostScript name for GID 1
gid  = charset.gid_for("A")  # GID for PostScript name "A"

CFF 인코딩

CffEncoding는 문자 코드를 글리프 ID에 매핑합니다. 표준 인코딩은 Adobe Latin 문자 집합을 포함합니다; 개별 코드 포인트를 조회하려면 unicode_to_gid()을 사용하고, 모든 매핑된 값을 나열하려면 get_all_codepoints()를 사용하십시오.

from aspose_font.cff import CffEncoding

enc = CffEncoding.standard()
gid = enc.unicode_to_gid(0x41)
codepoints = enc.get_all_codepoints()

CFF 사전 파싱

CffDict.from_bytes()는 원시 CFF DICT 블롭을 연산자 키 매핑으로 파싱합니다. 각 연산자 키는 기본 너비나 서브루틴 오프셋과 같은 글꼴을 구성하는 숫자 값 목록에 매핑됩니다.

from aspose_font.cff import CffDict

d = CffDict.from_bytes(raw_bytes)
vals = d.get(21)   # retrieve values for operator 21

CFF 인덱스

CffIndex.from_reader()는 바이너리 스트림에서 CFF INDEX 데이터 구조를 파싱합니다. INDEX 구조는 CFF 글꼴 내에서 이름 테이블, 문자열 테이블, 그리고 차스트링 저장에 사용되는 가변 길이 데이터 배열입니다.

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

reader = BinaryReader(io.BytesIO(raw_index_bytes))
index = CffIndex.from_reader(reader)
print(f"INDEX entries: {len(index)}")

Type 2 차스트링 해석

Type2Interpreter.interpret()는 Type 2 차스트링을 실행하고 GlyphPath를 반환합니다.

from aspose_font.cff import Type2Interpreter

interpreter = Type2Interpreter()
glyph_path = interpreter.interpret(charstring_bytes, private_dict)

팁 및 모범 사례

  • CffEncoding.standard()를 기본값으로 사용하고, 임베디드 인코딩의 경우 from_reader()로 재정의하십시오.
  • CffDict.to_bytes()는 수정된 사전을 다시 직렬화할 수 있게 합니다
  • Charstring 해석은 원시 글리프 윤곽 추출에만 필요합니다; GlyphAccessor는 더 높은 수준에서 대부분의 사용 사례를 포괄합니다

API Reference 요약

클래스 / 메서드설명
CffCharset.standard()표준 ISO Adobe 문자셋
CffCharset.name_for(gid)glyph ID에 대한 PostScript 이름
CffCharset.gid_for(name)PostScript 이름에 대한 Glyph ID
CffEncoding.standard()표준 CFF 인코딩 테이블
CffEncoding.unicode_to_gid(cp)코드 포인트를 GID에 매핑
CffDict.from_bytes(data)원시 CFF DICT 파싱
CffDict.get(operator)DICT 연산자에 대한 값을 가져옵니다
CffIndex.from_reader(reader)CFF INDEX 파싱
Type2Interpreter.interpret(cs, pd)Type 2 charstring을 실행하십시오

참조

 한국어