Aspose.Font FOSS for Python เป็นชุดเครื่องมือ pure-Python สำหรับการโหลด, ตรวจสอบ, แปลง, สร้าง subset, และแสดงตัวอย่างฟอนต์ที่รองรับรูปแบบ TrueType, OpenType, CFF, Type 1, WOFF, WOFF2, และ EOT. ไลบรารีทำงานบน Python 3.10 หรือใหม่กว่าและไม่ต้องการไลบรารีฟอนต์ของ OS ภายนอกหรือการพึ่งพาเนทีฟใดๆ.
ไลบรารีเปิดเผย API ที่สะอาดสำหรับการโหลดฟอนต์ผ่าน FontLoader, การเข้าถึง glyph ผ่าน GlyphAccessor, การแปลงรูปแบบผ่าน FontConverter, การเพิ่มประสิทธิภาพเว็บผ่าน FontCleaner, การทำ subset ที่รับรู้ข้อความผ่าน FontSubsetter, และการทำแอนิเมชันฟอนต์แบบตัวแปรผ่าน AnimationPreviewBuilder. เมตาดาต้าฟอนต์เช่น ชื่อ, ครอบครัว, สไตล์, จำนวน glyph, การเข้ารหัส, และเมตริก สามารถเข้าถึงได้ผ่านคลาสฐาน Font โดยไม่ต้องพาร์สตารางไบนารีด้วยตนเอง.
Aspose.Font FOSS มีสัญญาอนุญาตแบบ MIT และสามารถติดตั้งจาก PyPI ด้วยคำสั่ง pip install เพียงคำสั่งเดียว มันเหมาะสำหรับเครื่องมือออกแบบฟอนต์, กระบวนการฟอนต์บนเว็บ, เอนจินการเรนเดอร์ glyph, และแอปพลิเคชัน Python ใด ๆ ที่ต้องการอ่าน, แปลง, หรือสร้างไฟล์ฟอนต์ สำหรับตระกูลผลิตภัณฑ์ระดับองค์กร ดู Aspose.Font — Enterprise Product Family.
FontLoader.open() และ FontLoader.load()Font: font_name, font_family, font_style, num_glyphsFontEncoding.unicode_to_gid() และ get_all_codepoints()FontMetrics: ascent, descent, line gap, em-squareGlyphAccessor.get_glyph_by_id() และ get_glyph_by_unicode()GlyphAccessor.get_glyphs_for_text()MoveTo, LineTo, QuadraticTo, CurveTo, ClosePathGlyph propertiesKernPair เพื่อการคำนวณการจัดวางข้อความที่แม่นยำFontConverter.convert()CurveAdapter.quad_to_cubic() และ cubic_to_quads()convert_path_quad_to_cubic() และ convert_path_cubic_to_quad()FontSubsetter.subset_by_text()FontSubsetter.subset_by_gids()FontSubsetter.subset_for_web()FontSubsetter.subset_by_presets() และ available_presets()FontSubsetter.analyze_coverage() และ analyze_web_coverage()FontCleaner.clean_for_web()CompatibilityChecker.compare_fonts() และ compare_variable_instances()AnimationPreviewBuilder.build_axis_sweep()AnimationPreviewBuilder.build_path()เปิดแบบอักษร TrueType หรือ OpenType จากเส้นทางไฟล์และอ่านข้อมูลเมตาเบื้องต้นของมัน.
from aspose_font.loader import FontLoader
font = FontLoader.open("Roboto-Regular.ttf")
print(font.font_name) # e.g. "Roboto"
print(font.font_family) # e.g. "Roboto"
print(font.num_glyphs) # e.g. 1294
ดึง glyphs ทั้งหมดสำหรับจุดรหัส Unicode และตรวจสอบเส้นร่างของพวกมัน.
from aspose_font.loader import FontLoader
font = FontLoader.open("OpenSans-Regular.otf")
glyph_id = font.encoding.unicode_to_gid(0x41) # Unicode for A
glyph = font.glyph_accessor.get_glyph_by_id(glyph_id)
for cmd in glyph.path.commands:
print(type(cmd).__name__, cmd)
สร้าง 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")
ลบตารางเก่าและบันทึกชื่อ 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)
# DSIG, FFTM, meta tables removed; Mac platform name records stripped
เป็นไลบรารี pure-Python ฟรีที่มีสัญญาอนุญาต MIT สำหรับโหลด, ตรวจสอบ, แปลงและทำ subset ฟอนต์ในรูปแบบ TTF, OTF, CFF, Type 1, WOFF, WOFF2 และ EOT ไม่ต้องพึ่งพาไลบรารีเนทีฟใดๆ
เรียกใช้ pip install "aspose-font>=1.0.0". ไม่จำเป็นต้องมีการพึ่งพาระดับระบบใดๆ ไลบรารีทำงานบน Windows, macOS และ Linux พร้อมกับ Python 3.10 หรือใหม่กว่า
FontLoader.open() อ่าน TTF, OTF, CFF, Type 1, WOFF, WOFF2 และ EOT. FontConverter.convert() เขียน TTF, CFF, WOFF, และ WOFF2. EOT เป็นแบบอ่านอย่างเดียว
ไม่. Font.to_bytes() ยังไม่ได้ถูกนำไปใช้ในคลาสฐาน ใช้ FontConverter.convert() เพื่อสร้าง Font ใหม่ในรูปแบบที่ต้องการ
ใช่. FontSubsetter.subset_by_text(font, text) คืนค่า Font ใหม่ที่มีเฉพาะ glyph ที่จำเป็นสำหรับข้อความที่ระบุ FontSubsetter.subset(font, codepoints) และ subset_by_gids(font, gids) ให้การควบคุมที่ละเอียดขึ้น