Introduction
Type 1 เป็นรูปแบบตัวอักษรที่สามารถขยายได้ของ Adobe ที่ก่อนหน้า TrueType และ OpenTyme. แฟนต์แบบ 1 ประกอบด้วยไฟล์ 2 รายการ: a .pfb (Printer Font Binary) ไฟล์ที่มีตัวเลข โปรแกรมรหัสตัวอักษร และโปรแกนมุมที่ใช้การปรับเปลี่ยน .afm (Adobe Font Metrics) ไฟล์ที่มีการคอเรนก์และ ข้อมูลเมทริกส์ แม้จะถูกเปลี่ยนไปโดย OpenType, แฟนต์แบบ 1 ยังคงเป็นเรื่องปกติในประเทศไทยและอังกฤษ. การเผยแพร่กระบวนการทํางาน, หลักสูตร PostScript และเอกสารอาร์คิวิก.
Aspose.Font FOSS for Python provides direct access to Type 1 internals through Type1Font, Type1FontData, Type1Serializer,และ Type1Interpreter.คุณสามารถบรรทุก แฟลล์ PFB หรือ PFA ผ่านทาง FontLoader.open, ตรวจสอบเมตาข้อมูลโปรแกรมที่ติดตัวใน fonts, แปล charstrings เป็นทาง glyph และเรียงลําดับตัวอักษรกลับสู่รูปแบบ PFB หรือ PFA.
ห้องสมุดถูกประกาศใน PyPI เป็น aspose-font และได้รับอนุญาตภายใต้ลิซเซนส์ MIT. มันไม่มีการพึ่งพาณิชย์ที่จําเป็น และทํางานบน Python 3 มาตรฐาน.
คุณสมบัติหลัก
การอัตราบรรจุ Type 1 Font
การใช้งาน FontLoader.open เพื่ออัตราการโหลดไฟล์ PFB หรือ PFA. อุปกรณ์ที่กลับออกมาจะเปิดทั้ง PDF และ PPA ให้เห็นได้ชัดเจน สินค้าประจําตัว Font ช่องทางการใช้งานที่มีความสามารถในการทํางานของระบบประกอบด้วยเครื่องมือและไฟฟ้า Type1Font ประเภท:
from aspose_font import FontLoader
loaded = FontLoader.open("fonts/Courier.pfb")
print(loaded.font_name) # e.g. "Courier"
print(loaded.font_family) # e.g. "Courier"
print(loaded.num_glyphs) # number of defined glyphs
print(loaded.font_style) # style string, e.g. "Regular"
FontLoader.open พบรูปแบบ Type 1 โดยอัตโนมัติจากหัวไฟล์ PFB และ PFA ทั้งสองจะสนับสนุน.
การอัด AFM
แฟนต์แบบ 1 ส่งเมทริกส์ของพวกเขาในตัวที่แยก .afm รายการนี้ Type1Font ประเภท เปิดเผย a load_afm(path) วิธีที่เชื่อมข้อมูล AFM กับวัตถุตัวอักษรที่ถูกบรรจุ, การเปิดให้การค้นหาคู่เม็ดผ่าน get_kern_pairs().
โดยไม่มีไฟล์ AFM, get_kern_pairs() กลับรายการว่างเพราะข้อมูลคาร์นเป็นตัวจริง ในไฟล์ AFM ไม่ใช่ในโปรแกรม PFB ตัวเอง load_afm วิธีรับไฟล์ สายเส้นทางที่ชี้ไปที่เพื่อน .afm แฟ้ม.
การเข้าถึง Type1FontData เมตาเดท่า
การ Type1FontData class เปิดเผยวัสดุโปรแกรมตัวอักษรที่ติดอยู่ใน Type 1 แฟลล์ มันรวมเมทริกส์, กล่องขอบเขต, เวกเตอร์การโค้ด, ชาร์สไตรง และซับรูทีน:
from aspose_font.type1.data import Type1FontData
# Type1FontData is the font program dictionary parsed from the PFB
# Access its properties to inspect the raw PostScript font data
Type1FontData คุณสมบัติ:
font_name(str) ชื่อโพสต์กริ๊ปของตัวอักษรfull_name(str) ชื่อที่อ่านได้เต็มตัวfamily_name(str) ครอบครัวตัวอักษรweight(str) สายน้ําหนัก (เช่น."Medium")italic_angle(float) มุมอัดในองศาis_fixed_pitch(bool) ถูกต้องสําหรับตัวอักษรที่ใช้พื้นเดียวfont_bbox(tuple[int, int, int, int]) ตารางกําหนด(llx, lly, urx, ury)underline_position(int) สถานที่การลดราคาในหน่วยตัวอักษรunderline_thickness(int) ความหนาของเส้นลวดลายencoding(list[str]) วექტอร์การโค้ดสล็อต 256 (ชื่อ glyphs ของ PostScript)charstrings(dict[str, bytes]) ชื่อ glyph → การผนอไบต์ charstringsubrs(list[bytes]) สาย byte รอบการใช้โดยเครื่อง charstringlen_iv(int) ปารามีการรหัส lenIV
การตีความ Charstrings
Type1Interpreter การถอดรหัสโปรแกรม Charstring แบบ 1 เป็น GlyphPath ผืนเส้นทางผ่าน ไบท์ charstring แร่จาก Type1FontData.charstrings ไปยัง interpret:
from aspose_font.type1.interpreter import Type1Interpreter
interpreter = Type1Interpreter()
charstring = b"\x0e" # seac or other charstring bytes
glyph_path, stack_depth = interpreter.interpret(charstring)
for cmd in glyph_path.commands:
print(cmd)
interpret กลับ a (GlyphPath, int) หนองแคบ GlyphPath มีภาพวาด คําสั่งสําหรับการออกแบบ glyph. ตัวเลขเต็มคือความลึกของ stack สุดท้ายหลังจากการดําเนินงาน, ซึ่งเป็นประโยชน์ในการแก้ไขความผิดปกติ charstrings.
การจัดเรียงเป็น PFB และ PFA
Type1Serializer เปลี่ยนแปลงตัวอักษร Type 1 ที่ถูกบรรจุกลับเป็นรูปแบบ PFB หรือ PFA แบบคู่. ทั้งสองวิธีรับการใด ๆ Font ตัวอย่างและคืนไบท์ทรัพย์:
from aspose_font import FontLoader
from aspose_font.type1.serializer import Type1Serializer
# Serialize to PFB (binary) format
pfb_bytes = Type1Serializer.serialize_pfb(loaded)
with open("output/Courier_copy.pfb", "wb") as fh:
fh.write(pfb_bytes)
# Serialize to PFA (text) format
pfa_bytes = Type1Serializer.serialize_pfa(loaded)
with open("output/Courier_copy.pfa", "wb") as fh:
fh.write(pfa_bytes)
print(f"PFB: {len(pfb_bytes)} bytes")
print(f"PFA: {len(pfa_bytes)} bytes")
แฟนต์เมทริกส์
การวัดและการโค้ดสามารถเข้าถึงได้ผ่านมาตรฐาน Font ช่องทาง:
from aspose_font import FontLoader
metrics = loaded.metrics
print(f"Units per em : {metrics.units_per_em}")
print(f"Ascender : {metrics.ascender}")
print(f"Descender : {metrics.descender}")
print(f"Underline pos : {metrics.underline_position}")
print(f"Underline tck : {metrics.underline_thickness}")
เริ่มต้นอย่างรวดเร็ว
ติดตั้งห้องสมุด:
.venv/bin/pip install aspose-font
อัตราการอัด PFB และตรวจสอบมัน:
from aspose_font import FontLoader
from aspose_font.type1.serializer import Type1Serializer
loaded = FontLoader.open("Courier.pfb")
print(f"Font name : {loaded.font_name}")
print(f"Family : {loaded.font_family}")
print(f"Style : {loaded.font_style}")
print(f"Glyphs : {loaded.num_glyphs}")
metrics = loaded.metrics
print(f"UPM : {metrics.units_per_em}")
# Round-trip: serialize back to PFB
pfb_bytes = Type1Serializer.serialize_pfb(loaded)
print(f"Serialized: {len(pfb_bytes)} bytes")
รูปแบบที่สนับสนุน
| Format | Extension | Read | Write |
|---|---|---|---|
| TTF | .ttf | ✓ | — |
| OTF | .otf | ✓ | — |
| EOT | .eot | ✓ | — |
| CFF | .cff | ✓ | — |
| TYPE1 | .pfb/.pfa | ✓ | — |
| WOFF | .- โว๊ฟ | ✓ | — |
| WOFF2 | .woff2 | ✓ | — |
ไฟท์แบบ 1 ถูกอัดผ่าน FontLoader.open และถูกจัดเป็นซีเรียลผ่านทาง Type1Serializer.
หลักสูตรและใบอนุญาต
Aspose.Font FOSS for Python is released under the MIT License. You can use it in โครงการส่วนตัว, การค้า และโคร่งแหล่งเปิดโดยไม่มีค่าใช้จ่าย. เอกสารที่ออกมาจากคือ มีอยู่บน GitHub และแพ็คเกจถูกจําหน่ายผ่าน PyPI เป็น aspose-font.