Repository navigation
Conversation
AutoCAD sizes TrueType text by the height of its H: Arial's OS/2 cap height is 1467 of 2048 units, its H 1466 high, and AutoCAD's MTEXT wraps Arial text 1467/1466 wider than the OS/2 value gives (all 20 measured wrap limits match with the H, 13 with the OS/2 value).
…torytold#3010) A word stays on the line while the pen position where it starts plus the width of its measure box is below the column width (AutoCAD wraps on equality); SHX glyphs are measured by craft-shx Glyph::extent (arcs by their chord-and-sagitta box), slanted text by slanting its measure points. Lines are justified by their drawing (the first character's side bearing dropped; leading spaces, a tab and spaces formatted unlike both neighbouring words keep the line's start), every space of a run counts, leading spaces of a paragraph stay and count as a word. The first baseline drops by the first line's drawing top when that is higher than the text, middle and bottom attachment count the last line's descender, and the At least step from line i to i+1 is (H_i + h)/3 + max(H_i+1, its top). craft-shx points at storytold/craft-libs#2036 until that is merged.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. CodeRabbit Verify
|
Conflicts: Cargo.toml/Cargo.lock (main's craft-libs revisions; craft-shx stays on the craft-libs#2036 head), fonts/ttf.rs (storytold#2261's pinned cap height comes first, then the drawn H, then OS/2).
|
Merged current main (a70b9b0). Conflicts: Locally |
Fixes #3010. MTEXT wraps, justifies and spaces its lines as AutoCAD does. Measured against AutoCAD Mechanical 2023 with synthetic drawings (summary in #3010 (comment)).
Draft: needs storytold/craft-libs#2036 (
craft-shxreports the box AutoCAD measures a glyph by).Cargo.tomlpointscraft-shxat that PR's commit for now; I'll switch it back to storytold/craft-libs once #2036 is merged.What AutoCAD does, and what changes
mtext.rsplain_lines,para.rsLineBuilder::place): a word stays on the line while the pen position where it starts plus the width of its measure box is below the column width; AutoCAD wraps on equality. Before, the word's advances were compared, so text wrapped too early (the trailing side bearing of the last character and the leading one of the word counted).text_extent, new): SHX glyphs bycraft_shx::program::Glyph::extent(arcs by their chord-and-sagitta box, which is what makes isocp/isoct wrap 0.5–1 % earlier than their ink), other fonts by their outlines; slanted text by slanting the measure points (a 15° style, as in most dimension styles).{\C1;a} {\C3;b}) is justified by its drawing's width but drawn without the bearing correction.mtext_exact_spacing_ignores_taller_linesexpected 5/3 of the doubled height before and after a\H2xline; AutoCAD steps 2/3·h + 2h before it and h + h after it, so its at-least value changes to that (Exactly is unchanged).ttf.rscap_height): by the drawn height ofHbefore OS/2sCapHeight(a cap height pinned byCADCRAFT_CAP_HEIGHT, fonts: a substitute's text scales by the cap height the installation pins for it, not the substitute's own #2261, still comes first). Arial's OS/2 value is 1467, itsH1466 units; with theHall 20 measured Arial wrap limits match, with the OS/2 value 13.Evidence
Synthetic test drawings (one MTEXT per cell; isocp, isoct, romans, simplex, SIMPLEX8, txt, Arial; heights 2.5 and 12.5; width factors 1 and 0.75; all nine attachments; paragraphs,
\P,\H,\W,\C,\Q, tabs, leading and repeated spaces; 15° styles), plotted by AutoCAD and bycadcraft-cli, rasterised and compared per line (line count, ink extents relative to the insertion point, tolerance 0.03·h):\H)\T, see below)Wrap limits stepped by 0.02·h (120 font/text pairs) and 0.005·h (64 arc glyphs): all match except exact ties at the rounding of the stored width (≤ 5·10⁻⁵).
Not covered here:
\Ttracking (not supported; #2848), the underline offset of TrueType text, negative oblique angles and slanted TrueType at the right edge (small differences remain), and single-line TEXT.Tests
New, with a test font compiled in the test (
shx/tests.rs):mtext_wraps_a_word_by_its_drawing_not_its_advances,mtext_lines_are_justified_by_their_drawing,mtext_lines_are_placed_by_their_drawing_vertically; each also runs the paragraph path and checks both agree. All three fail on main and pass here.Locally:
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspace(both withoutcadcraft-web) pass. I did not run the wasm build or the fullcargo xtask ci.On our 472 production drawings (not shareable) plotted against AutoCAD's own PDFs, 46 drawings get closer to AutoCAD and none moves away.