Risoluzione dei problemi Aspose.Font FOSS for Python
Errori di importazione
ModuleNotFoundError: No module named 'aspose_font'
Il pacchetto non è installato nell’ambiente Python attivo. Installalo:
git clone https://github.com/aspose-font-foss/Aspose.Font-FOSS-for-Python.git
cd Aspose.Font-FOSS-for-Python
pip install -e .Assicurati di installare nell’ambiente virtuale corretto se ne usi uno.
ImportError: cannot import name 'FontType' from 'aspose_font'
FontType è esportato dal pacchetto di livello superiore aspose_font. Usa:
from aspose_font import FontType # correctSe vedi questo errore, conferma di avere aspose-font>=1.0.0 installato nel tuo ambiente attivo.
Errori di caricamento dei font
FontLoadException durante la chiamata a FontLoader.open()
Possibili cause:
- Il percorso del file è errato o il file non esiste
- Il file è corrotto o ha un’intestazione non standard
- Hai passato un oggetto bytes che non è un font valido
Verifica che il file esista prima di caricarlo:
import os
from aspose_font import FontLoader
path = "MyFont.ttf"
if not os.path.exists(path):
raise FileNotFoundError(path)
font = FontLoader.open(path)Problemi con il backslash nei percorsi Windows
Usa stringhe raw o slash (/) su Windows:
font = FontLoader.open(r"C:\Fonts\MyFont.ttf")
# or
font = FontLoader.open("C:/Fonts/MyFont.ttf")API Errori
AttributeError: 'Font' object has no attribute 'ttf_tables'
ttf_tables è una proprietà su TtfFont, non sulla classe base Font. Usa un’annotazione di tipo:
from aspose_font import TtfFont
ttf_font: TtfFont = FontLoader.open("MyFont.ttf")
tables = ttf_font.ttf_tablesNotImplementedError da Font.to_bytes()
Font.to_bytes(font_type) genera NotImplementedError solo quando viene chiamato sulla classe base astratta. Tutte le classi concrete di font (TtfFont, CffFont, WoffFont, Woff2Font, ecc.) implementano to_bytes() e restituiscono i byte del font. Se chiami FontLoader.open() ottieni un’istanza concreta — chiama to_bytes() direttamente, oppure usa FontConverter.convert() per cambiare formato prima:
from aspose_font.converter import FontConverter # internal API — may change between releases
from aspose_font import FontType
woff2 = FontConverter.convert(font, FontType.WOFF2)