הכניסה
פורמט טופס קומפקטי (CFF) הוא פורמנט תיאור גליף בינארי המשמש בתוך OpenType. טקסטים עם מנוע תצוגה תואם PostScript. Aspose.Font FOSS for Python exposes קבוצה של שיעורים מתחת ל- aspose_font.cff שם הספר לקריאה ו מבחן נתונים של CFF: CffFont, CffCharset, CffEncoding, CffDict, CffIndex, ו Type2Interpreter.הפוסט הזה עובר דרך איך להעלות את האותיות CFF, לחצו על הטבלאות הפנימיות שלהם, ולפרש תוכניות צ’רסטרינג באמצעות הספרייה.
החבילה מורשית על ידי MIT.התקנה עם pip install aspose-font>=1.0.0.
תכונות מרכזיות
להורדה של CFF Font
FontLoader.open() זיהוי פורמט CFF באופן אוטומטי – עובר או סטנדאולון .cff קובץ או קבץ OTF המכניס לוח תוצאות CFF.האובייקט החוזר הוא CffFont (הוא זמין דרך cff_font נכסים על TtfFont עבור קבצי OTF).
from aspose_font.loader import FontLoader
# Load a standalone CFF file
font = FontLoader.open("OpenSans.cff")
# Load a standalone CFF file (auto-detected from format)
font = FontLoader.open("OpenSans.cff")
print(font.font_name, font.num_glyphs)
CFF Charset – מפת זיהוי Glyph לשמות
CffCharset מפות GIF IDs (GIDs) ל PostScript GF שמות. standard() ל קבלו את הסטנדרט ISO Adobe Charget או from_reader() להוציא את הרכב מהבנקים נתונים של CFF - The name_for() שיטה מחזירה את שם PostScript עבור GID, ו gid_for() מבצעים את המבט הפוך.
from aspose_font.cff.charset import CffCharset
charset = CffCharset.standard()
print(charset.name_for(1)) # ".notdef" or similar
print(charset.gid_for("A")) # GID for the PostScript name "A"
CFF Encoding – Unicode-to-GID מפת
CffEncoding הוא מנהל את לוח הקוד CFF, אשר מפה קודים של דמויות ל- glyph IDs. standard() החזיר את הקוד הסטנדרטי, expert() החזיר את הקוד המומחה, ו from_reader() הפריסה של קוד מותאם אישית מתוך נתונים בינאריים CFF. unicode_to_gid() ל צפו ב-GID על ידי Unicode Code Point ו get_all_codepoints() להדפיס את כל המפות נקודות קוד.
from aspose_font.cff.encoding import CffEncoding
encoding = CffEncoding.standard()
gid = encoding.unicode_to_gid(0x41) # Unicode for 'A'
all_codepoints = encoding.get_all_codepoints()
print(f"Standard encoding covers {len(all_codepoints)} code points")
CFF מילון Parsing
CFF fonts מאחסנים נתונים מטא-דאו ברמה העליונה ופרטיים במילון. CffDict.from_bytes() פסיס את CFF DICT בלוב ירוק ומעניק לך get() ו set() גישה באמצעות מפתח מפעיל. TopDict.from_dict() זה מתמחה במילונים ברמה הגבוהה ביותר של CFF, ו PrivateDict.from_dict() אותו דבר גם לגבי דיקטים פרטיים.
from aspose_font.cff.dict_ import CffDict
# Parse a raw CFF DICT from bytes
raw_dict_bytes = b"..." # CFF-encoded DICT bytes
d = CffDict.from_bytes(raw_dict_bytes)
vals = d.get(21) # retrieve values for operator 21 (PostScript CharstringType)
CFF Index מבנה
CffIndex מייצג מבנה נתונים של CFF INDEX – סדרת משתנים ארוכה ומוגדרת. אורך ביט שורות בשימוש עבור צ’רסטרים, subrs, ו- שם טבלאות. from_reader() פרסים מדד מהקורא הבינארי והתוצאה מנוית על ידי מדס מלא.
from aspose_font.cff.index import CffIndex
from aspose_font._io import BinaryReader # internal API — may change between releases
import io
raw_index = b"..." # raw CFF INDEX bytes
reader = BinaryReader(io.BytesIO(raw_index))
index = CffIndex.from_reader(reader)
print(f"INDEX entries: {len(index)}")
סוג 2 - תרגום צ’ארסטרינג
Type2Interpreter מבצע תוכנית סוג 2 (הפוסטסריקט המסורתי) הפורמט המשמש בגרפיות CFF) ומייצר את GlyphPath פקודות מפתח - Call interpret() עם הוויטות האצ’ר והדיבור הפרטי הקשורים. מאפשר לך לחלץ את תוצרי הגליף הירוק מ CFF ללא כל תרגום PostScript.
from aspose_font.cff.type2 import Type2Interpreter
interpreter = Type2Interpreter()
glyph_path = interpreter.interpret(charstring_bytes, private_dict)
for cmd in glyph_path.commands:
print(type(cmd).__name__, cmd)
מהיר התחלה
pip install aspose-font>=1.0.0
from aspose_font.loader import FontLoader
# Load an OTF with embedded CFF outlines
font = FontLoader.open("OpenSans-Regular.otf")
glyph_id = font.encoding.unicode_to_gid(0x41)
glyph = font.glyph_accessor.get_glyph_by_id(glyph_id)
print(f"Path commands for 'A': {len(glyph.path.commands)}")
פורמט תומך
| פורמט | הרחבה | קראו | כתוב |
|---|---|---|---|
| CFF | .קפ | ✓ | ✓ |
| OTF | .אוטו | ✓ | ✓ |
| TTF | .טטפ | ✓ | ✓ |
| WOFF | .ווק | ✓ | ✓ |
| WOFF2 | .WOW2 | ✓ | ✓ |
| EOT | .EOT | ✓ | ✓ |
| TYPE1 | .pf / . pfa | ✓ | ✓ |
קוד פתוח & רישיון
Aspose.Font FOSS for Python is MIT licensed. Source code is on GitHub at עקבו אחרי font font fox foxy foxi foxo fo. הפעלת PyP כמו aspose-font.