Skip to content

craft-dxf: R12 binary, more code pages, borrowing sections, exponent reals (ports of open CadCraft PRs) - #847

Merged
dylanmtaylor merged 8 commits into
mainfrom
port/dxf-app-prs
Nov 11, 2026
Merged

dylanmtaylor merged 8 commits into
mainfrom
port/dxf-app-prs

Conversation

@dylanmtaylor

Copy link
Copy Markdown
Member

What this is

Open CadCraft pull requests that change crates/dxf, the copy cadcraft#3040 deletes. This carries their DXF parts here, one commit per source PR, each with its original author.

What changed (crates/dxf)

Commit Source Change
ASCII reader unescapes only text with a backslash storytold/cadcraft#1833 by @mbolling (approved) Fewer copies on the per-group path. What is read is unchanged.
write_ascii_in_page storytold/cadcraft#2851 by @ffishman (approved) write_ascii_in without its fallback to pure ASCII, for a reader that decodes strictly by $DWGCODEPAGE. Additive.
Behaviour-preserving cleanups storytold/cadcraft#2571 by @AxylumRust (approved) Idioms and docs only.
R12 and earlier binary DXF storytold/cadcraft#1499 by @valentinevg812-eng The reader knew only the R13+ layout (2-byte codes). Pre-R13 files use 1-byte codes with 255 escaping a 2-byte code. The layout is told from the first tag. In R13+, 255 is now an ordinary code.
section_slices, record_slices, Tag::str_ref storytold/cadcraft#1708 by @MadsHolten Borrowing variants of sections and records, so a reader does not hold a large file's tags two or three times. sections and records now build their copies from these. Additive.
Exponent reals, string_groups storytold/cadcraft#1790 by @LastSkywalk format_real wrote f64::MAX as 309 digits. Values outside 1e-10..1e16 are written as 1.0E+20 and read back exactly. string_groups and MAX_STRING_CHARS split text into 250-character groups.
DOS and ISO 8859-15 code pages storytold/cadcraft#1271 by @vangel76 DOS720, 737, 775, 855, 857, 860, 861, 863, 864, 865, 869 and ISO8859_15 decoded as Windows-1252. New tables in dos_tables.rs, checked against the Unicode Consortium mapping files (noted in the file). DOS 864 % and U+FFFD are escaped on write, as the reviews there asked. Cheaper cstr, hex and unescape.
Korean Johab storytold/cadcraft#1911 by @francescoBV ANSI_1361 / JOHAB text and \M+4 escapes decode. Read only.

Where the ports differ from their sources

Not ported (left for a decision)

Behaviour changes

  • Pre-R13 binary DXF files now parse. An R13+ binary file with a group code 255 now reads it as code 255.
  • Text in the listed DOS code pages, ISO 8859-15 and Johab decodes correctly where it was read as Windows-1252.
  • format_real output for magnitudes outside 1e-10..1e16 changes form (same value).

Checks run

  • cargo test -p craft-dxf: 77 passed, 2 ignored (pre-existing ignores).
  • cargo clippy -p craft-dxf --all-targets -- -D warnings: clean.
  • cargo fmt --check -p craft-dxf: clean.

Checks not run

Workspace-wide tests. CadCraft's own io tests against this branch (cadcraft#3040 is the switch). No third-party R12 binary or Johab files; the tests build their inputs.

mbolling and others added 8 commits November 11, 2026 19:05
Only a string with a backslash can hold a \U+ or \M+ escape; every other
string moves into the tag as it is instead of being copied. The EOF check
reads the value before it moves.

Ported from storytold/cadcraft#1833.
… fallback

write_ascii_in falls back to pure ASCII when the code page bytes happen to
be valid UTF-8, for readers that guess UTF-8. A reader that decodes a
pre-2007 DXF strictly by its $DWGCODEPAGE needs the code page bytes.

Ported from storytold/cadcraft#2851.
Exact group-code mappings in one place, documented errors on the fallible
public parsers, and simpler option, result and formatting idioms. No change
to parsing, writing, numeric conversion, encoding or the public API.

Ported from storytold/cadcraft#2571.
Binary DXF written before R13 stores each group code in one byte, with 255
escaping a 2-byte code. The reader only knew the R13+ layout, where codes
are two bytes, and also treated 255 as an escape there. The layout is now
told from the first tag; 255 is an escape only in the 1-byte layout and an
ordinary code in R13+.

Ported from storytold/cadcraft#1499.
…ead of copying

sections() and records() copy every tag out of the parsed list, so a reader
that keeps the list holds a large file's tags two or three times. The new
functions return slices of the list. sections() and records() now build
their copies from them, so there is one implementation of each split.

Ported from storytold/cadcraft#1708. storytold/cadcraft#1588 solves the same
problem by changing Section itself; this keeps the existing API.
…orm; string_groups

format_real wrote f64::MAX as 309 digits. Values outside 1e-10..1e16 are now
written as AutoCAD writes them (1.0E+20) and read back exactly.
string_groups splits text into the 250-character groups long strings are
stored in (MAX_STRING_CHARS).

Ported from storytold/cadcraft#1790.
…59-15 code pages; cheaper unescape and hex

$DWGCODEPAGE values DOS720, 737, 775, 855, 857, 860, 861, 863, 864, 865, 869
and ISO8859_15 had no decoder and fell back to Windows-1252. ISO 8859-15
decodes through encoding_rs, the DOS pages through tables checked against
the Unicode Consortium mapping files (dos_tables.rs). DOS 864's byte 0x25 is
U+066A, so a writer escapes '%' there. U+FFFD is never written as a table
byte. A string without an escape moves into its tag without a copy, cstr
finds its terminator with one scan, and binary chunks are hex-encoded from a
table.

Ported from storytold/cadcraft#1271. Its group-code-255 change is carried by
the R12 binary port: the 1-byte layout is detected only when the escaped
code is one that needs the escape, so an R13+ file starting with code 255
still reads.
Johab had no decoder: files declaring ANSI_1361 were read as Windows-1252
and \M+4 escapes stayed literal. Hangul syllables are composed from the
three 5-bit jamo indices (KS X 1001 annex 3); symbols and Hanja map onto
KS X 1001 rows decoded as EUC-KR. Read only: a writer escapes instead.

Ported from storytold/cadcraft#1911 (its DOS code pages are covered by the
tables from storytold/cadcraft#1271).
@coderabbitai

coderabbitai Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4c6fe7c and e08c39e.

Files selected for processing: 10

  • crates/dxf/src/codepage.rs
  • crates/dxf/src/dos_tables.rs
  • crates/dxf/src/lib.rs
  • crates/dxf/src/version.rs
  • crates/dxf/tests/ascii_bom.rs
  • crates/dxf/tests/audit_followups.rs
  • crates/dxf/tests/code_page_write.rs
  • crates/dxf/tests/conformance.rs
  • crates/dxf/tests/hex_chunks.rs
  • crates/dxf/tests/roundtrip.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sonarqubecloud

Copy link
Copy Markdown

@dylanmtaylor
dylanmtaylor merged commit ebb40fa into main Nov 11, 2026
10 checks passed
mbolling added a commit to mbolling/cadcraft that referenced this pull request Nov 12, 2026
main now reads DXF through craft-dxf (storytold#3040) and no longer carries
crates/dxf, so this branch's change to that crate is dropped: it is in
craft-dxf already (storytold/craft-libs#847) and reaches cadcraft with the
next pin. The text helper in crates/io takes the renamed crate path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

7 participants