Python에서 Type 1 글꼴을 작업하는 방법

Python에서 Type 1 글꼴을 작업하는 방법

PostScript Type 1은 TrueType와 OpenType 이전에 주된 전문 글꼴 형식이었습니다. Aspose.Font Python용 FOSS는 FontLoader.open()를 통해 자동 형식 감지를 사용하여 Type 1 글꼴 로드를 지원합니다.

단계별 가이드

1단계: 패키지 설치

git clone https://github.com/aspose-font-foss/Aspose.Font-FOSS-for-Python.git
cd Aspose.Font-FOSS-for-Python
pip install -e .

2단계: 필요한 클래스 가져오기

from aspose_font import FontLoader
from aspose_font.converter import FontConverter  # internal API — may change between releases
from aspose_font import FontType

3단계: Type 1 글꼴 로드

font = FontLoader.open("MyFont.pfb")
print(font.font_name)
print(font.num_glyphs)

단계 4: Type 1을 TTF로 변환

from aspose_font import FontLoader
from aspose_font.converter import FontConverter  # internal API — may change between releases
from aspose_font import FontType

font = FontLoader.open("MyFont.pfb")
ttf = FontConverter.convert(font, FontType.TTF)

단계 5: 글리프 윤곽선에 접근

from aspose_font import FontLoader

font = FontLoader.open("MyFont.pfb")
glyph = font.glyph_accessor.get_glyph_by_unicode(0x0041)  # 'A'
print(glyph.glyph_id)

일반적인 문제 및 해결책

폰트 로드 실패: .afm file — Type 1 폰트는 종종 쌍으로 제공됩니다 (.pfb + .afm). 파일을 .pfb 파일에 FontLoader.open(). 해당 .afm 메트릭 파일은 동일한 디렉터리에 존재하면 자동으로 읽힙니다.

변환 후 누락된 글리프 — 일부 Type 1 폰트는 비표준 인코딩 벡터를 사용합니다. 검사하십시오 font.encoding 변환하기 전에.

자주 묻는 질문

Type 1이 사용하는 파일 확장자는 무엇입니까?

가장 일반적인 확장자는 .pfb (binary)와 .pfa (ASCII)입니다. 두 가지 모두 지원됩니다.

Type 1을 WOFF2로 변환할 수 있나요?

예. FontConverter.convert(font, FontType.WOFF2)는 Type 1을 포함한 로드된 모든 Font와 함께 작동합니다.

참조

 한국어