Skip to content

fix(fonts): MTEXT \W…x multiplies the width factor; document the atom cap - #1273

Merged
skylartaylor merged 1 commit into
storytold:mainfrom
vangel76:fix/fonts-mtext-width-factor
Nov 9, 2026
Merged

skylartaylor merged 1 commit into
storytold:mainfrom
vangel76:fix/fonts-mtext-width-factor

Conversation

@vangel76

Copy link
Copy Markdown
Contributor

Fixes #1272

Problem

In MTEXT, a trailing x on the width code (\W2x;) makes the value relative: it multiplies the current width factor (public DXF reference). parse stripped the x and used the number as an absolute factor, so \W2x; set 2 instead of doubling. \H...x was already correct. Separately, the 200 000-atom cap in parse dropped the rest of an MTEXT without saying so anywhere.

Changes

  • crates/fonts/src/mtext.rs: \W<n>x; multiplies the current wf; \W<n>; is unchanged (absolute). The compounded result is clamped to 0.01..100, the range an absolute \W already accepts, so a long relative chain stays finite (same idea as the relative \H bound).
  • Doc comment on MAX_ATOMS states that parsing stops after the cap and the rest is silently dropped. Behaviour is unchanged.
  • Regression test width_factor_x_is_relative: absolute, relative, relative after absolute, capital X, 50-step chains up and down (clamped to 100 and 0.01), and 1e999, NaN, empty values (ignored).

Limits

  • Only \W...x. \K, \T, \A are untouched.
  • No warning channel for the atom cap; docs-only, as decided. I found no suitable page in docs/ for it, so the doc comment is the only place.
  • A relative value below 0.01 (for example \W0.005x;) is still ignored, like an absolute one.

Test plan

Did not run

  • Full cargo xtask ci (whole-workspace clippy/tests, assets, wasm build) and the rest of the workspace tests.
  • No visual check in the running app.

🤖 Generated with Claude Code

…om cap (storytold#1272)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReviewerA — source-read COMMENT (not an approval)

I read the diff: MTEXT \W...x multiplies the width factor, and the atom cap is documented. The doc comment on the cap now says it counts words, spaces and paragraph breaks per MTEXT, that hostile contents are cut there, and that the rest of the contents is silently dropped from the layout with no warning to the caller (an honest statement of a limitation). The width factor code was num(a.trim_end_matches(['x','X'])).filter(|v| *v > 0.01 && *v < 100.0) with f.wf = v; the new code strips the suffix with strip_suffix(['x', 'X']) to know whether it was relative and, per the comment, \W2x; multiplies the current factor (like \H2x;) and \W2; sets it. That is the MTEXT rule. The range filter on the value (0.01 to 100) should apply to the product too, since repeated \W50x; multiplies the factor beyond any bound, a way to produce a huge layout from a small string; the cap on atoms does not limit that. I have not run it, and no exact-head CI result exists for this head. Nothing was run.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

@austin62jake austin62jake left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. I merged it onto current main with ten other small PRs (#1273, #1266, #1265, #1263, #1254, #1247, #1233, #1196, #1114, #1445, #1591). The whole suite passes (3170 tests), and so do fmt and the web build. Clippy stops only on #1254's test.

\W2x; multiplying the current width factor, as \H2x; already does for height, while \W2; sets it, matches the MTEXT format. Clamping the compounded factor to the absolute range keeps repeated x codes bounded. Documenting that atoms past the cap are dropped silently is honest.

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1d29b626e66cc1a06999ba36dfb40e441929b3f6. No findings in the complete one-file source review. My earlier compounding-width concern was incorrect: this head already clamps the product to 0.01..=100.0, and width_factor_x_is_relative covers repeated growth/shrinkage, absolute vs relative assignment, uppercase X and invalid values. The atom-limit documentation accurately describes the existing behavior.

This is a review comment, not an approval: GitHub reports no checks for this head, and no local Rust tests were run because the available workspace is out of disk space. Please refresh the branch onto the current CI-enabled base and obtain a passing gate, or provide reproducible validation for this exact head. The missing validation is the remaining gap; I am not asking for duplicate tests that are already in the diff.

@skylartaylor

Copy link
Copy Markdown
Member

CI never ran on this branch since it predates the workflow, so I checked it by hand: merged onto current main (909af5e3) with this batch, the workspace tests (3,732) and clippy on cadcraft-fonts pass on Linux. Merging.

@skylartaylor
skylartaylor merged commit d9e62df into storytold:main Nov 9, 2026
ashokram-si added a commit to ashokram-si/cadcraft that referenced this pull request Nov 9, 2026
…H…x do (storytold#2827)

Main's storytold#1273 made the x suffix of \W relative (\H already was). \T read
it as an absolute factor, so \T2;\T1.5x; tracked at 1.5 instead of 3.
The product is held to the format's 0.75 to 4. The three size codes
now read their argument with one helper, `factor`.
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.

fonts: MTEXT \W…x is relative; document the 200000-atom cap

4 participants