DXF text and AutoCAD SHX/BigFont support implemented with Rust and PyO3.
Project description
easy-font
easy-font is a PyO3/Rust Python extension focused on DXF text handling and
AutoCAD SHX font compatibility. It intentionally starts smaller than ezdxf:
the first milestone is reliable text/style extraction plus support for
AutoCAD-86 SHX unifont and bigfont files found in CAD datasets.
Development
nix-shell
maturin develop
pytest
Python API
import easy_font as cad
font = cad.open_shx("cad-data/fonts/hztxt.shx", encoding="gbk")
print(font.kind, font.is_bigfont, font.glyph_count)
doc = cad.readfile("cad-data/data/hatch.dxf")
for entity in doc.modelspace():
if entity.dxftype == "TEXT":
print(entity.text)
dwg = cad.readfile("cad-data/data/baseline-sample.dwg")
print(dwg.format, len(dwg.modelspace()))
# Resolve extracted text to local font files.
resolved_rows = cad.resolve_text_runs(dwg, ["cad-data/fonts"])
print(resolved_rows[0]["style"], resolved_rows[0]["font_path"])
Current scope
- Reads ASCII DXF group-code pairs.
- Reads DWG files using a handwritten Rust binary parser path.
- Extracts
STYLEtable records, including primary SHX font and BigFont file. - Extracts common text entities from
ENTITIES:TEXT,MTEXT,ATTRIB, andATTDEF. - Recognizes AutoCAD-86 SHX
unifontandbigfontheaders. - Preserves raw SHX glyph records so BigFont files that
ezdxfcannot load are still inspectable. - Decodes DXF text escapes such as
%%d,\P, and\U+4E2D. - Decodes encoded BigFont text bytes through Python codecs such as
gbk,big5, andshift_jis.
Full DXF entity parity with ezdxf is out of scope for this initial
implementation.
Font Resolution Workflow
python scripts/extract_and_resolve_fonts.py --input baseline-sample.dwg --limit 10
This script reads text entities from a drawing, resolves style fonts against
cad-data/fonts, and prints style/text font coverage.
For SHX fonts it verifies glyph coverage through open_shx; for TTF/OTF/TTC/WOFF
it verifies cmap coverage when fontTools is available.
To validate real render output for SFNT fonts (TTF/OTF/TTC/WOFF/WOFF2) and save PNG previews:
python scripts/validate_render_output.py --input baseline-sample.dwg --max-rows 200 --preview-limit 20
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cad_easy_font-0.1.0.tar.gz.
File metadata
- Download URL: cad_easy_font-0.1.0.tar.gz
- Upload date:
- Size: 26.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d042afb078d3a416044a37b1cd2101ce4d71748d4c2eb2471907f3c941a98da2
|
|
| MD5 |
fb361a0cca89ff46484a784ac81e5cb4
|
|
| BLAKE2b-256 |
40b7ac6716f17fb3259d18b5af5d6e5ac3d563ea6e322d8355edad6ad15a7b73
|
File details
Details for the file cad_easy_font-0.1.0-cp39-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: cad_easy_font-0.1.0-cp39-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 634.9 kB
- Tags: CPython 3.9+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1a28a030bd4991292425a73b1b4a936f67b15fd5b3a0608957c95895c3b5e15
|
|
| MD5 |
9e6c6fc464c9856312a7965090892545
|
|
| BLAKE2b-256 |
c955628d6f82df30d6fc4ed5188d212a43879b01ac07c4e50b793466f7ffad64
|