Repository navigation
Document grid: lines per page and characters per line (#391) - #401
Merged
Merged
Conversation
vangel76
force-pushed
the
feat/391-document-grid
branch
2 times, most recently
from
October 11, 2026 06:31
25147e3 to
145faf5
Compare
This was referenced Oct 11, 2026
vangel76
force-pushed
the
feat/391-document-grid
branch
2 times, most recently
from
October 11, 2026 18:08
b11da8f to
f35cffe
Compare
- Model: `SectionProps::doc_grid` (`w:docGrid` type, line pitch, charSpace) and the paragraph `w:snapToGrid` flag; DOCX read and write (ECMA-376 §17.6.5). - Layout: with a line grid, lines of snapping paragraphs take whole line pitches with their text centred; with a character grid, East Asian characters take whole cells of the character pitch (all text with snapToChars), Latin text stays proportional. Hostile pitches and charSpace are clamped. Headers and footers don't snap. - Command `layout.documentGrid` (type, linesPerPage, charsPerLine, linePitch, charSpace), one undo step, section scope; catalog row under Layout › Page Setup. - Page Setup dialog: Document Grid section; View › Gridlines draws the document grid of a section that has one. UI strings in every catalog (incl. et, sr, sr-latn). - Tests: DOCX round trip, line pitch and lines per page, character pitch placement, command with clamping and undo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vangel76
force-pushed
the
feat/391-document-grid
branch
from
October 11, 2026 18:57
f35cffe to
ca1ed4b
Compare
# Conflicts: # ROADMAP.md # crates/doc/src/section.rs # crates/docx/src/read/props.rs # crates/layout/src/lib.rs # crates/ui-egui/src/i18n/es.tsv # crates/ui-egui/src/i18n/et.tsv # crates/ui-egui/src/i18n/ja.tsv # crates/ui-egui/src/i18n/pt-br.tsv # crates/ui-egui/src/i18n/ru.tsv # crates/ui-egui/src/i18n/sr-latn.tsv # crates/ui-egui/src/i18n/sr.tsv # crates/ui-egui/src/i18n/tr.tsv # crates/ui-egui/src/i18n/uk.tsv # crates/ui-egui/src/i18n/zh-hans.tsv # crates/ui-egui/src/i18n/zh-hant.tsv # docs/file-format-parity.md # docs/gaps.md
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Layout › Page Setup › Document Grid (
w:docGrid, ECMA-376 §17.6.5).SectionProps::doc_grid(typedefault|lines|linesAndChars|snapToChars, line pitch,w:charSpace) and paragraphw:snapToGrid, read and written (w:docGridwritten afterw:bidiinsectPr; Word's no-grid<w:docGrid w:linePitch="360"/>survives a round trip).w:snapToGrid w:val="0"turns it off), each line's height rounds up to whole line pitches with the text centred in them. Multiple spacing is a multiple of the snapped height; Exactly isn't snapped. Headers and footers don't snap.linesAndCharsgives East Asian characters (CJK ideographs, kana, Hangul, CJK punctuation, full-width forms) whole cells of the character pitch, glyph centred. The pitch is the Normal font size plus charSpace/4096 pt. A larger character takesround(size / default size)cells. Latin text keeps its own widths. WithsnapToChars, all text snaps to whole cells.layout.documentGrid {"type"?, "linesPerPage"?, "charsPerLine"?, "linePitch"?, "charSpace"?}: section scope like the other page-setup commands, one undo step, returns lines per page and characters per line. New catalog row: Layout › Page Setup › Document Grid (403/435).How tested
crates/layout/src/tests_grid.rs:floor(text height / line height)lines.snapToGridoff gives the natural heights.k × pitch, and Latin advances don't change. No assertion depends on font metrics, and the test works when CJK glyphs are missing.crates/docx/tests/roundtrip.rs: section grid (linesAndChars, 17.5 pt, negative charSpace), a default grid, andsnapToGridround-trip.crates/engine/src/tests.rs:layout.documentGridsets 40 lines / 30 chars, is one undo step, clamps hostile values, rejects an unknown type, and undoes back to no grid.crates/docunit test: pitch clamping and lines/chars per page.cargo teston doc, docx, layout, engine and ui-egui (lib); clippy-D warningson those crates;cargo fmt;cargo xtask layers,wasmandparity.ui_shot: Japanese text on a 30×30 grid, with the gridlines and the dialog shown.Not done
w:snapToGridisn't read.Fixes #391
🤖 Generated with Claude Code