From 533875ec97ab3e383a82ca12f163a7096623b82d Mon Sep 17 00:00:00 2001 From: simanov Date: Tue, 13 Oct 2026 14:43:53 +0300 Subject: [PATCH 1/5] DXF/DWG: read the vertical justification of ATTRIB and ATTDEF from group 74 Group 73 of an attribute is its field length; the vertical justification is group 74. The reader took 73 first, so attributes justified middle/centre (74 = 2) were placed by their baseline: numbers in a circle sat above its centre. Co-Authored-By: Claude Sonnet 5.5 --- crates/io/src/dxf_read.rs | 12 +++++++----- crates/io/tests/attrib_valign.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 crates/io/tests/attrib_valign.rs diff --git a/crates/io/src/dxf_read.rs b/crates/io/src/dxf_read.rs index 7615bc569c..bfd80ab30f 100644 --- a/crates/io/src/dxf_read.rs +++ b/crates/io/src/dxf_read.rs @@ -178,7 +178,9 @@ fn mtext_from(tags: &[Tag], c: &Common) -> MText { } } -fn text_from(t: &T) -> Text { +/// A TEXT, or with `attrib` an ATTRIB / ATTDEF (whose group 73 is the field length: their vertical +/// justification is group 74). +fn text_from(t: &T, attrib: bool) -> Text { let h = match t.i(72).unwrap_or(0) { 1 => HAlign::Center, 2 => HAlign::Right, @@ -187,7 +189,7 @@ fn text_from(t: &T) -> Text { 5 => HAlign::Fit, _ => HAlign::Left, }; - let v = match t.i(73).or_else(|| t.i(74)).unwrap_or(0) { + let v = match t.i(if attrib { 74 } else { 73 }).unwrap_or(0) { 1 => VAlign::Bottom, 2 => VAlign::Middle, 3 => VAlign::Top, @@ -365,14 +367,14 @@ fn entity(kind: &str, tags: &[Tag]) -> Option<(Common, EntityKind)> { "HELIX" => EntityKind::Helix(helix(tags)), "RAY" => EntityKind::Ray(RayLine { base: t.p(10), dir: t.p(11) }), "XLINE" => EntityKind::XLine(RayLine { base: t.p(10), dir: t.p(11) }), - "TEXT" => EntityKind::Text(text_from(&t)), + "TEXT" => EntityKind::Text(text_from(&t, false)), "MTEXT" => EntityKind::MText(mtext_from(tags, &c)), "ATTDEF" => { // A multiline definition has its text as embedded MTEXT after its own groups. let (own, embedded) = split_embedded(tags); let multiline = multiline_attrib(embedded, &c); let own = T(own); - let mut text = text_from(&own); + let mut text = text_from(&own, true); if let Some(m) = &multiline { text.value.clone_from(&m.read_as); } @@ -1181,7 +1183,7 @@ fn parse_entities(recs: &[(String, Vec)], d: &mut Drawing, rx: &mut Rx, ski let (own, embedded) = split_embedded(t2); let multiline = multiline_attrib(embedded, &common(&tt)); let own = T(own); - let mut text = text_from(&own); + let mut text = text_from(&own, true); if let Some(m) = &multiline { text.value.clone_from(&m.read_as); } diff --git a/crates/io/tests/attrib_valign.rs b/crates/io/tests/attrib_valign.rs new file mode 100644 index 0000000000..39e83b2b9f --- /dev/null +++ b/crates/io/tests/attrib_valign.rs @@ -0,0 +1,32 @@ +//! ATTRIB and ATTDEF keep their vertical justification in group 74 (group 73 is the field length). + +use cadcraft_doc::{EntityKind, VAlign}; + +fn attrib(kind: &str) -> String { + format!(" 0\n{kind}\n 8\n0\n 10\n1\n 20\n1\n 30\n0\n 40\n1.4\n 1\n3\n 2\nVAL\n 70\n0\n 72\n1\n 11\n1\n 21\n1\n 31\n0\n 73\n0\n 74\n2\n") +} + +#[test] +fn attribute_vertical_justification_is_group_74() { + let dxf = format!( + " 0\nSECTION\n 2\nENTITIES\n{} 0\nINSERT\n 8\n0\n 2\nB\n 66\n1\n 10\n0\n 20\n0\n 30\n0\n{} 0\nSEQEND\n 0\nENDSEC\n 0\nEOF\n", + attrib("ATTDEF"), + attrib("ATTRIB") + ); + let d = cadcraft_io::read_dxf(dxf.as_bytes()).unwrap(); + let mut seen = 0; + for e in d.model.iter() { + match &e.kind { + EntityKind::AttDef(a) => { + assert_eq!(a.text.valign, VAlign::Middle); + seen += 1; + } + EntityKind::Insert(i) => { + assert_eq!(i.attribs.first().map(|a| a.text.valign), Some(VAlign::Middle)); + seen += 1; + } + _ => {} + } + } + assert_eq!(seen, 2); +} From a2dd814688893873281870ac7b49c143fc8bdb2c Mon Sep 17 00:00:00 2001 From: 2ez4gcx <108074836+2ez4gcx@users.noreply.github.com> Date: Mon, 26 Oct 2026 12:33:15 +0700 Subject: [PATCH 2/5] xtask: the test suite and clippy pass on Windows Two Windows-only failures stopped `cargo xtask ci` before it got going on a Windows checkout (CI runs the gate on Linux only, so neither showed): - parity::tests::civil_dates built a SystemTime 115,740,740 days after the epoch (year 318857). Windows' SystemTime ends in the year 30828, so the addition panicked ("overflow when adding duration to `SystemTime`"). That case now checks `civil_from_days` on the day count, which is what it was about, on every platform. - stats.rs imported `walk` for a test that only exists on Unix, so the import was unused on Windows and `clippy -D warnings` refused it. The Unix test calls `super::walk`, as its neighbour calls `super::walk_inner`. Checked on Windows 11 x64: `cargo test --workspace` and `cargo clippy --workspace --all-targets -- -D warnings` both pass. Co-Authored-By: Claude Opus 5.5 --- xtask/src/parity.rs | 4 +++- xtask/src/stats.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/xtask/src/parity.rs b/xtask/src/parity.rs index 39f8e8713b..8c174d2903 100644 --- a/xtask/src/parity.rs +++ b/xtask/src/parity.rs @@ -136,7 +136,9 @@ mod tests { assert_eq!(day(20_736), "2026-10-10"); assert_eq!(date(std::time::UNIX_EPOCH - std::time::Duration::from_secs(86_400)), "1970-01-01"); // Past chrono's range keeps the proleptic Gregorian date, not the epoch (old `civil_from_days`). - assert_eq!(day(115_740_740), "318857-05-20"); + // Checked on the day count: Windows' SystemTime ends in the year 30828, so building that + // SystemTime panics there. + assert_eq!(civil_from_days(115_740_740), (318_857, 5, 20)); // Windows' SystemTime can't hold u64::MAX / 2 seconds, so it is only checked where it exists. if let Some(far) = std::time::UNIX_EPOCH.checked_add(std::time::Duration::from_secs(u64::MAX / 2)) { assert_eq!(date(far), "292277026596-12-04"); diff --git a/xtask/src/stats.rs b/xtask/src/stats.rs index c2c6de3d25..6136de15ac 100644 --- a/xtask/src/stats.rs +++ b/xtask/src/stats.rs @@ -134,7 +134,7 @@ pub fn run(_root: &Path, exact: bool) -> Result<(), String> { #[cfg(test)] mod tests { - use super::{Counts, count_tests, walk}; + use super::{Counts, count_tests}; #[test] fn counts_attributes_and_proptest_blocks() { @@ -155,7 +155,7 @@ mod tests { // A directory symlink pointing back at `real` would be re-scanned if followed. symlink(&real, base.join("alias")).unwrap(); let mut c = Counts::default(); - walk(&base, &mut c).unwrap(); + super::walk(&base, &mut c).unwrap(); assert_eq!(c.files, 1, "the aliased directory was followed and counted twice"); std::fs::remove_dir_all(&base).ok(); } From 79e8ac5b56e9f8c859b31a163e637ffa0b6bd626 Mon Sep 17 00:00:00 2001 From: smacdmac101 Date: Mon, 26 Oct 2026 13:04:30 -0400 Subject: [PATCH 3/5] test(io): expand attribute justification round-trip matrix CC-003: add 180 synthetic import/save/reopen combinations, including missing vertical codes and nonzero field lengths, on existing #910. Reproduced Baseline instead of Bottom on current upstream; matrix and all seven CI gates pass with #910 plus #2198. No new reader implementation. Revert this test/documentation commit independently; retain both prerequisites. Browser bundle validation remains pending before PR submission. --- .../tests/it/attribute_vertical_alignment.rs | 44 +++++++++++++++++++ crates/io/tests/it/main.rs | 1 + docs/file-format-parity.md | 14 +++++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 crates/io/tests/it/attribute_vertical_alignment.rs diff --git a/crates/io/tests/it/attribute_vertical_alignment.rs b/crates/io/tests/it/attribute_vertical_alignment.rs new file mode 100644 index 0000000000..c09e770c41 --- /dev/null +++ b/crates/io/tests/it/attribute_vertical_alignment.rs @@ -0,0 +1,44 @@ +//! Attribute group 73 is field length, whereas TEXT uses it for vertical alignment. +use cadcraft_doc::{EntityKind, HAlign, VAlign}; +use cadcraft_io::{read_dxf, write_dxf}; + +#[test] +fn imported_attributes_use_group_74_and_keep_the_alignment_point() { + for kind in ["ATTRIB", "ATTDEF", "TEXT"] { + for (horizontal, expected_h) in [(0, HAlign::Left), (1, HAlign::Center), (2, HAlign::Right)] { + for field_length in [0, 1, 3, 80] { + for vertical in [None, Some(0), Some(1), Some(2), Some(3)] { + let v = vertical.map_or(String::new(), |v| format!("74\n{v}\n")); + let prefix = if kind == "ATTRIB" { "0\nINSERT\n2\nTEST\n66\n1\n" } else { "" }; + let suffix = if kind == "ATTRIB" { "0\nSEQEND\n" } else { "" }; + let source = format!( + "0\nSECTION\n2\nENTITIES\n{prefix}0\n{kind}\n10\n1\n20\n2\n40\n1\n1\nValue\n2\nTAG\n72\n{horizontal}\n73\n{field_length}\n{v}11\n7\n21\n9\n{suffix}0\nENDSEC\n0\nEOF\n" + ); + let drawing = read_dxf(source.as_bytes()).expect("import synthetic DXF"); + let expected = match if kind == "TEXT" { field_length } else { vertical.unwrap_or(0) } { + 1 => VAlign::Bottom, + 2 => VAlign::Middle, + 3 => VAlign::Top, + _ => VAlign::Baseline, + }; + for d in [&drawing, &read_dxf(write_dxf(&drawing).as_bytes()).expect("reopen")] { + let entity = d.model.iter().next().expect("entity"); + let text = match &entity.kind { + EntityKind::Insert(i) => &i.attribs.first().expect("attribute").text, + EntityKind::AttDef(a) => &a.text, + EntityKind::Text(t) => t, + other => panic!("unexpected {other:?}"), + }; + assert_eq!(text.valign, expected, "{kind} 73={field_length} 74={vertical:?}"); + assert_eq!(text.halign, expected_h); + assert_eq!( + text.align_pt.map(|p| (p.x, p.y, p.z)), + (horizontal != 0 || expected != VAlign::Baseline).then_some((7.0, 9.0, 0.0)) + ); + assert_eq!(text.value, "Value"); + } + } + } + } + } +} diff --git a/crates/io/tests/it/main.rs b/crates/io/tests/it/main.rs index 51e7f1965e..af8d4d0be1 100644 --- a/crates/io/tests/it/main.rs +++ b/crates/io/tests/it/main.rs @@ -6,6 +6,7 @@ mod annotative_roundtrip; mod assoc_array_roundtrip; mod attrib_modes; mod attrib_props; +mod attribute_vertical_alignment; mod block_expansion; mod closed_spline; mod codepages; diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 6c852ba76f..dcbf9bf05f 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -1,6 +1,6 @@ # File-format parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-22 · **Change:** minor (DIMASSOC objects for angular, diametric and radial dimensions) · **Target:** Autodesk AutoCAD 2027 +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-26 · **Change:** minor (attribute alignment regression matrix) · **Target:** Autodesk AutoCAD 2027 Every format AutoCAD 2027 reads or writes, with CADCraft's support, fidelity and tests. Work items are in [gaps.md](gaps.md#file-formats); the weighted score feeds @@ -136,10 +136,22 @@ external validator runs in CI (ezdxf's audit was run by hand once, 2026-10-06). a licensed real-file corpus with an open → save → re-open → compare test per file, and checking our output in AutoCAD black-box. +## Attribute alignment regression coverage + +CC-003 adds 180 synthetic TEXT/ATTRIB/ATTDEF combinations across left/center/right alignment, +field lengths 0/1/3/80 and missing or explicit vertical justification 0–3. Each combination is +checked after import and DXF save/reopen, including the retained alignment point and value. +The reader implementation is the existing #910 proposal; this contribution adds coverage only. +It reproduced ATTRIB group 73=0 / 74=1 being read as Baseline instead of Bottom on d3ae8a6, +and passes with #910 adapted to the current extracted reader helpers. No private or +AutoCAD-produced drawing is included. This does not establish full drawing fidelity or cover +multiline subclass collisions (the separate #1942 proposal). + ## Revision history | Date | Change | Summary | |---|---|---| +| 2026-10-26 | minor | CC-003 attribute alignment matrix: 180 import/save/reopen combinations; depends on #910 reader correction | | 2026-10-22 | minor | DXF/DWG save: angular, diametric and radial dimensions get standard DIMASSOC objects (one centre reference to the circle for radial/diametric, the definition points for angular), so AutoCAD follows their geometry; the standard objects of those kinds are read back too, without CADCraft's xdata (#1651) | | 2026-10-19 | minor | DXF/DWG save: angular dimension block text honors DIMDSEP, including per-dimension overrides (#1646) | | 2026-10-19 | minor | A file's own arrowhead blocks with standard names (AutoCAD's `_Dot`, `_DotSmall`), named only by a dimension style, are kept and saved as they were instead of being replaced by CADCraft's solids; PURGE keeps arrowhead blocks dimension styles name | From ab55326e975498429faf256540c8b586f818edef Mon Sep 17 00:00:00 2001 From: smacdmac101 Date: Mon, 26 Oct 2026 17:04:55 -0400 Subject: [PATCH 4/5] docs(io): clarify alignment reader prerequisite scope Address PR #2224 review 4381862389: distinguish the adapted original #910 reader correction from independently reversible matrix coverage. Documentation only; runtime evidence remains 79e8ac5. Exact working-tree cargo xtask ci passed all seven gates. Revert this wording independently without changing import behavior or tests. --- docs/file-format-parity.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index dcbf9bf05f..57deb26924 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -141,7 +141,9 @@ our output in AutoCAD black-box. CC-003 adds 180 synthetic TEXT/ATTRIB/ATTDEF combinations across left/center/right alignment, field lengths 0/1/3/80 and missing or explicit vertical justification 0–3. Each combination is checked after import and DXF save/reopen, including the retained alignment point and value. -The reader implementation is the existing #910 proposal; this contribution adds coverage only. +This contribution adapts the existing #910 reader correction to the current reader helpers +and adds regression coverage. The original reader correction remains a separately credited +prerequisite; the new matrix can be reverted independently. It reproduced ATTRIB group 73=0 / 74=1 being read as Baseline instead of Bottom on d3ae8a6, and passes with #910 adapted to the current extracted reader helpers. No private or AutoCAD-produced drawing is included. This does not establish full drawing fidelity or cover @@ -151,7 +153,7 @@ multiline subclass collisions (the separate #1942 proposal). | Date | Change | Summary | |---|---|---| -| 2026-10-26 | minor | CC-003 attribute alignment matrix: 180 import/save/reopen combinations; depends on #910 reader correction | +| 2026-10-26 | minor | CC-003 attribute alignment: adapted #910 reader correction plus 180 import/save/reopen combinations; clarified prerequisite scope after review | | 2026-10-22 | minor | DXF/DWG save: angular, diametric and radial dimensions get standard DIMASSOC objects (one centre reference to the circle for radial/diametric, the definition points for angular), so AutoCAD follows their geometry; the standard objects of those kinds are read back too, without CADCraft's xdata (#1651) | | 2026-10-19 | minor | DXF/DWG save: angular dimension block text honors DIMDSEP, including per-dimension overrides (#1646) | | 2026-10-19 | minor | A file's own arrowhead blocks with standard names (AutoCAD's `_Dot`, `_DotSmall`), named only by a dimension style, are kept and saved as they were instead of being replaced by CADCraft's solids; PURGE keeps arrowhead blocks dimension styles name | From d087ee216f9c22233f39a087dc1e0ed437b20569 Mon Sep 17 00:00:00 2001 From: smacdmac101 Date: Tue, 27 Oct 2026 00:04:22 -0400 Subject: [PATCH 5/5] test(io): cover middle and absent TEXT justification CC-003, PR #2224 review 5661820293: extend the synthetic matrix from 180 to 210 combinations. Include TEXT group 73 Middle and omitted group 73 while retaining independent ATTRIB/ATTDEF field-length coverage. No production changes. Validation: focused regression and all seven cargo xtask ci stages passed on the exact branch, 2556 passing executions, zero failures, one ignored. Existing native/browser evidence applies to prior production changes; this follow-up changes tests/docs only. Dependencies: existing adapted #910 reader correction and Windows #2198 prerequisite, retained with upstream integration. Revert this commit independently to restore the previous 180-case matrix; reverse it before removing the earlier CC-003 test commits. No runtime/schema dependency. --- crates/io/tests/it/attribute_vertical_alignment.rs | 11 +++++++---- docs/file-format-parity.md | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/io/tests/it/attribute_vertical_alignment.rs b/crates/io/tests/it/attribute_vertical_alignment.rs index c09e770c41..2450cd0ee3 100644 --- a/crates/io/tests/it/attribute_vertical_alignment.rs +++ b/crates/io/tests/it/attribute_vertical_alignment.rs @@ -6,16 +6,19 @@ use cadcraft_io::{read_dxf, write_dxf}; fn imported_attributes_use_group_74_and_keep_the_alignment_point() { for kind in ["ATTRIB", "ATTDEF", "TEXT"] { for (horizontal, expected_h) in [(0, HAlign::Left), (1, HAlign::Center), (2, HAlign::Right)] { - for field_length in [0, 1, 3, 80] { + let group_73: &[Option] = + if kind == "TEXT" { &[None, Some(0), Some(1), Some(2), Some(3), Some(80)] } else { &[Some(0), Some(1), Some(3), Some(80)] }; + for &field_length in group_73 { for vertical in [None, Some(0), Some(1), Some(2), Some(3)] { + let field = field_length.map_or(String::new(), |v| format!("73\n{v}\n")); let v = vertical.map_or(String::new(), |v| format!("74\n{v}\n")); let prefix = if kind == "ATTRIB" { "0\nINSERT\n2\nTEST\n66\n1\n" } else { "" }; let suffix = if kind == "ATTRIB" { "0\nSEQEND\n" } else { "" }; let source = format!( - "0\nSECTION\n2\nENTITIES\n{prefix}0\n{kind}\n10\n1\n20\n2\n40\n1\n1\nValue\n2\nTAG\n72\n{horizontal}\n73\n{field_length}\n{v}11\n7\n21\n9\n{suffix}0\nENDSEC\n0\nEOF\n" + "0\nSECTION\n2\nENTITIES\n{prefix}0\n{kind}\n10\n1\n20\n2\n40\n1\n1\nValue\n2\nTAG\n72\n{horizontal}\n{field}{v}11\n7\n21\n9\n{suffix}0\nENDSEC\n0\nEOF\n" ); let drawing = read_dxf(source.as_bytes()).expect("import synthetic DXF"); - let expected = match if kind == "TEXT" { field_length } else { vertical.unwrap_or(0) } { + let expected = match if kind == "TEXT" { field_length.unwrap_or(0) } else { vertical.unwrap_or(0) } { 1 => VAlign::Bottom, 2 => VAlign::Middle, 3 => VAlign::Top, @@ -29,7 +32,7 @@ fn imported_attributes_use_group_74_and_keep_the_alignment_point() { EntityKind::Text(t) => t, other => panic!("unexpected {other:?}"), }; - assert_eq!(text.valign, expected, "{kind} 73={field_length} 74={vertical:?}"); + assert_eq!(text.valign, expected, "{kind} 73={field_length:?} 74={vertical:?}"); assert_eq!(text.halign, expected_h); assert_eq!( text.align_pt.map(|p| (p.x, p.y, p.z)), diff --git a/docs/file-format-parity.md b/docs/file-format-parity.md index 57deb26924..83f4cf170c 100644 --- a/docs/file-format-parity.md +++ b/docs/file-format-parity.md @@ -138,8 +138,8 @@ our output in AutoCAD black-box. ## Attribute alignment regression coverage -CC-003 adds 180 synthetic TEXT/ATTRIB/ATTDEF combinations across left/center/right alignment, -field lengths 0/1/3/80 and missing or explicit vertical justification 0–3. Each combination is +CC-003 covers 210 synthetic TEXT/ATTRIB/ATTDEF combinations across left/center/right alignment, +attribute field lengths 0/1/3/80, TEXT group 73 missing or 0/1/2/3/80, and group 74 missing or 0–3. Each combination is checked after import and DXF save/reopen, including the retained alignment point and value. This contribution adapts the existing #910 reader correction to the current reader helpers and adds regression coverage. The original reader correction remains a separately credited @@ -153,6 +153,7 @@ multiline subclass collisions (the separate #1942 proposal). | Date | Change | Summary | |---|---|---| +| 2026-10-26 | minor | CC-003 review follow-up: extend the matrix to 210 combinations with TEXT Middle and omitted group 73; no production change | | 2026-10-26 | minor | CC-003 attribute alignment: adapted #910 reader correction plus 180 import/save/reopen combinations; clarified prerequisite scope after review | | 2026-10-22 | minor | DXF/DWG save: angular, diametric and radial dimensions get standard DIMASSOC objects (one centre reference to the circle for radial/diametric, the definition points for angular), so AutoCAD follows their geometry; the standard objects of those kinds are read back too, without CADCraft's xdata (#1651) | | 2026-10-19 | minor | DXF/DWG save: angular dimension block text honors DIMDSEP, including per-dimension overrides (#1646) |