Skip to content

Fix SHX unifont code-7 subshape number endianness - #1482

Merged
mozman merged 1 commit into
mozman:masterfrom
1915rising:fix/1468-shx-unifont-endianness
Nov 22, 2026
Merged

mozman merged 1 commit into
mozman:masterfrom
1915rising:fix/1468-shx-unifont-endianness

Conversation

@1915rising

Copy link
Copy Markdown
Contributor

Fixes #1468.

parse_shape_codes() reads the unifont code-7 subshape number little-endian, but compiled unifont SHX files store it big-endian. Shape 0x80 in txt.shx has raw bytes 07 20 AC 00: the current parser produces subshape 0xAC20, which does not exist in the font, so glyphs defined as subshape references render empty; the big-endian reading 0x20AC exists. I checked 37 stock unifont files: 826 code-7 references, all 826 resolve big-endian and none little-endian. (This is compatible with the € rendering observation in the issue: a direct lookup of glyph 0x20AC never exercises the code-7 path.)

The fix uses the existing DataReader.u16_big() for unifont code 7 only; non-unifont parsing is unchanged.

Tests: tests/test_05_tools/test_533_shapefiles.py + test_515b_fonts_shapefiles.py — 34 passed / 18 skipped before, 37 passed / 18 skipped after (3 new regression tests, including an end-to-end shx_load of a constructed unifont file). Broader run (test_05_tools + render shape tests): 1490 passed, 29 skipped.

@mozman

mozman commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Please provide an example DXF which shows this issue.

Edit:

I expected such a test file:

image

BricsCAD:

image

@mozman
mozman merged commit ea22d86 into mozman:master Nov 22, 2026
12 checks passed
@1915rising

1915rising commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for merging, and sorry for the late reply to your question here.

The concrete example case: in the stock txt.shx and isocp.shx, shape 0x80 is defined as the bytes 07 20 AC 00, a code-7 subshape reference to shape 0x20AC (the € glyph). Before this fix, parse_shape_codes() read that two-byte number little-endian and produced 0xAC20, which doesn't exist in either font, so glyphs defined through a code-7 reference rendered as nothing. In isocp.shx alone there are 83 such references (the accented capitals 0xC0–0xCB reference their base letters this way); across the 37 unifont files I checked, all 826 code-7 references resolve big-endian and none little-endian.

A direct € in a TEXT entity doesn't show the bug, because that looks up shape 0x20AC directly instead of going through a code-7 reference, which is why the ISOCP test file rendered fine. A DXF that exercises it is one whose text uses a character mapped to a code-7-defined glyph, e.g. character 0x80 in a TXT/ISOCP style. The regression test added with this PR also builds a minimal unifont whose shape 0x80 is exactly 07 20 AC 00 referencing an existing 0x20AC glyph, if a small self-contained case is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SHX unifont: subshape number of code 7 is big-endian, parsed as little-endian

2 participants