הכניסה
Aspose.Font FOSS for Python is a new open-source library that gives Python developers חבילת כלים מלאה לעבודה עם קבצי טקסט באופן תוכנה. TTF עבור בדיקת גליף, להפוך OTF ל- WOFF2 עבור משלוח אינטרנט, להגדיר טופס כדי להפחית את גודל העומס, או ליצור תמונות אנמיות של אסיות טופס משתנות, הספרייה מציג API מאוחדת, ללא תלות עבור כל המשימות האלה.
הספרייה פורסמה ב-PIPI כ aspose-font על פי רישיון MIT, יש צורך Python 3.10 או מאוחר יותר ואין תלות בספריות הפורטוגזיות ברמת ה- OS כגון: FreeType או HarfBuzz. זה עושה את זה מתאים היטב עבור סביבות שרתים ללא ראש, צינורות CI, וטעינה עבודה במכולת שבה התקנת טקסטים של המערכת היא בלתי מעשית.
Aspose.Font FOSS v1.0.0 supports loading fonts in TTF, OTF, CFF, Type 1, WOFF, WOFF2, ו- EOT פורמטים, עם יכולת ייצוא לאותו קבוצה של פורמט באמצעות FontConverter.
מה כולל
גישה למטא-דאו וגישה לנתונים
The FontLoader שיעור הוא נקודת הכניסה היחידה עבור טקסטים להעלות. FontLoader.open() עם מסלול קובץ או באטים ירוקים והספרייה תזהה את הפורמט באופן אוטומטי ו החזיר את האובייקט המתאים.אחרי שהטעינה, Font שיעור בסיס נותן לך גישה ל font_name, font_family, font_style, num_glyphs,וגם את המפה הקודמת.
from aspose_font.loader import FontLoader
font = FontLoader.open("Roboto-Regular.ttf")
print(font.font_name) # "Roboto"
print(font.font_family) # "Roboto"
print(font.num_glyphs) # number of glyphs in the font
Glyph Inspection and Path Access – בדיקת גישה וגישה
The GlyphAccessor שיעור מאפשר לך להסתכל על הגליפים באמצעות Glyph ID או Unicode Code Point דרך get_glyph_by_id() ו get_glyph_by_unicode().כדי לפתור את כל הגליפים עבור רצועה של שימוש בבת אחת, שימוש get_glyphs_for_text().כל אחד Glyph האובייקט מראה את מסלול היציאה שלו כאמור, יש להקפיד על סדרת דרכים – MoveTo, LineTo, QuadraticTo, CurveTo, ו ClosePath – לתת לך גישה לנתונים של Bézier ללא מנוע רנדרינג.
from aspose_font.loader import FontLoader
font = FontLoader.open("OpenSans-Regular.otf")
glyph_id = font.encoding.unicode_to_gid(0x41) # Unicode code point for 'A'
glyph = font.glyph_accessor.get_glyph_by_id(glyph_id)
for cmd in glyph.path.commands:
print(type(cmd).__name__, cmd)
תת-קובץ
FontSubsetter ישנן מספר אסטרטגיות של שימוש. subset_by_text() ל שמור רק את הגליפים הנדרשים עבור רצועה ספציפית, subset_by_gids() להגדיר את הגליף יש להציג את המודעות, או subset_for_web() להפעיל את ההגדרה המקדימה אופטימיזציה אינטרנט אשר נופל לעתים נדירות שימוש ב-Glyphs ו-Tables.The analyze_coverage() שיטת ההבדל מאפשרת לך לבדוק איזה אחוז מתוך האות המקורית, תת-סדרה מכסה לפני שהתחייבת לה.
from aspose_font.loader import FontLoader
from aspose_font.subsetter import FontSubsetter
font = FontLoader.open("NotoSans-Regular.ttf")
# Subset to the characters needed for a Latin-script page
result = FontSubsetter.subset_by_text(font, "Hello, World!")
אופטימיזציה Web Font Optimization
FontCleaner.clean_for_web() ה-DSIG, FFTM ו-Meta tables מוחלפים ומסירים את Mac. רשומות שמות הפלטפורמה מתוך לוח השם של האות.התוצאה היא בינארי קטן יותר זה מחזיק מהר יותר כמו טקסט אינטרנט ללא שינוי של מפות או גרפיקה.
from aspose_font.loader import FontLoader
from aspose_font.cleaner import FontCleaner
font = FontLoader.open("Roboto-Regular.ttf")
cleaned = FontCleaner.clean_for_web(font)
# stripped of legacy tables; ready for WOFF2 packaging
צילומי אנמיה משתנים
עבור מילים משתנות, AnimationPreviewBuilder ניתן ליצור APNG אנמיה אשר מתפשטת ערך אחד ממערך התחלה לערך הסופי. build_axis_sweep() שיטת קבלה תגית אסיס (לדוגמה,., "wdth" או "wght"• מספר מסגרת, מסגרות לשנייה ו- 1 דגל בונצ’ה אופציונלי שמפנה את הדופק כדי ליצור אנימציה קפיצה. הוא אחד AnimationAsset מי write_to() שיטת ההצלה מחזיקה את APNG לדיסק.
from aspose_font.loader import FontLoader
from aspose_font.animation import AnimationPreviewBuilder
font = FontLoader.open("Roboto-VariableFont_wdth,wght.ttf")
asset = AnimationPreviewBuilder.build_axis_sweep(
font,
axis_tag="wdth",
start_val=75.0,
end_val=100.0,
frames=3,
fps=10,
text="A",
size=10.0,
bounce=True,
)
asset.write_to("roboto-sweep-wdth.png")
מהיר התחלה
הקמת הספרייה מה-PyPI:
git clone https://github.com/aspose-font-foss/Aspose.Font-FOSS-for-Python.git
cd Aspose.Font-FOSS-for-Python
pip install -e .לאחר מכן, להעלות טופס ולבדוק את הנתונים המוטא-דוא"ל בכמה שורות:
from aspose_font.loader import FontLoader
font = FontLoader.open("MyFont.ttf")
print(f"Family: {font.font_family}")
print(f"Style: {font.font_style}")
print(f"Glyphs: {font.num_glyphs}")
# Look up a glyph by Unicode code point
glyph_id = font.encoding.unicode_to_gid(ord("A"))
glyph = font.glyph_accessor.get_glyph_by_id(glyph_id)
print(f"Path commands for 'A': {len(glyph.path.commands)}")
פורמט תומך
| פורמט | הרחבה | קראו | כתוב |
|---|---|---|---|
| TTF | .טטפ | ✓ | ✓ |
| OTF | .אוטו | ✓ | ✓ |
| CFF | .קפ | ✓ | ✓ |
| TYPE1 | .pf / . pfa | ✓ | ✓ |
| WOFF | .ווק | ✓ | ✓ |
| WOFF2 | .WOW2 | ✓ | ✓ |
| EOT | .EOT | ✓ | ✓ |
קוד פתוח & רישיון
Aspose.Font FOSS for Python is published under the MIT license. You can use it in פרויקטים מסחריים, לשנות אותו ולפצה אותו בחופשיות.הקוד המקור זמין על GitHub ב עקבו אחרי font font fox foxy foxi foxo fo החבילה זמינה ב-PyPI כ aspose-font.