소개

Type 1은 Adobe의 원래 확장 가능한 글꼴 포맷으로, TrueType와 OpenType보다 먼저 등장했습니다. Type 1 글꼴은 두 개의 파일로 구성됩니다: 암호화된 글꼴 프로그램을 포함하는 .pfb (Printer Font Binary) 파일과, 커닝 및 메트릭 데이터가 들어 있는 .afm (Adobe 글꼴 메트릭) 파일입니다. OpenType에 의해 대체되었음에도 불구하고, Type 1 글꼴은 출판 워크플로, PostScript 파이프라인, 그리고 보관 문서에서 여전히 널리 사용됩니다.

Python용 Aspose.Font FOSS는 Type1Font, Type1FontData, Type1Serializer, Type1Interpreter을 통해 Type 1 내부에 직접 접근할 수 있게 합니다. FontLoader.open를 사용하여 PFB 또는 PFA 파일을 로드하고, 내장된 글꼴 프로그램 메타데이터를 검사하며, charstring을 글리프 경로로 해석하고, 글꼴을 PFB 또는 PFA 형식으로 다시 직렬화할 수 있습니다.

이 라이브러리는 PyPI에 aspose-font라는 이름으로 공개되었으며 MIT 라이선스를 따릅니다. 필수 상용 종속성이 없으며 표준 Python 3에서 실행됩니다.


주요 기능

Type 1 글꼴 로드

FontLoader.open를 사용하여 PFB 또는 PFA 파일을 로드합니다. 반환된 객체는 표준 Font 인터페이스와 Type1Font 클래스를 통한 Type 1 전용 기능을 모두 제공합니다:

from aspose_font import FontLoader

loaded = FontLoader.open("fonts/Courier.pfb")

print(loaded.font_name)    # e.g. "Courier"
print(loaded.font_family)  # e.g. "Courier"
print(loaded.num_glyphs)   # number of defined glyphs
print(loaded.font_style)   # style string, e.g. "Regular"

FontLoader.open은 파일 헤더에서 Type 1 형식을 자동으로 감지합니다. PFB와 PFA 파일 모두 지원됩니다.


AFM 메트릭 로드 중

Type 1 글꼴은 메트릭을 별도의 .afm 파일에 포함합니다. Type1Font 클래스는 load_afm(path) 메서드를 제공하여 AFM 데이터를 로드된 글꼴 객체에 연결하고, 이를 통해 get_kern_pairs()으로 커닝 페어를 조회할 수 있게 합니다.

AFM 파일이 없으면, get_kern_pairs()은 빈 리스트를 반환합니다. 커닝 데이터는 PFB 프로그램 자체가 아니라 AFM 파일에 저장되어 있기 때문입니다. load_afm 메서드는 동반 .afm 파일을 가리키는 파일 경로 문자열을 입력받습니다.


Type1FontData 메타데이터에 접근하기

Type1FontData 클래스는 Type 1 파일에 포함된 폰트 프로그램 사전을 노출합니다. 여기에는 메트릭, 경계 상자, 인코딩 벡터, charstrings, 서브루틴이 포함됩니다:

from aspose_font.type1.data import Type1FontData

# Type1FontData is the font program dictionary parsed from the PFB
# Access its properties to inspect the raw PostScript font data

Type1FontData 속성:

  • font_name (str) — PostScript 글꼴 이름
  • full_name (str) — 전체 사람이 읽을 수 있는 이름
  • family_name (str) — 글꼴 패밀리
  • weight (str) — 굵기 문자열 (예: "Medium")
  • italic_angle (float) — 이탤릭 각도 (도)
  • is_fixed_pitch (bool) — 고정폭 글꼴인 경우 true
  • font_bbox (tuple[int, int, int, int]) — 경계 상자 (llx, lly, urx, ury)
  • underline_position (int) — 글꼴 단위의 밑줄 위치
  • underline_thickness (int) — 밑줄 두께
  • encoding (list[str]) — 256-슬롯 인코딩 벡터 (PostScript 글리프 이름)
  • charstrings (dict[str, bytes]) — 글리프 이름 → charstring 바이트 매핑
  • subrs (list[bytes]) — charstring 엔진에서 사용되는 서브루틴 바이트 문자열
  • len_iv (int) — lenIV 암호화 매개변수

Charstrings 해석

Type1Interpreter은 Type 1 charstring 프로그램을 GlyphPath 윤곽선으로 디코드합니다. Type1FontData.charstrings에서 interpret으로 원시 charstring 바이트를 전달하십시오:

from aspose_font.type1.interpreter import Type1Interpreter

interpreter = Type1Interpreter()
charstring = b"\x0e"  # seac or other charstring bytes

glyph_path, stack_depth = interpreter.interpret(charstring)
for cmd in glyph_path.commands:
    print(cmd)

interpret은 (GlyphPath, int) 튜플을 반환합니다. GlyphPath에는 글리프 윤곽선에 대한 그리기 명령이 포함됩니다. 정수는 실행 후 최종 스택 깊이이며, 이는 손상된 charstring을 디버깅하는 데 유용합니다.


PFB 및 PFA 로 직렬화

Type1Serializer은 로드된 Type 1 글꼴을 바이너리 PFB 또는 텍스트 PFA 형식으로 다시 변환합니다. 두 메서드 모두 모든 Font 인스턴스를 받아 원시 바이트를 반환합니다:

from aspose_font import FontLoader
from aspose_font.type1.serializer import Type1Serializer

loaded = FontLoader.open("fonts/Courier.pfb")

# Serialize to PFB (binary) format
pfb_bytes = Type1Serializer.serialize_pfb(loaded)
with open("output/Courier_copy.pfb", "wb") as fh:
    fh.write(pfb_bytes)

# Serialize to PFA (text) format
pfa_bytes = Type1Serializer.serialize_pfa(loaded)
with open("output/Courier_copy.pfa", "wb") as fh:
    fh.write(pfa_bytes)

print(f"PFB: {len(pfb_bytes)} bytes")
print(f"PFA: {len(pfa_bytes)} bytes")

글꼴 메트릭

메트릭 및 인코딩은 표준 Font 인터페이스를 통해 접근할 수 있습니다:

from aspose_font import FontLoader

loaded = FontLoader.open("fonts/Courier.pfb")

metrics = loaded.metrics
print(f"Units per em  : {metrics.units_per_em}")
print(f"Ascender      : {metrics.ascender}")
print(f"Descender     : {metrics.descender}")
print(f"Underline pos : {metrics.underline_position}")
print(f"Underline tck : {metrics.underline_thickness}")

빠른 시작

라이브러리를 설치합니다:

.venv/bin/pip install aspose-font

PFB 글꼴을 로드하고 검사합니다:

from aspose_font import FontLoader
from aspose_font.type1.serializer import Type1Serializer

loaded = FontLoader.open("Courier.pfb")

print(f"Font name : {loaded.font_name}")
print(f"Family    : {loaded.font_family}")
print(f"Style     : {loaded.font_style}")
print(f"Glyphs    : {loaded.num_glyphs}")

metrics = loaded.metrics
print(f"UPM       : {metrics.units_per_em}")

# Round-trip: serialize back to PFB
pfb_bytes = Type1Serializer.serialize_pfb(loaded)
print(f"Serialized: {len(pfb_bytes)} bytes")

지원되는 형식

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

Type 1 글꼴은 FontLoader.open을 통해 로드되고 Type1Serializer을 통해 직렬화됩니다.


오픈 소스 및 라이선스

Aspose.Font FOSS for Python는 MIT 라이선스에 따라 공개됩니다. 개인, 상업 및 오픈 소스 프로젝트에서 비용 없이 사용할 수 있습니다. 소스 코드는 GitHub에서 제공되며, 패키지는 PyPI를 통해 aspose-font 형태로 배포됩니다.


시작하기

관련 리소스