Skip to content

Add TEXTALIGN: align and space text objects - #2145

Closed
insanedps wants to merge 1 commit into
HakanSeven12:mainfrom
insanedps:pr/textalign
Closed

insanedps wants to merge 1 commit into
HakanSeven12:mainfrom
insanedps:pr/textalign

Conversation

@insanedps

Copy link
Copy Markdown
Contributor

Closes #2144.

What

New command TEXTALIGN: aligns and spaces several TEXT, MTEXT and ATTDEF objects against a base text, following the AutoCAD prompts:

Current settings: Align = Left, Spacing Mode = Current Vertical
Select text objects to align [alIgnment/Options]:
Select text object to align to [Point]:
Pick second point or [Options]:
  • alIgnment: Left / Center / Right edge of the text.
  • Options (spacing mode): Distribute (even spacing between the base and the second point), Set spacing (fixed distance along the direction), Current vertical (keep each Y, line the edges up along the picked direction), Current horizontal (the same with X and Y swapped).
  • Point: two picked points instead of a base text.
  • Settings stay for the session. The whole batch is one undo step. The existing .pgp alias that pointed at TEXTALIGN now resolves to it.

How

  • Edges come from the rendered glyphs (wire_models_for → text_verts), measured in the text's own frame. Each SDF glyph tile is the glyph's ink box plus SPREAD_UNITS (now pub(crate) in sdf_atlas.rs), so the margin is subtracted to get the ink edge, the same measure as text_local_bounds. The ink box is then mapped back to world axes, so rotated text aligns by its world-axis box.
  • Objects are only translated: the insertion point, plus the alignment point for justified TEXT and for ATTDEF. Height, rotation, style and justification are kept.
  • New file src/modules/draw/modify/textalign.rs; dispatch in src/app/commands/draw.rs.

Known limits

  • The edge follows the font OCS renders. With a substitute font, side bearings can differ slightly from AutoCAD's SHX (for example, AutoCAD's txt.shx has a small left bearing on B and C).
  • MTEXT uses its nominal height for the glyph margin; inline height or width changes are not taken into account.
  • When the second point is neither straight above nor beside the base (a slanted direction), AutoCAD places the texts differently from the line through the base edge used here.
  • Prompts are English only for now (no catalog entries yet).

Tests

11 tests: left, right and centre edges against the glyph ink, justified TEXT moving both points, MTEXT and rotated TEXT/ATTDEF, distribute, set spacing, horizontal mode, rejecting a second point straight across the spacing axis, prompts resolving to text, and one undo restoring every position in model space and in a paper layout through the .pgp alias. Each test fails with its part of the code turned off. Full cargo test --lib: 3164 passed, 0 failed, 32 ignored.

Left/Center/Right edges, Distribute, Set spacing, Current vertical and
Current horizontal modes; edges come from the rendered glyph ink.

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

Copy link
Copy Markdown
Owner

Thanks @insanedps. Closing as superseded: #2188 implemented TEXTALIGN with all 12 alignments and localized prompts, building on the same idea.

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.

Feature request: TEXTALIGN command (align and space several text objects)

2 participants