Skip to content

Export: area type that Shrink Text to Fit scales down is written at the size it draws at - #2672

Open
dotCooCoo wants to merge 1 commit into
storytold:mainfrom
dotCooCoo:fix/svg-live-text-shrink-to-fit
Open

dotCooCoo wants to merge 1 commit into
storytold:mainfrom
dotCooCoo:fix/svg-live-text-shrink-to-fit

Conversation

@dotCooCoo

Copy link
Copy Markdown
Contributor

What and why

Shrink Text to Fit scales area type down at layout time. docs/mcp.md says "The stored sizes don't change: the scaling happens at layout time, so rendering and every export see it." The canvas, PDF export and the exports that write type as outlines draw the shrunk size, but four writers took their sizes from the stored styles. SVG export wrote 12 pt type that the layout draws at 8 pt as font-size="12", with the full letter spacing and baseline shift, so a viewer drew it larger than the canvas does.

  • vectorcraft_text::scaled, the function the layout scales shrunk text with, is now public. SVG export, legacy .ai saves and the CSS Properties panel take the type's styles from it at the layout's fit_scale, and DXF export multiplies its TEXT heights by that scale.
  • SVG export writes live text's font size, letter spacing and baseline shift (dy) at the drawn size, with and without Fewer <tspan> Elements. Positions and textLength still come from the layout.
  • Legacy .ai saves write the text objects' size, leading and baseline shift at the drawn size, so the type reads back fitting its frame.
  • DXF export writes TEXT heights at the drawn size, and the CSS Properties panel gives the drawn font size, letter spacing and line height.
  • docs/target-app-parity.md has one line for it. No command, reply or user-visible string changes.

How it was tested

New tests, each failing on main:

  • shrunk_area_type_is_written_at_the_size_it_draws_at (vectorcraft-svg, tests/text_layout.rs): usvg draws every character of shrunk area type where the canvas draws it and as wide (tracked, kerned, shifted and larger runs on Left, Center, Justify Left and Justify All lines, and a horizontally scaled run on all but Center); Fewer <tspan> Elements writes the shrunk size.
  • shrunk_area_type_gives_the_size_it_draws_at (vectorcraft-svg, tests/css_rules.rs): checks the CSS rule's font size, letter spacing and line height.
  • tests::shrunk_area_type_is_text_at_the_size_it_draws_at (vectorcraft-cad): checks every TEXT height.
  • legacy_ai::tests::shrunk_area_type_is_written_at_the_size_it_draws_at (vectorcraft-eps): checks the sizes, leading and baseline shift read back from the file, and that the read-back type fits its frame.

Targeted checks on the final tree: cargo fmt --all -- --check; cargo clippy -p <crate> --all-targets -- -D warnings and cargo test -p <crate> on vectorcraft-text, vectorcraft-svg, vectorcraft-cad and vectorcraft-eps; cargo xtask brands, layers and assets.

On Windows 11 (x86-64) with rustc 1.99.1, on top of main at 08878722:

  • CRAFT_FONTS_DIR=<craft-fonts checkout> cargo xtask ci passes its 10 steps: 7,608 tests passed, 0 failed, 11 ignored.

git merge-tree reports no conflicts with main at 08878722 or at 009384b2; merged with 009384b2, which changes crates/text/src/layout.rs, the four new tests pass.

Checklist

  • cargo xtask ci passes (fmt, clippy, tests, assets, brands, layers, wasm).
  • No panics in shipped code: no unwrap(), expect(), panic!, unreachable!, todo! or
    unimplemented! outside tests, and no unchecked indexing on data from files, parameters or
    messages. Errors are returned as Result and shown to the user
    (why and how).
  • Clean-room: nothing copied from Adobe products or GPL/AGPL code (AGENTS.md).
  • Every new asset has a row in ASSETS.md.

…he size it draws at

Shrink Text to Fit scales area type down at layout time, and the canvas,
PDF export and the exports that write type as outlines draw it at that
size. SVG export wrote the live text at its stored font size, letter
spacing and baseline shift, so a viewer drew it larger than the canvas
does. Legacy .ai saves wrote the stored size, leading and baseline shift
into the text objects, DXF export took the TEXT heights from the stored
size, and the CSS Properties panel gave the stored font size, letter
spacing and line height.

The text crate's scaled, which the layout scales shrunk text with, is
now public. SVG export, legacy .ai saves and the CSS Properties panel
take the type's styles from it at the layout's fit scale, and DXF
export multiplies the TEXT heights by that scale. Positions and
textLength in SVG still come from the layout.

Docs: docs/target-app-parity.md.

@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.

This is a comment, not an approval. I haven't built or run it (no cargo here), and the hosted checks on this head (affinity3, FreeBSD, the two windows-arm64 jobs) all pass but none of them is a workspace test run that I can see, so the five new tests have no hosted result. By my reading I found no blocker.

What I read. The whole diff: text/src/layout.rs (scaled made public), the DXF, legacy .ai, SVG export and CSS writers, and the four new tests.

What I checked, and it holds.

  • The idea. Shrink Text to Fit lays out scaled(t, layout.fit_scale), but the exporters wrote the unscaled styles, so a shrunk area type came out at its full size and overflowed its frame in the target. Each exporter now writes the styles the layout draws in, using the same scaled function the layout itself uses, so the two cannot drift apart.
  • DXF. The cap height is cs.size * layout.fit_scale * .... The test checks 14.0 * fit for 20 pt type (cap height 0.7 of the size), which is consistent with CAP_HEIGHT.
  • Legacy .ai, CSS. Both build fitted only for Area plus ShrinkText and only when fit_scale != 1.0, and otherwise keep the original t, so other type and unshrunk type are unchanged. The .ai test checks sizes, baseline shift (3 * fit) and leading (20 * fit) after a read-back, and that the result no longer overflows.
  • SVG. drawn replaces t only for the first style and the text_line calls; lines and lay still come from the original layout, which is what was shrunk. The test runs ragged, centred and both justified modes, plus Fewer <tspan> Elements.
  • Docs. The parity note matches what is written.

Points for the author and maintainers.

  • Layout runs again. css.rs and legacy_ai.rs call layout just to get fit_scale, a second full layout (with its shrink search) for each shrunk object. Fine for correctness; if exports of big documents get slower, pass the layout in instead.
  • Float equality. fit_scale != 1.0 is an exact compare. It is only a shortcut (scaling by 1.0 is a no-op), so no harm.
  • Rounding. A shrunk size is now an arbitrary number (for example 17.3 pt). That is the true drawn size, but reimporting the SVG or .ai will show it, and it is worth a line in the release note.
  • Hosted tests. Please get the workspace test job run on this head so the five new tests are checked.

Validation request (head d1d9cff876f03ecc60edc452ade02cda6672bbab):

  • os: linux
  • commands: cargo fmt --all -- --check; cargo test -p vectorcraft-cad -p vectorcraft-eps -p vectorcraft-svg -p vectorcraft-text
  • expected: all pass, including shrunk_area_type_* in cad, eps and svg; an area type with Shrink Text to Fit exports at its drawn size in SVG, .ai, DXF and CSS
  • holds: I did not run anything; no hosted workspace test result on this head

@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.

Correction to my review above (same head, d1d9cff8…): I wrote that none of the hosted checks was a workspace test run, so the five new tests had no hosted result. That was wrong. The freebsd / FreeBSD 15 (build + test) job runs cargo test --workspace --locked on this head and passes (about 2,130 tests across the workspace in its log), so the new tests in cad, eps, svg and text were run and are green on FreeBSD.

The rest of my review is unchanged: no blocker, and the points for the author (the second layout pass in the .ai and CSS writers, arbitrary shrunk sizes on re-import) still stand. Only the "no hosted workspace test result" hold is withdrawn.

@Messhias Messhias 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.

Export: area type that Shrink Text to Fit scales down is written at the size it draws at. Checklist cargo xtask ci is ticked.

This branch has not been deployed

No deployments
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.

3 participants