Skip to content

Enclose Characters: put a character in a circle, square, triangle or diamond - #301

Merged
echelon merged 3 commits into
storytold:mainfrom
vangel76:feat/enclose-characters
Oct 11, 2026
Merged

echelon merged 3 commits into
storytold:mainfrom
vangel76:feat/enclose-characters

Conversation

@vangel76

@vangel76 vangel76 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #297

What changed

  • Command format.enclose {"shape": "circle|square|triangle|diamond" | null, "style"?: "shrink|enlarge", "text"?: string} works on one full-width character or up to two half-width ones (anything else is an error). It can also change the shape of enclosed characters that are selected or next to the caret, and null turns them back into plain text. Each step can be undone. The text parameter is the dialog's Text box: it replaces the selection, or goes in at the caret.

  • Model: enclosed characters are an EQ field with the overstrike switch, as ECMA-376 Part 1 §17.16.5.20 describes: eq \o\ac(○,字). Its cached result is the text, so plain-text export, search and PDF text still read 字. Parsing lives in the new wordcraft_doc::eq module (parse_overstrike, Enclosure).

  • Layout/render/PDF: general EQ \o support. The arguments are drawn on top of each other as one cluster, centred by default or aligned with \al/\ar. An enclosure symbol is drawn as a vector Draw::Shape (ellipse, rectangle, triangle or diamond) in the text colour, so it doesn't depend on the font having ○□△◇:

    • "Shrink text": the text is scaled to fit inside a shape one em high.
    • "Enlarge symbol": the text keeps its size and the shape grows around it.

    Before this change, Word documents with enclosed characters showed nothing at all, because Word writes no field result for them.

  • .docx:

    • Writing follows Word's structure: begin, then the code split so the symbol and the text each have their own run size and position, then end, with no result.
    • Reading gets the style back from those run sizes.
    • In the model, the style is a trailing \* enlarge on the code. It never reaches a file.
  • UI: a Home › Font › Enclose Characters button (icon drawn in code) opens a dialog with Style (None / Shrink text / Enlarge symbol), Text, an Enclosure list, a drawn preview and OK. Scripts and agents that pass a shape never see the dialog. The new strings are in all 8 catalogs, including sr.tsv and sr-latn.tsv.

  • Docs: parity checklist regenerated. ROADMAP, gaps, target-app, UI, file-format and layout parity docs updated.

Parity

Before: 402/434 (92.6%). After: 403/434 (92.9%) (rebased on main). The floor test value is unchanged.

Testing

  • wordcraft-doc eq::tests: Word's enclosure codes, nested switches, ; separators, escapes and plain \o parse; other fields and EQ switches are rejected.
  • wordcraft-engine enclose_characters_make_an_eq_field_and_come_back_out:
    • the command builds the right instruction and refuses selections that don't fit;
    • the shape changes and the style is kept;
    • null restores the text and selects it, and undo works;
    • a .docx round trip keeps both fields and both styles;
    • text inserts at the caret.
  • wordcraft-docx enclosed_characters_round_trip_in_words_structure: the written XML has no separate, no marker and a shrunk text run. All four shape/style/size combinations read back identical.
  • wordcraft-layout enclosed_characters_draw_a_shape_around_the_text: the shape is drawn around the shrunk text, the next text follows the shape, enlarge grows the shape, and plain \o overstrikes without a shape.
  • wordcraft-ui-egui enclose_characters_button_opens_the_dialog.
  • ui_shot: checked the dialog and the rendering of all four shapes, enlarge and a CJK character, at 200%.
  • Passing: cargo test and cargo clippy --all-targets -D warnings on doc, layout, docx, engine and ui-egui; cargo fmt; cargo xtask layers, assets, wasm and parity.

🤖 Generated with Claude Code

@vangel76
vangel76 force-pushed the feat/enclose-characters branch 4 times, most recently from 20a3781 to fe3dc72 Compare October 10, 2026 23:45
@vangel76

Copy link
Copy Markdown
Contributor Author

Rebased onto main (after #315/#308/#294/#397/#399 and others). Conflicts: revision tables, i18n catalogs (kept main's "Formatted" next to ours), an engine test placed next to main's new Delete Columns test, parity numbers. docs/parity-checklist.md regenerated: 403/434 (92.9%), PR body updated. Main's new Estonian catalog got the 6 new strings.

@vangel76
vangel76 force-pushed the feat/enclose-characters branch from fe3dc72 to 440468e Compare October 11, 2026 07:54
… around a character (storytold#297)

New command format.enclose {"shape": "circle|square|triangle|diamond" | null,
"style"?: "shrink|enlarge", "text"?: string} puts one full-width or up to two
half-width characters in an enclosure, changes its shape, or (null) takes the
text back out. It is stored the way ECMA-376 describes it: an EQ field with the
overstrike switch, eq \o\ac(○,字), with the text as its plain-text result.

Layout now draws EQ \o fields: the arguments overstruck as one cluster
(centred, \al or \ar). An enclosure symbol among them is drawn as a vector
shape around the text in the text's colour, so it never depends on the font
having ○ □ △ ◇; "shrink text" scales the text into a one-em shape, "enlarge
symbol" grows the shape around text at its own size. Screen and PDF both get
it through the display list. Imported Word documents with enclosed characters
used to show nothing (the field has no result); they now render.

.docx: written as Word stores enclosed characters (begin, the code split so the
symbol and the text have their own run sizes, end, no result); the reader
recovers the style from those sizes. The style lives in the model as a trailing
\* enlarge on the code, never written to a file.

Home › Font gets an Enclose Characters button that opens a dialog (Style:
None / Shrink text / Enlarge symbol, Text, Enclosure list, a drawn preview);
scripts with a shape never see it. Strings in every interface catalog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vangel76
vangel76 force-pushed the feat/enclose-characters branch from 440468e to 7486393 Compare October 11, 2026 16:50
# Conflicts:
#	ROADMAP.md
#	crates/docx/tests/roundtrip.rs
#	crates/layout/src/display.rs
#	crates/layout/src/para.rs
#	crates/layout/src/tests.rs
#	crates/ui-egui/src/i18n/et.tsv
#	crates/ui-egui/src/i18n/ru.tsv
#	crates/ui-egui/src/i18n/tr.tsv
#	docs/file-format-parity.md
#	docs/gaps.md
#	docs/layout-parity.md
#	docs/parity-checklist.md
#	docs/target-app-parity.md
@echelon
echelon merged commit a5b17eb into storytold:main Oct 11, 2026
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution, @vangel76! This is now merged into main. If you haven't already, please come join us on Discord: https://discord.gg/artcraft

daghantektepe added a commit to daghantektepe/wordcraft that referenced this pull request Nov 6, 2026
…cter in a circle, square, triangle or diamond tamamlandı
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.

Parity: Home › Font › Enclose Characters (format.enclose)

2 participants