How to Work with Type 1 Fonts in Python

How to Work with Type 1 Fonts in Python

PostScript Type 1 was the dominant professional font format before TrueType and OpenType. Aspose.Font FOSS for Python supports loading Type 1 fonts via FontLoader.open() with automatic format detection.

Step-by-Step Guide

Step 1: Install the Package

pip install "aspose-font>=1.0.0"

Step 2: Import Required Classes

from aspose_font.loader import FontLoader
from aspose_font.converter import FontConverter
from aspose_font import FontType

Step 3: Load a Type 1 Font

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

Step 4: Convert Type 1 to TTF

from aspose_font.loader import FontLoader
from aspose_font.converter import FontConverter
from aspose_font import FontType

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

Step 5: Access Glyph Outlines

from aspose_font.loader import FontLoader

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

Common Issues and Fixes

Font fails to load with .afm file — Type 1 fonts often come in pairs (.pfb + .afm). Pass the .pfb file to FontLoader.open(). The .afm metrics file is read automatically if present in the same directory.

Missing glyphs after conversion — Some Type 1 fonts use non-standard encoding vectors. Inspect font.encoding before converting.

Frequently Asked Questions

What file extensions does Type 1 use?

The most common extensions are .pfb (binary) and .pfa (ASCII). Both are supported.

Can I convert Type 1 to WOFF2?

Yes. FontConverter.convert(font, FontType.WOFF2) works with any loaded Font including Type 1.

See Also