Aspose.Font FOSS สำหรับ Python เป็นชุดเครื่องมือ pure-Python สำหรับการโหลด, ตรวจสอบ, แปลง, ย่อยส่วน, และแสดงตัวอย่างฟอนต์ในรูปแบบ TrueType, OpenType, CFF, Type 1, WOFF, WOFF2, และ EOT ไลบรารีทำงานบน Python 3.10 หรือใหม่กว่าและไม่ต้องการไลบรารีฟอนต์ของ OS ภายนอกหรือการพึ่งพาเนทีฟ
ไลบรารีเปิดเผย API ที่สะอาดสำหรับการโหลดฟอนต์ผ่าน FontLoader, การเข้าถึง glyph ผ่าน GlyphAccessor, การแปลงรูปแบบผ่าน FontConverter, การเพิ่มประสิทธิภาพเว็บผ่าน FontCleaner, การย่อยส่วนที่รับรู้ข้อความผ่าน FontSubsetter, และการทำแอนิเมชันฟอนต์แบบตัวแปรผ่าน AnimationPreviewBuilder. เมตาดาต้าฟอนต์เช่น ชื่อ, ครอบครัว, สไตล์, จำนวน glyph, การเข้ารหัส, และเมตริก สามารถเข้าถึงได้ผ่านคลาสฐาน Font โดยไม่ต้องพาร์สตารางไบนารีด้วยตนเอง
Aspose.Font FOSS มีสัญญาอนุญาต MIT และสามารถติดตั้งจาก PyPI ด้วยคำสั่ง pip install เพียงคำสั่งเดียว. มันเหมาะสำหรับเครื่องมือออกแบบฟอนต์, pipeline ฟอนต์เว็บ, เอนจินการเรนเดอร์ 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, ClosePathGlyphKernPair เพื่อการคำนวณการจัดวางข้อความที่แม่นยำ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 หรือ OpenTyme font จากเส้นทางไฟล์และอ่านเมตาเดต้าพื้นฐานของมัน.
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
เป็นห้องสมุดไพธอนที่มีใบอนุญาต MIT ที่ฟรี สําหรับการอัตราบรรจุ, การตรวจสอบ, แปลงและการตั้งตัวแทนในรูปแบบ TTF, OTF , CFF, Type 1, WOFF , WOff2 และ EOT. ไม่จําเป็นต้องใช้ความขึ้นอยู่กับพื้นบ้าน.
Run 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() เขียน TFT, CFCF, WOFF และ WOFL2. Eot เป็นการอ่านเท่านั้น.
ไม่. Font.to_bytes() ไม่ได้ถูกนําไปใช้ในคลาสฐาน ใช้ FontConverter.convert() เพื่อผลิต Font ใหม่ ในรูปแบบที่ต้องการ
ใช่. FontSubsetter.subset_by_text(font, text) ส่งกลับใหม่ Font ซึ่งมีเพียง glyphs ที่จําเป็นสําหรับข้อความที่ให้.FontSubsetter.subset(font, codepoints) และ subset_by_gids(font, gids) ให้การควบคุมที่ดีกว่า.