96 Commits
Author SHA1 Message Date
DolanandClaude Opus 5.5 5f626c02ba fix(layout): lay out rows that repeat their table's properties, split rows at multiple line spacing and overfull text boxes, as Word does (#3918)
* fix(layout): lay out rows that repeat their table's properties, split rows at multiple line spacing and overfull text boxes, as Word does

estimatePageNumbers stopped at three things report templates have (#3912):

- A row whose w:tblPrEx repeats the table's own w:tblW, w:tblLayout or
  w:tblInd. Properties that are the same as the table's change nothing,
  so only those that differ still stop the layout.
- A cell's line at multiple spacing at the foot of a row that breaks
  across pages, where it fits only without the space below its text.
  word-split-rows-and-boxes.docx shows Word moves it to the next page,
  unlike in the body: 69 probes, with and without borders and above a
  cell's bottom margin, all now on Word's pages.
- An inline VML text box of its own height whose text is taller than
  it. Word cuts the text off and keeps the box's height (OB1 in the same
  probe), so the box is laid out at its own height.

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

* fix(layout): compare a row's table properties with the table's whatever order their attributes are in

XML gives attributes no order, so a row's w:tblPrEx written with
w:type before w:w is the same as the table's w:tblW written the other
way round. The comparison now sorts each element's attributes first,
as a text frame's are compared, rather than stopping the layout there.

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

* fix(layout): put the probe's text box shape type before whichever box ONLY leaves first

The shape type was added to OB1a's box, so a run with ONLY=OB1b wrote a
box referring to a shape type the document didn't declare. It now goes
before the first box in the document, whichever that is. A full run
writes the same document as before.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 04:14:34 +00:00
DolanandClaude Opus 5.5 2e07d2d688 perf: make the browser bundle 29 KB smaller, zipping with fflate and hashing with docx's own SHA-1 and SHA-256 (#3834) (#3836)
* build(deps): add fflate, to zip and unzip packages in place of JSZip

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* perf: hash with docx's own SHA-1 and SHA-256, in place of hash.js

hash.js was about 6.5 KB of a browser bundle, minified and gzipped, as its whole library is bundled for the two hashes
docx uses: SHA-1 for the names of media files (`hashedId`) and SHA-256 for the password that protects a document. It
hasn't had a release since 2018, and brought `inherits` and `minimalistic-assert` with it. The platforms' own hashes
can't replace it, as browsers only hash asynchronously and documents are written synchronously.

The hashes are the same: they match FIPS 180-4's examples and node:crypto, and the password hash Word accepts is
unchanged. They are also faster: hashing a 5 MB image takes about half the time, and a password's 100,000 rounds about
130 ms rather than 155 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* perf: zip and unzip with fflate, in place of JSZip

JSZip was about 30 KB of a browser bundle, minified and gzipped, as its prebuilt browser file brings its own copy of
pako and more. fflate's zipSync and unzipSync, the only parts docx needs, are about 6 KB. Together with the hashes, the
bundle of a page that packs a document goes from 123 KB to 94 KB.

Nothing changes for users:
- Packer and patchDocument give each output type as JSZip gave it, including "string" and "binarystring" as a
  character for each byte, a Blob with the .docx or .docm MIME type, and the same errors for "nodebuffer" without
  Buffer, a Blob without Blob, and "text", which JSZip never gave.
- patchDocument and patchDetector still take a JSZip instance, which is read through its generateAsync, so the types
  no longer import jszip. They also still take the other forms JSZip read: a string with a character for each byte, an
  array of bytes, a Blob, an ArrayBuffer and bytes from another realm.
- A part's text keeps a byte order mark at its start, as it did.
- Packer.toStream still compiles synchronously, so it throws as before, and gives the document a turn of the event
  loop later.

Zipping is now synchronous, and faster: packing a document with 5,000 paragraphs and 5 MB of images takes 83 ms
rather than 182 ms.

The zip files no longer have folder entries, which JSZip added for each folder. Word doesn't write them, and nothing
reads them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test: test the packer and the patcher's zip reading without JSZip

These specs mocked JSZip or read the JSZip instance the compiler returned. They now build real zip files and read
what the Packer and the patcher give, so they test the zipping too:
- loadZip reads every form a template can be given in, a JSZip instance through its generateAsync, and leaves out
  folders
- Packer.toStream throws when the document can't be written, and gives it even to a listener added after an await
- toBlob, toArrayBuffer and toStream give real zip files, rather than what a mocked compiler gave

The counts of the files in a package no longer include the folder entries JSZip added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test: test zipping, unzipping and each output type of a zip file

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* chore: read and write .docx files in the scripts with fflate, in place of JSZip

docx is replacing JSZip with fflate (#3834), and jszip is leaving package.json, so the scripts that read documents
(compare-layout.ts, the layout probes' line checkers) and the probes that edit docx's output before writing it use
fflate's unzipSync and zipSync. They leave out folder entries when they unzip, as Word's own files have none, and zip
at level 6. The written documents have the same files in the same order, with the same contents, as before.

check-api.ts's comment no longer says the built declarations import jszip. Those of releases up to 9.14.0 still do,
and the import, which no longer resolves, is any there, which the check accepts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix: load Node's types from docx's declarations, which JSZip's used to load

The declarations use Node's types, such as Buffer and NodeJS.ReadableStream. They had them because they imported
JSZip's declarations, which reference Node's types. Without JSZip, a project that doesn't load every @types package,
such as one with `types` set, or TypeScript 6's default, would find no Buffer in docx's types, and docx's own optional
entries didn't build. The reference is kept in the built declarations with `preserve="true"`, as TypeScript otherwise
leaves it out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test: read and make zip files with fflate in the specs of charts, embedded files, macros, shapes and the core, in place of JSZip

jszip is leaving docx's dependencies, so these specs read packed documents and make changed templates with the helpers
in tests/zip, which unzip and zip with fflate, as docx now does. Each test checks what it checked before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test: read and make zip files with fflate in the specs of docx/html, docx/layout and the patcher, in place of JSZip

jszip is leaving docx's dependencies, as docx now zips and unzips with fflate, so these specs read packed documents
and make templates with the helpers in src/tests/zip.ts. Templates that were JSZip instances are now zip files' bytes,
and the specs read text and bytes from the unzipped files directly, so some helpers that only awaited JSZip are no
longer asynchronous.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* test: patch real zip files in patchDocument's spec, rather than mocking JSZip

JSZip is leaving the dependencies. The spec mocked JSZip.loadAsync and passed an empty Buffer as the template, so
patchDocument never unzipped anything. Each template is now a real zip file, made with the specs' zip helper, so the
tests exercise the unzipping too. The tests of a template opened with JSZip pass an object with generateAsync, which
is how a JSZip instance is read now.

The path keys of the templates are covered by one file-level naming-convention exception, in place of the comments on
each patch key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* build(deps): remove jszip, as nothing uses it now

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix: refuse a zip file's entry of the wrong size before taking memory for it, and inflate only what patchDetector reads

fflate takes room for the size a zip file gives an entry before inflating it, so a template of a few hundred bytes
could make docx take 4 GB, which fails in a browser or a process with a memory limit. JSZip refused such an entry
("uncompressed data size mismatch"). An entry whose given size is more than DEFLATE can inflate its data to (1032
times) is now refused before fflate takes the room, and one that inflates to less than its given size after.

JSZip also inflated only the entries that were read, so patchDetector, which reads only the XML parts in word/, never
inflated a template's images or embedded files. unzipFiles and loadZip now take the paths to read, and patchDetector
gives them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

* fix: refuse a zip file whose entries claim more compressed data than the zip file holds, before taking memory for them

The size an entry inflates to was checked against its compressed size, but that is also read from the zip file, so an
entry could claim compressed data larger than the zip file and pass. The entries docx reads now have their compressed
sizes added up, and a total larger than the zip file is refused before fflate takes room for the entry. Together with
DEFLATE's ratio, that keeps the room taken to 1032 times the zip file's size, as a real zip bomb's is.

The tests damage the entry's data too, so only a refusal before inflating gives their error: without either check, each
fails with fflate's own error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 00:08:58 +01:00
DolanandClaude Opus 5.5 3aaeff48b8 fix: start a numbered heading's table of contents entry with its number, with page numbers from docx/layout (#1130) (#3800)
* fix: start a numbered heading's table of contents entry with its number, with page numbers from docx/layout (#1130)

When Word fills in a table of contents, the entry of a numbered heading
starts with the heading's number, then a tab, with a tab stop past the
number. docx wrote the entries without the numbers. With page numbers
from docx/layout, the table is written clean, so Word shows it as it is
written and doesn't update it: the numbers were never shown. Word for
Mac opened such a document with "Main 2" where its own entry is
"1 Main 2".

A page number estimator can now work out the list numbers of the
paragraphs bookmarks start (listNumbers), which docx asks for once it
has bookmarked the headings, before it writes the entries.
estimatePageNumbers, and estimatePageNumbersWith's estimators, read
them as docx/layout numbers its lists, without laying out the pages. A
numbered heading's entry then starts with its number and a tab, or its
number and a space when its list follows the number with a space or
nothing, as Word writes it, and the pages are laid out with them. A
number docx/layout doesn't write as Word does is left out.

Word places the tab stop by its Normal template, not the document:
past the number, measured in Aptos 12 pt, by 240 twips, and 240 more a
level below the first, at the next multiple of 240 up to 1920, and
where it falls past that. docx places it the same way. The probes are
scripts/layout-probes/word-toc-numbers.ts and the documents Word saved
once it had updated their tables. After entries at levels 7 to 9, Word
places the stops after them on multiples of 200 instead, which docx
doesn't follow.

Checked in Word for Mac 16.114: Word opens the docs' example without
asking to update it, with "1 Introduction 2" to "2.1 Results 3", and
writes the same entries, tab stops and page numbers when it updates
the table itself.

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

* fix: don't name the TOC number probes .word.docx, which the layout comparison lays out

scripts/compare-layout.sh lays out every scripts/layout-probes/*.word.docx
and compares the page of each heading with the pages Word marked in it,
failing for a committed one whose marks don't have all its pages. The
TOC number probes' documents are what Word saved once it had updated
their tables, saved before Word had laid out all their pages, and
aren't for laying out: the shape demos workflow failed on
word-toc-numbers.word.docx, "its marks have 2 of its 3 pages".

They are now word-toc-numbers.docx and word-toc-numbers-font.docx, as
the other probes' documents are named.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 23:49:36 +01:00
Dolan 7907016816 fix: read and write XML without xml and xml-js, which are no longer maintained (#3779) 2026-10-17 09:44:22 +01:00
DolanandClaude Opus 5.5 1fb5e15729 fix: Size rows below a merged cell with its margins, and show how to merge cells by hand (#3766)
Word makes a row below a cell merged down rows as tall as the merged
cell's margins in it, as word-merged-cell-margins.docx shows: with
rowSpan, the cells docx adds take the table's margins, so the rows below
are as tall as the table's margins above and below and a line.
docx/layout left those cells out of the row's height, and now counts
their margins.

The table docs now show merging cells by hand with verticalMerge, which
gives the merged cell's part in each row settings of its own, such as no
margins, which keeps the rows below to a line. That is what #668 asked
for besides keeping rows together.


Claude-Session: https://claude.ai/code/session_0121RHRfmgN8jDksNAdAWKnK

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 23:27:08 +01:00
Dolan 31b98f2e62 feat(layout): lay out compatibility modes, suppressTopSpacing, useFELayout, booklets and HTML divisions where round 26 shows Word's way, as Word does (#3730)
Word's PDFs of round 26 settled what word-stops-compat3, word-stops-top-spacing3 and -4, word-stops-booklet3, word-stops-divisions2 and word-stops-fe-layout3 probed. In Word 2010's and 2007's modes a table of a share of the width is that share of the text and its margins, a table widened for a long word grows to the room with the margins, floating tables sized to their text shift as CN9's did, text after a tab past the end goes on to 22 inches, and gaps of 1250 twips or less beside a frame are left empty; in Word 2007's mode East Asian text in its language breaks as in none and VML shapes' outlines take no room. suppressTopSpacing leaves 0.8 lines and bordered paragraphs' later lines as they are, reverse-folded booklets are the section's pages, a division's box is drawn once with its later paragraphs taking its margins and side borders, and useFELayout puts half the font's average character width between East Asian text and Latin letters or digits.
2026-10-06 22:30:48 +01:00
Dolan 22d15122e5 feat(layout): lay out bordered and Word 6 list numbers, hidden marks at sections, controls, headers and notes, and deleted rows and section breaks, as round 26 shows Word does (#3728)
* feat(layout): lay out bordered and Word 6 list numbers, the schema's other alignments, lists of one definition, hidden marks at sections, controls, headers and notes, and deleted rows and section breaks where round 26 shows Word's way, as Word does

* fix(layout): keep the section break of the paragraph a hidden mark joins to, as the next one's mark is the joined paragraph's
2026-10-06 21:47:10 +01:00
Dolan a1215475f7 feat(layout): lay out Japanese line rules, compressed punctuation, grid indents, right-to-left line ends, endnotes down the page and Arabic's letters side by side where round 26 shows Word's way, as Word does (#3726)
* feat(layout): lay out Japanese line rules, compressed punctuation, grid indents, right-to-left line ends, endnotes down the page and Arabic's letters side by side where round 26 shows Word's way, as Word does

Word's PDFs of round 26 (word-stops-east-asian3.ts and word-stops-arabic2.ts) show that Word's strict rules keep each small kana and the prolonged sound mark from the start of a line of Japanese, in place of the document's own list, and change nothing in Chinese or Korean; that compressed punctuation leaves justified Japanese and left-aligned Chinese as they are; that indents of part of a cell on a grid that snaps to characters are rounded up line by line, before the margin too, with tabs to their stops; that the space after a line's last right-to-left word takes room beside left-to-right text in a right-to-left run and between right-to-left words in any run; that endnotes after text that runs down the page run down it, and end with their section before text that runs another way; and that Word doesn't kern Arabic's letters in Arial and Times New Roman, every pair being as wide as its forms to 8 thousandths of an em. The layout follows each, and keeps a narrowed stop where a case is still open: half-width small katakana and the document's own lists beyond the strict list, distributed Japanese and justified or distributed Chinese and Korean with compression, indents a character or more before the margin, endnotes from a section followed by one that runs as it does before a change of direction, and Calibri's Arabic, which Word kerns by pairs of glyphs.

* docs: say Word doesn't kern Arabic's letters side by side in the fonts of the tables, and spell tatweels

The fonts paragraph of docs/usage/layout.md still said Word kerns them in Arial, Times New Roman and Cambria by pairs not yet known, so only Courier New's Arabic is laid out, which round 26's AR4 PDF showed to be wrong, and the probe README's ignore list lacked tatweels, which failed CSpell.

* fix: fail the Arabic kerning reader on a PDF without its probe, or a paragraph without its 42 words

Otherwise a PDF with no AR4 labels wrote {} and exited 0, and the checker reported nothing.

* fix(layout): measure Arabic's letters in their joined forms as drawn too, with ligatures or kerning on

measureTextWidthAsDrawn measured each Arabic letter in its isolated form where measureTextWidth has the forms the letters beside them join them in, so a word of Arabic in Arial with ligatures on, which no longer stops, was nearly twice as wide as Word draws it. It now takes the joined widths by each glyph's index among the characters, as the plain measurement does.
2026-10-06 21:30:57 +01:00
Dolan 0c0f1f07b9 feat(layout): lay out accents sized to their letter, cramped lower limits, spaces beside brackets, sums in a script's script, pre-scripts, phantoms, boxes and centred equation arrays, as Word's round 26 shows (#3725)
Word's PDFs of the round-26 probes (word-stops-equations3, word-stops-equation-small2) settle most of the equation stops #3702 left: roots, brackets and braces narrowed to what the PDFs still leave between two sizes, accents over a letter sized to fit it where the MATH table attaches them, superscripts in lower limits cramped, TeX's spaces beside brackets and bars, more symbols' classes, a sum in a script's script, equation arrays without ampersands centred and alignment marks left as they are, boxes struck through, phantoms without their width, ascent or descent, pre-scripts, and small fractions with displayed equations' defaults on. A scripts box now carries its base's first glyph for kerning and its last script's italic correction, which an accent leaves out. A second ampersand in a row still stops, with the sides of a box and transparent phantoms where Word's way isn't settled; word-stops-equations4.ts probes those for the next batch.
2026-10-06 21:16:24 +01:00
Dolan 1f172c6939 feat(layout): lay out phonetic guides, tabs, soft hyphens, squeezed lines, run borders, fitted text and grids above footnotes where round 26 showed Word's way, as Word does (#3729) 2026-10-06 21:10:40 +01:00
Dolan bc3180cfa6 feat(layout): keep a cell's text from the border Word draws before two that meet, and an exact row's space between cells inside its height, as Word does (#3727)
* feat(layout): keep a cell's text from the border Word draws before two that meet, and an exact row's space between cells inside its height, as Word does

Word's PDF of word-stops-tables3 (round 26) settled what the lay3-tables
probes left open. The text of the cell before two borders of different
styles that meet is kept from the border Word draws, by Word's weights for
their styles, which are back (BT7a to BT7c); where Word draws the wider, or
the next cell's over none, the layout stops, unless the cell's margin
settles it. A row of an exact height with space between cells has its own
space and its cells' borders inside its height, and only the table's edge
outside (TS16a), and a border of 3 points above an exact row is inside it
(TS16b). Half of each outer border of 3 and 6 points is inside the room a
table sized to its text fills (BT8a, BT8b), and a merged cell's text breaks
between its rows as a paragraph's lines do (RW21), as the layout had them.
A long word in cells merged across columns still stops: Word's six more
cases (LW9a to LW9f) show the word's excess handed to the columns one by
one, each taking a share of what is left, but the shares of columns that
differ fit no rule yet. word-stops-tables4.ts probes what would settle it,
for the next batch.

* ci: rerun the checks after GitHub's code scanning upload failed
2026-10-06 21:05:19 +01:00
Dolan 28defb1aac feat(layout): keep text at least half a point from a floating table, and draw the characters a run's hint moves to its East Asian font in it, as Word does (#3724)
Word's PDFs of round 26 showed the text beside a table that text flows around 0 to 10 twips from it starting where it does with no distance, and 15 twips as given (word-stops-float-distance.docx FD1a to FD1f); curly quotes, dashes, an ellipsis, a degree sign and the like in the East Asian font of a run with the hint for East Asian text, in Chinese, Japanese and English (word-stops-run-fonts.docx HA1a to HA1c); accented letters in the high ANSI font given alone or beside Courier New (HA2a, HA2b); the scripts the run-font rules leave out in the high ANSI font, or in the fonts Word falls back on from either (HA3a); and Hebrew and Arabic in the font for ASCII (HA3b). The layout follows each, and stops in a run with the hint only where the PDFs don't settle the font: an East Asian font that isn't one, Latin Extended letters outside Chinese, a combining mark, a right-to-left run, and a block the rules leave out in a run whose two fonts differ.
2026-10-06 20:14:03 +01:00
Dolan 76cde3d6a8 feat(layout): lay out VML pictures at their shapes' sizes, and a picture of one pixel at 33 points, as Word draws them (#3723)
Round 26's Word PDF of word-stops-vml-pictures2.docx (VM30a to VM30h) showed Word draws a VML picture (v:imagedata) at its shape's size, and the one-pixel picture of the first batch 33 points square whatever its shape, which VM20 had read as Word's way with every picture. A picture in the line is now a box of its shape's size, with its pixels read from its PNG, JPEG, GIF or BMP file through its part's relationships, 33 points at most across and down for a picture of one pixel. A shape of a VML shape type has the type's attributes where it gives none of its own, so Word's type for pictures gives them no outline, which also takes 0.72 points out of an object's picture's line. The layout still stops at a picture placed on the page that text flows around, one drawn past 33 points a pixel that isn't the one-pixel case or has a resolution of its own, one with no size, and one whose image isn't in the document or isn't read; word-stops-vml-pictures3 probes those for the next batch.
2026-10-06 20:08:49 +01:00
Dolan ee71db8433 fix(layout): keep text half a point from a floating table with no distance, and draw characters past ASCII in the run's high ANSI font, as Word does (#3712)
* fix(layout): keep text half a point from a floating table with no distance, and draw characters past ASCII in the run's high ANSI font, as Word does

Word's PDFs of round 25 showed the text beside a table that text flows around with no distance from the text starting 10 twips from its room (CN9, CM10), where the layout's model put it at the room's edge, and curly quotes in a run given SimSun for ASCII alone drawn in Calibri, the document's high ANSI font (CN10c, FE2c). Each of a run's fonts is now read on its own, with the high ANSI font for the blocks ECMA-376 17.3.2.26 gives it; the layout stops at characters the run's hint for East Asian text may move to the East Asian font, at scripts the rules leave out in a run whose two fonts differ, and at a distance under half a point.

* fix(layout): keep a mark in the font of the character it is on in a list number's one font

singleFontOf classified a combining mark on its own, as a character of the high ANSI font, where spansOf keeps it with the character it is on, so a list number such as a digit with an accent stopped as one of characters of both fonts.
2026-10-06 02:28:41 +01:00
Dolan c2816f8d20 feat(layout): lay out footnotes and endnotes, header pictures, cell spacing, header rows and tabs where round 25 shows Word's way, as Word does (#3709)
* feat(layout): lay out footnotes and endnotes, header pictures, cell spacing, header rows and tabs where round 25 shows Word's way, as Word does

Word's PDFs of the round-25 probes settle the cases docx/layout still
stopped at in notes (word-stops-notes2, word-stops-note-numbers, the
word-stops-endnotes-* documents, word-notes-across-pages and
word-notes-final-table) and around header pictures, contextual spacing in
cells, header rows and tabs (word-stops-edges). Where a case stays open,
the stop is narrowed to it.

* fix(layout): keep the space a cell's own blocks leave out when its table's edges leave out more

A paragraph after a table in a cell is compared with the end of the table's last row, which leaves out its
space before. The pass for the table the cell is in replaced what it left out with its own, so the paragraph
kept that space.

* fix(layout): lay out the endnotes of a section with no blocks of its own after it

Where the settings put endnotes at the end of each section, those of a section that suppresses its own go
after the next, which can have no blocks of its own, as its paragraphs are hidden. They weren't laid out at
all; now they go after the section before's last block, before the next section's first.

* docs(layout): put two doc comments back above their functions, and say what leftOut covers

* fix(layout): stop at more than 4 columns of footnotes, and don't make them

A document's w15:footnoteColumns can ask for any number of columns, and
each was made before the layout stopped. Word's Footnote and Endnote
dialog offers up to 4, so more stop, as not yet seen in Word, and the
section has no columns of footnotes to make.

* fix(layout): find where each section's endnotes go in one pass back

A section that suppresses its own endnotes puts them at the end of the
next that doesn't, and that was followed one section at a time, again
for every endnote. A long run of such sections overflowed the stack.
Each section's end is now found once, from the last section back, and
only where the settings put endnotes at the end of each section.

* fix(layout): lay out the endnotes of sections before the first block

Endnotes went after each body block, for the sections up to the next
block's, so those of sections before the first block's, whose paragraphs
are all left out as hidden, were never laid out, nor were any where the
body has no blocks at all. They now go before the first block, or alone.

* test(layout): cover a header's text box placed against its line or the page

The stop kept for a text box that text flows around in a header, placed
against its paragraph or line, is now tested for one against its line, and
one against the page is read as a drawing, as a picture there is.

* fix(layout): stop at endnotes in columns with no separator above them

The endnotes' columns start below their separator, so with an empty
separator note, which leaves none, a lone endnote at the document's end
left no start for the columns it ends in, and evening them out threw.
Word has been seen with endnotes in columns only below a separator, so
that stops, and guessing, the endnotes are laid out without evening out.

* docs(layout): say paragraphs kept before header rows go on only to the next page

The table section said the paragraphs kept with the next before a table
go on with its header rows to the next page or column. They go on to the
next page; in columns, or from the top of a page, the layout stops.

* fix(layout): cut a table row in a footnote across many pages in time

The search for where a footnote's table row is cut started from the rest
of the row and went up a line at a time, filling every earlier part of
the row again at each try, so the time grew far faster than the row: a
row of 400 lines across 7 pages took 4.7 seconds. Where the rest doesn't
fit, no part taller than the page does, so the search goes on from the
page's height, and the parts filled on a page are kept for the tries
after, filled afresh on each page as their lines may hold its number.
The cuts are the same: that row now takes 0.2 seconds, and one of 2,000
lines across 34 pages 3 seconds.

* fix(layout): stop at a left tab past the end of a later line only with a hanging indent

A tab to a left stop past the end of the line at the start of a later line
of a paragraph with a first line indent stopped, though that line starts at
the left indent, as TA9a's lines do, which Word put on a line of their own.
The stop is kept for the first line there, and for any line of a paragraph
with a hanging indent.

* fix(layout): find a line's footnote that starts on the next page afresh each time it is tried

The footnote of a line at the top of a page that starts on the next page,
after the line's others, was kept across the tries of the line, and a try
after a drawing was left out, a table placed or a column moved on to could
fit the line with all its footnotes, but still put the last on the next
page. It is now found again on each try.

* fix(layout): fill a footnote row's parts before its last in a loop

The parts of a table row in a footnote before its last were filled again
by recursion, once for each page the row had gone on to, after the parts
kept for a page were let go at its end. A row across thousands of pages
would run out of stack. They are now filled in a loop, and kept by the
rooms they were cut at one after the other rather than by a key that grew
with each page. The cuts and their times are the same.
2026-10-06 01:51:02 +01:00
Dolan 88732990f7 feat(layout): lay out compatibility modes, suppressTopSpacing, booklets and HTML divisions where Word's round 25 settled them, as Word does (#3704)
* feat(layout): lay out compatibility modes, suppressTopSpacing, booklets and HTML divisions where round 25 settled them, as Word does

Word's PDFs of round 25 (word-stops-compat2-15, -14, -12, -top-spacing2, -booklet2, -divisions and -fe-layout2, committed
in scripts/layout-probes/stops2 with their documents) settle most of what the earlier batch left open:

- Compatibility modes 14 and 12: a page break at the end of a paragraph and distributed lines as in mode 15 or as
  justified ones, no ligatures without enableOpenTypeFeatures, a tab past the end at its stop with the rest of the
  paragraph on that line, gaps beside drawings and frames down to 50 and 100 points, indented tables, tables in cells and
  tables widened for a long word, floating tables with their text at their place; in 12 and 11, East Asian text of no
  language broken only at its spaces, and a text box's outline taking no room in its line.
- suppressTopSpacing: at least a height X leaves out X less 9.6 points, whatever the line's height; a paragraph's later
  line, the space before a section's first paragraph and a table's cells are followed, multiple spacing and a line below a
  border left as they are.
- Folded booklets laid out as the section's pages; paragraphs in HTML divisions laid out from the web settings.
- useFELayout stops only at East Asian text beside other text with automatic spacing on.

It keeps stopping, narrowed, where Word hasn't shown its way, and word-stops-compat3.ts writes probes for those.

* fix(layout): measure an older mode's narrow gap beside a drawing within the paragraph's indents

The stop at gaps beside drawings narrower than Word 2010 was seen putting text in measured the whole gap, so a gap a
paragraph's left indent covers, which takes no text anyway, stopped the layout, and one an indent narrows passed by its
whole width. It now measures the room the indents leave in each gap.

* fix(layout): measure an older mode's gaps of a first line's row with its first line indent

When a paragraph's first line indent leaves the first gap beside a drawing no room, its first line may go in a later
gap of the row, which the stop at narrow gaps measured without the indent. Those gaps are now measured with it, so the
layout stops where the indent would leave less room than Word was seen putting text in. Which gap Word indents then
hasn't been seen, so the lines are laid out as before.

* fix(layout): measure only the gap that takes a first line with its first line indent

The last fix measured every later gap of a first line's row with the first line indent, so a gap that takes the second
line, after a first gap the first line fits in, was measured narrower than its room and could stop the layout. Only the
first gap the indent leaves room in, which the first line goes in, is measured with it now.

* fix(layout): let no hanging indent widen an older mode's gap beside a drawing

A first line indent less than none moved the room the stop at narrow gaps measured left of the gap, into the drawing's
room, so a gap of 80 points beside a drawing passed as 105. The stop now measures no further left than the gap itself.
Where Word starts a first line that hangs past a drawing's edge hasn't been seen, so the lines are laid out as before.

* docs(layout): say a tab line's reach is from where the paragraph's lines start, and test both sides of it

The comment called the 941.4 points Word was seen keeping text after a tab on its line "past the margin", though a
line's positions, as its tab stops, are from where the paragraph's lines start: CN5a's line ran to 18827 twips from
there, past the margin's 9026. The test now checks a line just within it as well as one past it.

* fix(layout): count only frames beside a line's row in an older mode's narrow gaps

A frame anywhere on the page whose edge was where a gap's is made the gap one beside a frame, and its stricter least
width, though the frame was lower or higher on the page. Only frames beside the line's row count now.
2026-10-06 01:11:28 +01:00
Dolan c717e7739f feat(layout): lay out grid indents, Japanese line rules and endnotes after other grids, and measure Arabic's joined forms, as Word does (#3705)
* feat(layout): lay out grids and East Asian rules round 25 settles

* feat(layout): measure Arabic in the forms Word joins it in, and end right-to-left lines as Word does

* test(layout): probes for what round 25 left open, and coverage of the round's cases

* perf(layout): look past a word for a right-to-left one only after one

* test(layout): cover a grid line's own stop

* fix(layout): stop at kerned Arabic and unseen right-to-left line ends, as Word's PDFs show

* docs(layout): say which fonts' Arabic Word kerns, apart from Courier New's

The sentence read as if Courier New's Arabic were the kerned one; it is the one Word doesn't kern. Calibri's Arabic is kerned too, as word-stops-arabic AR1 showed.

* refactor(layout): rename the right-to-left lookahead's names beside the tab code's

#3707's code for a word after a tab declares following and at in the same loop, which the lookahead's names shadowed.

* fix(layout): kern a letter on a grid that snaps to characters with the one before it in another run of its font

widthOf measures pieces of the same font together, so a pair across them is kerned; snapped started each piece afresh, so a word split across runs of one font took the cells it needs unkerned there. It now keeps the letter before across such pieces, but not after a soft hyphen's break (apart).

* fix(layout): lay out lam and alef alone in Arial, Times New Roman and Cambria, as one glyph Word doesn't kern within

unknownArabicKerning took lam and the alef after it as two letters side by side, which Word kerns, but Word joins them into one glyph, the ligature, whose width word-stops-arabic AR1 measured, so a word such as "la" alone stopped the layout for nothing.
2026-10-06 00:16:18 +01:00
Dolan bb6ffa3544 feat(layout): lay out table borders, space between cells, text running up cells, merged cells across pages and tables of a share of the width, as Word does (#3708)
* feat(layout): lay out table borders that meet, art borders, rows of their own space and borders, and borders of no width, as Word does

* feat(layout): lay out text that runs up or down a cell in tables sized to their text and rows of only it, as Word does

* feat(layout): lay out tables of a share of the width that their words don't fit, with rows that give a column different widths or start past it, and leave half their borders outside their columns, as Word does

* feat(layout): lay out table styles that keep rows whole, tables indented by a share, cells that don't wrap or fit their text in tables sized to it, and exact row heights with borders, as Word does

* feat(layout): lay out the text of cells merged down rows across pages, rows taller than a page with merged cells, footnotes and header rows, and rows taller than a column, as Word does

* docs(layout): say how tables' borders, space, rows across pages and text running up lay out, and list the round-25 probes followed

* test(layout): probe what the round-25 table probes left open, for Word's next batch

* fix(layout): keep the table's top border above a row below a header row taller than a page, which isn't repeated

* fix(layout): give a row of only a cell of text running up, without a paragraph, no height

A cell may hold only range marks, as a bookmark, with no paragraph, and one whose text runs up or down, in a row of only
such cells, failed to measure its last paragraph's mark. It needs no room, as a cell of nothing across the page.

* refactor(layout): tell art borders from lines in one place, checked against the schema

A run's, a paragraph's and a table cell's borders each told an art border from a line by its style not being one of the
lines they know, with three copies of the widest art border. They now share isArtBorder and WIDEST_ART_BORDER, and a test
reads ST_Border from wml.xsd to check that its lines, from nil to inset, are those with widths, so the rest of its styles
but custom, from apples on, are its art borders and no line is taken for one. A table border's room now comes from the
lines a run's and a paragraph's know, which are the same styles.

* test(layout): probe the border above a row of an exact height with space between cells and a thick border together

TS16a has space between cells with a border of half a point, whose 10 twips inside or outside the row's height Word's
PDF shows only just, and TS16b a thick border without the space. TS16c has both, a border of 3 points and space of 40,
so Word's next batch shows plainly where the border goes in a table with space between its cells.
2026-10-05 23:57:19 +01:00
Dolan f56f18a336 feat(layout): lay out sizes in other units, soft hyphens, tabs, run borders and fitted text at more of their stops, as Word does (#3707)
* feat(layout): read a run's size in any unit at whole half-points, rounded down, as Word does

* feat(layout): lay out a hanging indent in twips from a left indent in characters, as Word does

* feat(layout): end a box of borders at the empty paragraph that ends a section, as Word does

* feat(layout): move a line whose multiple spacing would go into the footnotes to the next page, as Word does

* feat(layout): break at a soft hyphen whose hyphen fits, and take a shorter part as it is over a longer one squeezed, as Word does

* feat(layout): squeeze a justified line with en spaces by no more than a quarter of its ordinary spaces, as Word does

* feat(layout): take a tab on to the next line with a word that doesn't fit after it, and line up text at stops past the end with any indent, as Word does

* feat(layout): measure kerned text either side of a soft hyphen apart, as Word does

* feat(layout): give a single run border with a shadow or drawn as a frame its room, as Word does

* feat(layout): lay out a picture in a border of its run with its border's room, as Word does

* feat(layout): lay out text fitted to a width as one box of that width, as Word does

* fix(layout): break a word with soft hyphens after a tab at its soft hyphen, as Word does

* docs(layout): say what Word showed of phonetic guides, which still stop the layout

* test(layout): cover a drawing placed on the page in text with a border, guessing

* refactor(layout): name the tab stop's state as lint asks

* docs(layout): say what the layout now follows of soft hyphens, tabs, borders, fitted text, sizes and indents

* docs(layout): commit Word's PDF of word-stops-text2, and say what it settled

* test(layout): spell the kerning probes' letters

* feat(layout): stop at text fitted to a width wider than its line after other text, and probe what word-stops-text2 left open

* test(layout): cover text fitted to no width

* docs(layout): end the sentence on fitted text before two lines in one

The sentence added for fitted text ran on into the next one without a full stop.

* fix(layout): put SH18e's second soft hyphen between the f and i of efficient

The probe is for ligatures across f-f and f-i boundaries, and splitting efficient as ef|fi|cient tested f-f and i-c instead.

* fix(layout): end a box of borders at the paragraph that ends a section after a table

After a table, the empty paragraph that ends a section takes a line, and sharesBorders still joined its box to the next section's paragraph, whose own box started after it, so its bottom border took no room.

* docs(layout): wrap the stops2 README's paragraph on the next batch
2026-10-05 23:33:40 +01:00
Dolan 0e7b7f75d4 feat(layout): lay out VML text boxes, shapes and objects, and more of floating tables, frames and pictures, as Word does (#3711)
* feat(layout): lay out VML text boxes, shapes and objects, and more of floating tables, frames and pictures, as Word does

Word's PDFs of round 25 (word-stops-floats2 and the seven VML probe documents) settle most of the stops of lines 12, 13,
14, 21 and 36 of the stops report. VML text boxes with insets, outlines or heights of their own, shapes with outlines,
groups, embedded objects and VML in a header's line are laid out as Word drew them, and so are pictures lined up
inside or outside down the page, floating tables and frames with no anchor across the page, two tables that may not
overlap with no room on the right, lines whose rooms take none of their words, kept headings with pictures or
floating tables, floating tables before a table that moves on, broken with header rows, or with borders between
rows only, floats and frames in endnotes, footnotes beside a picture, and frames with borders and a distance. VML
pictures still stop, as Word drew every one of 33 points or more 33 points square. Word 16 for Mac won't open a text
box in a text box.

* fix(layout probes): read curves, turned images, forms and next-line text in the shape reader, and give its command

CodeRabbit's review of #3711: the reader's bounds now take in a curve's extrema, not only its end; an image's box is
that of all four corners of its unit square, so a turned image's is its turned box; a Form XObject is said to be one
rather than called an image; the next-line text operators (TL, TD, T*, ' and ") move the text position; and the README
and the script's header give the command to run it with.
2026-10-05 23:03:00 +01:00
Dolan f269792774 feat(layout): lay out list numbers, hidden paragraph marks and tracked changes at more of their stops, as Word does (#3703)
* feat(layout): lay out list numbers, hidden paragraph marks and tracked changes at more of their stops, as Word does

Round 25's PDFs of word-stops-lists, -list-definitions, -picture-bullets,
-hidden, -hidden-edges, -tracked, -tracked-edges and -moves settle most of
the stops of the second inventory's lines 16 to 18, and show a level aligned
both laid out wrongly without stopping:

- Lists: a level Word leaves out (aligned both, or showing a level its list
  doesn't have), a centred number with its space, a number's emphasis marks
  and raise, its ascent with multiple spacing, the tab after a right-aligned
  number, a line of only a number, no automatic spacing between a list's
  levels, and Thai and Hindi words from 1 to 5.
- Hidden marks: paragraphs joined in the first one's indents, tab stops and
  borders, line by line in their line spacing, across a content control's
  end, sized as one in a table sized to its text; notes of hidden references
  laid out and counted; keepNext and boxes past hidden paragraphs; a hidden
  section break before a section alike on its page.
- Tracked changes: deleted pictures, tabs, breaks, note references and marks
  counted in sized columns as written; deleted endnote and moved note
  references counted; moved paragraph marks joined; deleted section breaks
  leaving their section to the next; deleted rows' notes counted, and rows
  around a deleted one in a spaced table as without it.

Commits the probes and Word's PDFs, and word-stops-lists2.ts and
word-stops-marks2.ts for what is still unsettled.

* docs(layout): say Word opens the page format probes but couldn't save them as PDFs

* fix(layout): stop after a left-out list level only at the levels it may have started again

A paragraph at a level Word leaves out marked every level below it as
uncertain until a level at or above it was counted, so the second of
several sub-items after a left-out heading stopped the layout, though it
is certainly 2. Only the levels that had numbers when the left-out
paragraph came may have been started again by it, and each is known once
it is counted, or started again by a level above it.
2026-10-05 22:38:46 +01:00
Dolan 2d1d6370dd feat(layout): lay out more of the equations Word builds up, and follow its maths settings, as Word does (#3702)
* feat(layout): lay out more of the equations Word builds up, and follow its maths settings, as Word does

Word's PDFs of the round-25 probes (word-stops-equations2, word-stops-equation-limits, word-stops-equation-small and
word-stops-equation-spacing) settle most of the equation stops they were written for:

- scripts' sizes are 73% and 60% of the equation's rounded down to the half point, at any size
- a superscript in a cramped part is raised by the MATH table's cramped shift, and a subscript isn't cramped
- fractions, sums and functions are spaced as TeX spaces them beside letters, digits, punctuation and each other, and
  brackets as the brackets they are
- roots' signs, brackets, accents (flatter over a tall part) and braces are the sizes Word draws, and matrices' and
  equation arrays' rows are spaced as Word spaces them
- boxes, equation arrays, phantoms, braces of their own sizes, fractions beside other parts and in displayed scripts,
  sums in scripts, bold and double-struck digits, and more symbols are laid out
- an equation displayed beside text, or alone after its list's number, is built up as in a line of text
- the maths settings' places for limits, displayed equations' defaults and space between equations are followed

Where Word's PDFs leave a size between two, or haven't shown a case, the layout still stops: equations too long for
their line, normal text, and the cases around what was settled.

* test(layout): probe the equations Word's round-25 PDFs leave between two sizes or haven't shown, for the next batch

* refactor(layout): measure an equation array row's part before its ampersand with settled
2026-10-05 20:54:57 +01:00
Dolan 6470849dca feat(layout): measure the bold Word makes itself, letters a font lacks and more characters in Office's fonts, as Word does (#3706)
* feat(layout): measure the bold Word makes itself, letters a font lacks and more characters in Office's fonts, as Word does

Round 25's font probes, saved from Word 16 for Mac, settle what Office's fonts still stopped at:

- word-stops-office-fonts MB1 to MB3: the bold Word makes itself for Calibri Light, Franklin Gothic Book and Impact
  draws each glyph 20 thousandths of an em further on than the regular at 8 to 72 points, the spaces as wide, kerned
  and joined as the regular, its lines as tall. The width tables now have it, from the generator.
- FB1, FB2: the font Word draws a letter a font lacks in doesn't depend on the run's language or East Asian font, and
  the line takes its ascent and descent. The width tables say which face of the tables Word draws each such letter in,
  where it is Calibri, Cambria, Arial, Times New Roman or Tahoma, and a line makes room for it.
- KL1: text with ligatures isn't kerned in a font kerned by its kern table alone, whichever ligatures it has.
- word-stops-more-widths-office and word-stops-more-italic-widths: Hebrew, Thai, box drawing, shapes, symbols and
  dingbats in Office's other fonts and in the five fonts' italics, as Word draws them.
- DS and word-stops-font-heights: font files' lines are as tall as their hhea tables make them, and go their descender
  below the baseline. Font files whose GPOS table doesn't kern Latin text are kerned by their kern table, and not with
  ligatures.

MB4 showed Word drawing Pacifico, which the document embeds, in Office's own copy of it, so bold text in a font given or
embedded without a bold face still stops.

* fix(layout): report KL lines the office-fonts reader doesn't find, rather than stopping

word-stops-office-fonts.py indexed the kerning of a KL1 line, and the words of KL2's, without checking it found the line
whole, so a PDF without one, or with one Word broke, stopped the reader before KL2 and DS. They now print "not found",
as MB does.
2026-10-05 20:15:23 +01:00
Dolan 90ca7b93ec feat(layout): lay out document grids, text down the page, Thai and imported documents, and measure more characters, as Word does (#3700)
* feat(layout): lay out document grids and East Asian settings at more of their stops, as Word does

* feat(layout): lay out text that runs down the page at more of its stops, as Word does

* feat(layout): measure Hebrew, Thai, box drawing, shapes, symbols and dingbats as Word lays them out, and Thai justified for it

* feat(layout): lay out imported documents whose formatting is kept, and whose own styles' defaults give no font or size, as Word does

* fix(layout): stop at endnotes that a section of another grid or direction follows, as Word ends them with their own section

* feat(layout): measure the Arabic-Indic and Devanagari digits as Word lays them out, as list and page numbers write them

* docs(layout): say what document grids, text down the page, Thai, imported documents and more characters lay out as, and list the batch's probes

* test(layout): probes of indents on grids, endnotes before another grid or direction, Japanese strict rules and compression, and Arabic's joined forms, for Word's next batch

* fix(layout): stop at an imported document whose formatting is kept that ends in a content control

Word gives the last paragraph of an imported document whose formatting is kept none of its space after. Where that
paragraph is in a content control or custom XML, the layout took off the space after of an earlier paragraph at the top
of the imported body, or threw where there was none. Which paragraph Word takes it off there hasn't been seen, so the
layout stops rather than guessing.

* fix(layout): read an imported document's w:matchSrc as on or off

w:matchSrc is an on/off property (CT_OnOff), so a w:val of 0, false or off turns keeping the imported document's
formatting off, and its paragraphs take the document's styles of the same names. The layout kept its formatting whenever
the element was there.

* docs(layout): say that an imported document whose formatting is kept stops the layout where it ends in a content control

* docs(layout): say in the imported documents probe what Word's PDF of it showed, and what still stops

* docs(layout): say which fonts Hebrew, Thai, bullets and symbols are measured in, and where they stop the layout

* test(layout): probe Hebrew, Thai, bullets and symbols in Office's other fonts and in italic, for Word's next batch

* fix(layout): stop at East Asian or right-to-left text in an imported document's notes where its styles give no font

Where an imported document's own styles give its Latin text Word's own font, the layout stops at East Asian or
right-to-left text in it, as which font Word gives that text hasn't been seen. It looked only at the imported body, so text
in its footnotes and endnotes, which are merged with the document's, went on without the stop.

* docs(layout): leave Cambria's and Times New Roman's Devanagari digits out of the characters measured as Word draws them

* docs(layout): give GR12's columns as the probe writes them, 2000 and 6526 twips
2026-10-05 17:49:04 +01:00
Dolan 227f9179f9 feat(layout): lay out floating tables, text frames and drawings in more of the ways Word does (#3687)
* feat(layout): lay out floating tables, text frames and drawings in more of the ways Word does

Follows Word's PDFs of word-stops-floats.docx and word-stops-drawings.docx
(lines 12, 13 and 14 of the stops report), and stops more narrowly where they
don't settle what Word does. Splits the VML probe into documents Word can open,
and adds word-stops-floats2.ts for what is left.

* fix(layout): stop, rather than throw, where a drawing's paragraph goes on to the next page outside placing a block, and find the floating tables around a block without copying the blocks

* docs(layout): leave out a floating table with nothing after it in its section, which no document has

* fix(layout): stop at once where the text before a table moves it on from the text frame anchored at its top

A frame placed from the page's top beside the text before its table is pinned to the page,
and when that text then went on to the next page, the frame's anchor named the table, which
the page laid out again without it didn't move on. The page was laid out again until it gave
up as drawings that don't settle. Where Word puts the frame then isn't known, so the layout
stops there as it does where the table moves on.

* fix(layout): read the empty paragraph Word adds after a floating table at the end of the body on its section's grid

It was read without the section's document grid, so its line took the font's height rather
than the grid's pitch, as the section's other paragraphs take it.

* docs(layout): say which text frames at the end of a section still stop

Those before the empty paragraph that ends a section are laid out; those at the end of the
document, or whose own paragraph ends the section, still stop.

* docs(layout): keep one comment on endsAfterTable, with what Word showed for both cases

* fix(layout): take a sliver of room beside a drawing as none, not as a narrow room

Edges worked out in different ways can leave a room a fraction of a point wide beside a
drawing as wide as the column. Taken as a room narrower than 18 points, the layout stopped
there, where before it moved the line below the drawing, as it does with no room.

* test(layout): name the probe whose marker is missing in word-stops-floats2's injections

A missing CO1b frame made the slices cut the document at the wrong place. Each injection now
throws, naming its probe, and they are separate, so ONLY leaves one out without the other.

* test(layout): throw where word-stops-vml's VM26b text box is missing, as its other injections do

A missing VM26b box made listItems slice document.xml at the wrong place, which ONLY's
swallowed errors would have written out.
2026-10-05 16:45:38 +01:00
Dolan a5b5351b54 feat(layout): lay out text that runs up or down a table cell where its column's width can't move a line, as Word does (#3680)
* feat(layout): lay out text that runs up or down a table cell where its column's width can't move a line, as Word does

Word's PDF of word-stops-vertical-cells.docx (lay-stops2's batch) settles
part of the work's line 5:

- In a table sized to its text, Word makes the column of text that runs up
  or down a cell about a line of each paragraph wide, however long its text,
  and sizes it by the text, not the mark (TV1, TV5). How wide exactly has
  been seen only of Calibri, so the layout lays it out where the other cells'
  widths don't depend on it, and still stops where they do: in a table
  narrowed to the room or fitted to its width, in a table cell, or that text
  flows around, and in a cell given less than about a line of it.
- A long word in it widens nothing (TV2).
- A row with it breaks across pages as other rows do, the text on the page
  of its first part (TV3).
- A picture in it leaves its row a line of its mark (TV5c), but a mark larger
  than its text doesn't make the row that tall (TV5b), which now stops.
- Text down with East Asian characters upright (tbRlV, tbLrV) is laid out as
  text running down, and across with them on their side (lrTbV) as text
  across (TV6).

Guessing past a table in such a cell no longer throws (TV5d).

word-stops-vertical-cells2.ts is the probe for the next batch: other fonts,
borders and paragraphs, and the row of only such a cell.

* fix(layout): size text running up or down a cell by its line size and page fields, and stop at a text box in it

A superscript's or subscript's line is its text's (TV4), as the reader
already compares it with the mark, and the numbers of PAGE, NUMPAGES and
the other page fields are text of their runs' size, so the column of a
cell whose text runs up or down is sized by those, and a field smaller
than its mark stops as text smaller than its mark does. A text box in
such a cell, which pagination lays out as tall as its text, hasn't been
seen in Word, so the layout stops there.
2026-10-05 16:09:55 +01:00
Dolan f03253eb22 feat(layout): lay out equations Word builds up, as Word does (#3685)
* feat(layout): lay out equations Word builds up, as Word does

Lay out the equations Word builds up (fractions, scripts, roots, sums and
integrals with their limits, brackets that grow, matrices and cases,
accents, bars, functions and limits, and braces) by the rules of Cambria
Math's OpenType MATH table, with the font's own widths, ink and
constants, as Word's PDFs of word-stops-equations, -equation-settings
and -equation-font show. Each probe's width in its line of text is
Word's to within 0.03 points and its line's height within Word's own
drawing grid, but two roots, which are within 0.1 points.

What of Cambria Math the layout needs is generated from Word's own copy
of the font by scripts/generate-cambria-math.ts into
src/layout/cambria-math.ts, which replaces the widths read from Word's
PDFs (equation-widths.ts) and the table of Cambria Math's own widths
within 1.5 thousandths of an em, the integrals with their italic
correction, and ◇, which Cambria Math hasn't, stops.

The layout keeps stopping where Word's PDFs leave the result unsettled:
scripts in sizes other than 11 points, superscripts in cramped parts,
brackets between two sizes, matrices whose rows are too tall to be
single spaced, thin spaces beside fractions, brackets, sums and
functions, boxes, normal text, equations too long for their line, maths
fonts other than Cambria Math, margins of displayed equations and space
between equations side by side in one m:oMathPara. Guessing past a stop,
an equation alone in its paragraph is laid out displayed first.
word-stops-equations2.ts writes the probes that settle them, each
validated against ooxml-schemas/.

* fix(layout): stop at a digit in a bold run or another alphabet, which Word hasn't been seen drawing

A digit in a bold or bold italic run was laid out as the plain digit, though Word draws a bold run's letters in
Unicode's bold alphabet (word-stops-equations.docx EQ19), which has bold digits too, wider than the plain ones. No
probe has shown which Word draws, so the layout stops there, as it does for a digit in another alphabet, and
word-stops-equations2.ts's EQ45 asks Word. The alphabets' unused first digits are gone.

* fix(layout): lay out an equation in a line of text in a numbered paragraph, stopping only at one alone after its list's number

* test(layout): probe an equation displayed (m:oMathPara) alone after its list's number too, as EQ38d
2026-10-05 15:41:50 +01:00
Dolan 1fb1aa03f9 feat(layout): number and place footnotes and endnotes, and write page references in words and pictures, as Word does (#3682)
* test(layout): split the numbers and marks probes into documents Word opens

Word 16 for Mac couldn't open word-stops-numbers.docx or word-stops-marks.docx. Write the
moves as Word writes them, with range marks and a footnote of its own at each end, start the
section past page 32767 from 32767, write the picture bullet as Word does, and split each
probe into smaller documents of related cases.

* feat(layout): number and place footnotes and endnotes, and write page references in words and pictures, as Word does

Word's PDFs of word-stops-notes, word-stops-endnotes and word-stops-fields showed how it numbers footnotes on each
page and from a later section's own number, leaves a footnote with a mark of its own uncounted, puts footnotes just
below the text, puts the rest of a footnote on a page of its own before a page break, numbers the pages of a rest
before a continuous section numbered afresh, ignores a section's own place for its endnotes, leaves out the text of
an endnote separator, and writes CardText, DollarText, OrdText, Hex and pictures with spaces, decimals and text.

* test(layout): write only the footnotes each of the next batch's notes documents refers to

The kit's footnote() keeps every document's notes and write() puts them all into each document a
script writes after, so the endnote documents of word-stops-notes2 carried the notes documents'
footnotes, unreferenced. Word refused two schema-valid documents this round, so documents for Word
shouldn't carry anything stray. kit.ts is left as the other lanes have it.

* fix(layout): count only a section's own footnotes in its numbers afresh on each page

Where sections numbered afresh on each page share a page, which stops the layout but which a guess
lays out, the number of a footnote counted those of the section before on the page too, though its
comment says its section's.

* test(layout): throw at a missing marker in the marks probes' injections

sectionMark, inControl, deletedRows and the TR1a and HD9b injections went on from the start of
the document when their marker was missing, as it is when ONLY leaves its probe out, and wrote
broken XML where the kit's injections throw, which write skips under ONLY.

* test(layout): take out the footnotes nothing refers to from the page 32768 and fields probes

The kit writes every footnote the script has made so far into each document, so
word-stops-page-32768.docx, which goes to Word in the next batch, carried NF7's
two footnotes with no reference to them. The fields document did too, with a
third footnote mark on each since the numbers document was split. Every
document of the script now keeps only the footnotes it refers to. The committed
word-stops-fields.docx stays as Word opened it.

* fix(layout): count the pages of a continuous section after a footnote's rest on pages of their own

Before a continuous section, the rest of a footnote goes on pages of its own,
and the number of pages of both sections was left blank, as Word counted them
its own way in word-stops-notes.docx NT2b. Word counts the next section's as its
own pages, though: 1 there, and 1 after FN5's rest in word-watertight-notes.docx,
which master wrote and this branch had left blank. Only the first section's,
which leaves out its pages of the footnote, is still left for Word.

* fix(layout): note the guess of a footnote's pages before a continuous section on the first of them

Guessing, the stop for a footnote continued across a continuous section break
onto pages of its own, whose sections' headers and footers differ, was noted on
the page of its reference. What is guessed is which footers the pages of the
footnote have, so it is noted on the first of them.
2026-10-05 15:31:42 +01:00
Dolan 2f42d7df4a chore(layout): probe the table and paragraph borders the layout still stops at, for the next Word batch (#3701)
word-stops-table-borders2.ts writes word-stops-table-borders2.docx (BT1
to BT6), a case for each border stop that word-stops-table-borders.docx
and word-stops-text.docx PB4 left: borders that meet where Word draws
the narrower beside text with small margins, art borders at other
widths, paragraph borders of no width or further than 31 points from
the text, tables with space between their cells breaking across pages,
rows with different space between their cells or space of other types,
and a row's own borders in a table with space between its cells.
2026-10-05 15:10:11 +01:00
Dolan 88aa81b43c feat(layout): squeeze lines, break at soft hyphens, and lay out tabs, borders and run formatting at more of their stops, as Word does (#3688)
* feat(layout): squeeze justified lines and break at soft hyphens as Word does

Word's squeeze limit is 2.015 rather than 2.04 for justified, distributed, Thai-distributed and kashida lines
(word-justify2 K07, K08, K09 and word-stops-tabs JU3). It never squeezes en, em or ideographic spaces (JU1),
squeezes a line with bordered text as any other (JU2), squeezes a soft hyphen's part on as it would a word
(SH10d), breaks a bordered word at a soft hyphen (SH11) and a first part longer than its line at characters
(SH12), and breaks with the hyphen 19.9 twips short of the end (SH13).

* fixup: rename shadowed parts

* feat(layout): line text up with tab stops past the line's end, at decimal stops and in borders as Word does

word-stops-tabs TA3: right, centred and decimal stops past the end at a line's start line the text up with the end.
TA4: centred and decimal stops past the right indent line the text up with the stop. TA6: a number lines up its end,
commas and all (12%, 12, 34). TA7: a box goes on round a tab in it, and bordered text lines up by its box.

* feat(layout): lay out paragraph borders, indents in characters and lines below the page's foot as Word does

word-stops-text PB1: paragraphs whose borders differ only by a between border share a box, with the first's
between border. PB2: the empty paragraph that ends a section takes no room for its borders or automatic spacing.
PB3b: a box ends before a page break. PB5b, PB5c, PB5e: a left indent in characters is in the style's size, a right
one in the mark's, and a first line indent in twips goes from it. PB7b: multiple spacing's room below may go below
evened-out columns. PB8: a larger mark doesn't count in a line of only a picture. word-stops-notes NT13: borders and
automatic spacing take room in a footnote.

* feat(layout): lay out emphasis marks, run borders and negative lengths as Word does

word-stops-text RF20, RF21, RF22: emphasis marks over and under one line take a quarter of it each side, a
quarter of a line with a picture, and line spacing holds them once its room is as much as theirs, with lines
below single spacing scaled. RF23: a bordered long word restarts its box on each line. RF25: art border sizes
are points, spaces wrap at 32, and sizes 0 and 1 are drawn. RF26, RF28: a minus sign is the whole number's only.

* feat(layout): draw two lines in one at half size, and join ligatures beside Latin letters, as Word does

word-stops-text RF30: Word draws two lines in one of Latin text on one row at half the size. word-stops-kerning
KE3: Word joins a ligature beside a Latin letter outside Windows-1252 as beside any other.

* feat(layout): break a kerned word longer than its line where its kerned letters fit, as Word does

word-stops-kerning KE6a: Word measures the letters of a long kerned word on each line together, kerned, so more
of them fit than measured each on its own. One with ligatures, which Word may break inside, still stops.

* docs(layout): what Word's PDFs of word-stops-text, -tabs, -notes and -kerning settled

* test(layout): add the probes of word-stops-text, -tabs, -kerning and -notes with Word's PDFs

* test(layout): check the squeeze limit against word-justify2's K07 and K08

* test(layout): a probe of what word-stops-text, -tabs and -kerning left open, for Word's next batch

* test(layout): cover a bordered footnote in columns, and tabs before a picture

* style(layout): spelling and lint

* feat(layout): lay out tabular figures as wide as Calibri's and Cambria's own, as Word does

word-stops-kerning KE7b, KE7d, KE7f: lining tabular figures in Calibri and Cambria, and old-style tabular ones in
Calibri, are as wide as their default figures. Other forms and spacings still stop.

* fix(layout): stop the word-stops-text2 probe when its bordered picture's marker or run isn't found

borderedPicture used the indices it searched for without checking them, so a missing marker, as when ONLY leaves
RF32b out, or a picture run with properties of its own wrote a corrupt document rather than an error that write
handles, as replaceMarkerRun and injectIntoParagraph do.

* feat(layout): give a left tab stop past the end a line of its own with a first line or hanging indent too, as Word does

word-stops-tabs TA1a, TA1b: with a first line indent of 720 and a hanging indent of 720, Word puts the tab after
"TA1a text" on a line of its own and "after" at the start of the next, as master now does without those indents
(TA8). TA1c, a left stop past the margin in a paragraph indented past it, where "after" doesn't fit: Word put the tab
on the next line, at its stop, and broke "after" there, where docx/layout put "after" whole on the next line without
stopping, so that stops now.

* docs(layout): list this batch's probes in stops2/README.md, and name word-stops-text2's tab probes TA10 and TA11

master's stops2/README.md lists the batch's documents a change has followed, so word-stops-kerning and
word-stops-notes go there, with what the text and tabs probes settled here, rather than in rows of their own in
scripts/layout-probes/README.md. word-stops-edges.ts already has TA9a and TA9b, so word-stops-text2's tab probes are
TA10a to TA10i, and TA11a and TA11b ask whether Word breaks the word after a left stop it doesn't fit after, as in
TA1c, without a right indent past the margin too.

* fix(layout): lay out two lines in one in a run with attributes, such as Word's revision ids

The check for what else is in a run of two lines in one counted the run's attributes, which the reader gives as an
_attr child, as content other than text, so a run Word wrote with w:rsidR stopped the layout.

* docs(layout): give word-stops-text2's SH16j and JU4 probes the spaces they have

SH16j to SH16l have 15 spaces before the soft hyphen, and JU4's first lines 6 en spaces, not 13 and 5. What each
asks doesn't depend on the counts, so the header says what the probes write rather than the probes changing.

* fix(layout): stop at a bordered or automatically spaced footnote that starts on the next page and goes on across pages

A footnote whose least part is taller than a page starts on the page after its reference's, and startPage splits it
through fillNote without splitLast, so its borders or automatic spacing went across pages without the stop splitLast
makes for them.

* fix(layout): line a picture after bordered text up with a right or centred stop, and keep a box open across its tab in content widths

shiftAt added the box's closing room after the last word even when a picture after it had closed the box, which
widthAfterTab counts already, so the text after a right stop ended a border's room before it. measureContentWidths
closed a box at a tab with its border and opened it again after, where the layout keeps it open (word-stops-tabs TA7a),
so a table sized to its text was a border's room wider than its line.

* docs(layout): say what tabular figures in Calibri and Cambria are as wide as

* fix(layout): stop at the empty paragraph that ends a section with the same borders as a paragraph beside it

Word's PDF of word-stops-text PB3a shows bordered paragraphs either side of the empty paragraph that ends a section,
which has none, as boxes of their own, and PB2a shows that paragraph's borders taking no room beside paragraphs without
them. Whether a box of its borders before or after it goes on through it hasn't been seen, and master stopped at any
borders on it, so stop there again rather than guess the box ends. word-stops-text2.ts PB3c to PB3e probe it for
Word's next batch.

* refactor(layout): read run borders of thin and thick lines with a medium or large gap as master's table cells do

#3677 gave thin and thick lines with a medium or large gap the widths Word draws beside a table's cells, from 4 to 24
eighths of a point, which word-stops-text RF25a, a thin, thick and thin line with a medium gap of 3 points 9 points wide
in a run, is one of. Only RF25b, a thick and thin line with a large gap of 4.5 points, is past those, so it alone stays
a width seen at one size, and the docs no longer list RF25a's as other than a paragraph's. The read-document test of a
run border not yet followed takes "custom", as apples of 4 points, which #3677 used, are an art border followed now.
2026-10-05 14:45:33 +01:00
Dolan 64e84bf387 feat(layout): lay out words longer than their table can make room for, and long words beside space between cells, as Word does (#3681)
* feat(layout): lay out words longer than their table can make room for, and long words beside space between cells, as Word does

Word's PDF of word-stops-long-words.docx (lay-stops2's batch) settles most of
the work's line 9:

- Where a table's columns' widest words don't fit in the room, and it has no
  width of its own in twips, Word gives each column's text a share of the
  room in proportion to its widest word, whatever width its cells give it,
  and breaks the words (LW1a to LW1l, LW4d; also L7, TW12 and TW13, which
  had been read as fitting no rule).
- A long word with more text beside it in a cell merged across columns
  widens them as its line does (LW2a, LW2b).
- With space between cells, a column with a long word is widened for it, and
  a table wider than its columns has them widened in proportion to fill it,
  the space aside (LW3a to LW3f, LW4a to LW4c); rows that give a column
  different widths are evened out as without the space (LW5c).

A table whose width is a share of more than the width it is in now stops:
the batch's probes of shares gave 50 times what they meant, and Word laid
those out three ways. word-stops-long-words2.ts asks again for the next
batch, with the shares meant.

* fix(layout): stop at a table whose cells' margins are wider than the room for it

Sharing the room among the columns in proportion to their widest words
gave widths that weren't numbers for empty cells, and below nothing for
others, where the cells' margins alone are wider than the room, such as
a table in a narrow cell. master stopped there, and what Word does
hasn't been seen, so the layout stops again, sizing each column as wide
as its widest word for a layout that guesses past it.
2026-10-05 14:33:25 +01:00
Dolan f78a5ce3dd feat(layout): lay out table borders of different styles that meet, and borders beside space between cells, as Word does (#3677)
* feat(layout): lay out table borders of different styles that meet, and borders beside space between cells, as Word does

Word's PDF of word-stops-table-borders.docx (lay-stops2's batch) settles the
table border stops of the work's line 6:

- Where two cells' borders meet, Word draws the heavier, by the weights
  MS-OI29500 gives for 17.4.66, but makes room for the wider of the two
  whichever it draws (TB1 to TB3; TB3d: a dotted border of 1.5 points below
  a single one of half a point takes 1.5 points, below the single one Word
  draws). Beside text, where Word draws the narrower and half the wider is
  more than the margin, which it keeps the text from hasn't been seen, so
  that still stops.
- Wave and 3D borders take their room at each width Word offers (TB4a to
  TB4v).
- With space between cells, each cell's borders left and right of it take
  their width from its text, and the table's none (TB5a to TB5l). A row's
  own space is the table's, at its edges too (TB6c, TB6d), and space given
  as a share of the table's width is none (TB6a, TB6b). Where such a table
  breaks across pages, its bottom border is below the last of it on the
  page and its top border above the rest of it on the next, between rows
  and in them (TB7a to TB7c).

Paragraph and run borders with a medium or large gap take the room they take
beside a table's cells (word-table-formats.docx BS, word-stops-text.docx PB4b).

* fix(layout): leave a deleted row's space between cells out of the rows' comparison

A deleted row takes no room, nor does the space around it (word-tracked-tables.docx MK14h), so a table whose kept rows
all have the same space between their cells no longer stops for a deleted row with other space, and its space is the
first kept row's.

* fix(layout): stop at a row's own borders in a table with space between its cells

A row's own table borders (w:tblPrEx), which #3686 gives its cells, meet
space between cells, whose table borders go around the space
(word-stops-table-borders.docx TB5). Where Word puts a row's own hasn't
been seen, so the layout stops there rather than guessing.
2026-10-05 13:42:12 +01:00
Dolan 438ef7f566 feat(layout): lay out table styles' row and cell formatting, rows' own table properties, and old merged and fitted cells, as Word does (#3686)
Word's PDF of word-stops-tables.docx (lay-stops2's batch) settles most of the
work's line 15:

- A part of a table style for some rows gives them its height (TS1a), and
  its space between cells is ignored (TS1c).
- A style's corner cells apply to each row of a header of several rows
  (TS2), and a header of three rows with its first row turned off is banded
  from its first row, as though it weren't a header (TS3).
- A row's own table borders and cell margins (w:tblPrEx) apply to its cells
  (TS4).
- A table style's own row height is ignored (TS5a), and its own cell margins
  apply to its cells (TS5b).
- Cells merged across columns as old versions of Word wrote them (w:hMerge)
  are one cell across them (TS6).
- In a table whose cells all have widths, a cell whose text Word is told not
  to wrap (w:noWrap) wraps it all the same (TS7b), and text fitted to its cell
  (w:tcFitText) is on one line a paragraph (TS8).

word-stops-tables2.ts is the probe for the next batch: a style keeping rows
whole, a share of the width as an indent (TS9 gave 500%), unwrapped and
fitted text in tables sized to their text, a header of four rows banded,
and a row's own height over its style's.
2026-10-05 13:23:31 +01:00
Dolan 06f22dd458 feat(layout): lay out documents in compatibility modes 14, 12 and 11, suppressTopSpacing and useFELayout, as Word does (#3679)
* feat(layout): lay out documents in compatibility modes 14, 12 and 11, suppressTopSpacing and useFELayout, as Word does

Word laid out the same 22 pages alike in compatibility modes 15, 14, 12 and 11
(word-stops-compat-15.docx to -11) but for justified lines, which Word 2010
and before don't squeeze, a table sized to its text, which they give its
cells' margins beside the room, tabs past the margin, a narrow gap beside a
frame, and in 12 and 11 East Asian text and VML text boxes. The layout now
lays out documents in those modes, and stops only at what they lay out
otherwise or haven't been seen with: those, a page break at a paragraph's end,
floating tables, tables sized to their text in cells, indented or as a share,
distributed lines, ligatures without enableOpenTypeFeatures, and the schema's
compatibility settings, seen leaving lines alone only in Word 2013's mode.

suppressTopSpacing leaves out the space above the text of the first line of a
page or column at exact and at-least spacing (word-stops-top-spacing.docx ST1
to ST5), and useFELayout leaves paragraphs without East Asian text as they are
(word-stops-fe-layout.docx FE1). Paragraphs kept together taller than some of 3
columns of different widths, and those kept with them, a gutter at the top
with mirrored margins or below a negative top margin, a table row in an HTML
division and pages printed two to a sheet no longer stop
(word-stops-pages.docx, word-stops-two-on-one.docx).

word-stops-compat2.ts writes the probes of what these left open, for the next
round of Word's PDFs.

* docs(layout): list the compatibility and settings probes in stops2/README.md, as #3678 lists the batch's

for the folder in scripts/layout-probes/README.md. The compatibility-mode, pages and
settings probes are listed there now, rather than in rows of their own.

* perf(layout): look for a paragraph's East Asian text only in documents that lay it out otherwise

unknownInOlderLayout scanned every character of every paragraph for East Asian text,
though only Word 2007's and 2003's modes and useFELayout lay it out otherwise.

* docs(layout): say FE1b turns off only autoSpaceDN, and probe both East Asian auto spacings off in FE2d

docx's autoSpaceEastAsianText writes only w:autoSpaceDN, so word-stops-fe-layout.docx
FE1b, which Word saved, has autoSpaceDE on, though its script's header said both were
off. The header now says what it is, and word-stops-compat2.ts's FE2d writes both off,
in the paragraph's properties in the schema's order, for the next batch.
2026-10-05 12:06:37 +01:00
Dolan 54bb97d5d9 feat(layout): lay out table rows across pages with merged cells, tables in cells, set heights and footnotes, as Word does (#3689)
Word's PDFs of word-stops-tables.docx and word-stops-notes.docx (lay-stops2's
batch) settle most of the work's line 20:

- A table in a cell doesn't repeat its header rows on the next page (RW1),
  and one with cells merged down its rows whose text is in their first rows
  breaks as any other (RW2). An empty paragraph that ends a cell after a
  table takes no room.
- The text of a cell merged down rows goes on page by page in the last of
  its rows (RW4a), between the border above its first row and the one below
  its last (RW4a, RW4b).
- A cell merged down from a row set taller than a page has its text in it
  (RW5a), and the row's footnote starts at the bottom of the next page (RW5c).
- A row set to at least a height taller than a page, whose text is taller
  than a page too, breaks where its text does, each part filling its page
  (RW6).
- In columns, a row kept whole that is taller than a column goes down the
  first column of each page (RW11).
- A table in a cell merged down rows breaks as one in a cell of a row (RW12).
- A row with a table in a cell beside a line with a footnote breaks where
  the footnote fits whole below it (NT11), rather than after the line.

word-stops-rows2.ts is the probe for the next batch: merged text beside a
row across three pages and across a page break between its rows, rows set
taller than a page with footnotes, merged cells or as a header row, and in
columns, and merged text in a table in a cell.
2026-10-05 11:43:23 +01:00
Dolan 68f31ec029 feat(layout): measure, kern and join letters in Office's fonts that Word installs, as Word does (#3683)
* feat(layout): measure, kern and join letters in Office's fonts that Word installs, as Word does

Adds Calibri Light, Aptos, Aptos Narrow, Trebuchet MS, Georgia, Verdana, Tahoma,
Century Gothic, Consolas, Candara, Corbel, Constantia, Book Antiqua, Franklin
Gothic Book, Gill Sans MT and Impact to the width tables, with their line
heights, kerning and ligatures, from Word's PDFs of lay-stops2's font probes and
Word's own files of the fonts. An italic Word slants is measured as upright; a
bold Word makes itself still stops. Text with ligatures isn't kerned in faces
whose kerning is only in their kern table, as Word leaves it.

* docs(layout): say which ligatures Office's fonts join, and with which settings

* fix(layout): name each made-bold probe line's font, so the reader reads each font's own

The three fonts' MB1 lines had the same names, so word-stops-office-fonts.py read Calibri
Light's under Franklin Gothic Book and Impact too. Each line now names its font, and the
spaced H's are three from 48 points, so the line fits beside its longer label.

* docs(layout): list the font probes in stops2's README
2026-10-05 11:31:57 +01:00
Dolan f12f03f33b feat(layout): lay out footnotes across pages in kept paragraphs, table rows and columns, and page references in them, as Word does (#3690)
* feat(layout): lay out footnotes across pages in kept paragraphs, table rows and columns, and page references in them, as Word does

word-watertight-notes.docx and word-page-fields.docx, saved from Word,
settle the footnote stops left on line 3 of the stops report:

- Paragraphs kept with the next that start a footnote's part on a page
  break as without them, as the text's do at the top of a page (FN9,
  FN10, FN12).
- A table row in a footnote breaks between its cells' lines, as a row of
  the text does, with the rest at the top of the next page's footnotes
  (FN11), and Word's empty paragraph after a table that ends a note
  takes a line below it (FN11, FN12, SP3c).
- A footnote too long for the columns of a page, whose reference would
  be at the top of a later column, gets as much room below the columns
  as leaves its reference on the page, found by laying the page out
  again with the room halved (FN3).
- A page reference with \p in a footnote or endnote writes "on page"
  and the page, wherever its bookmark is (PF8).

Where the evidence leaves something open, the layout stops: a row in a
footnote across more than two pages, a footnote that starts with a row
none of which fits, a note ending with a table where the note text style
isn't formatted as Normal, and a long footnote in columns that no room
leaves with its reference. word-notes-across-pages.ts probes them.

* fix(layout): stop where a footnote's reference moves on and back in columns, rather than lay the page out forever

A page in columns whose footnote moves its reference on to the next page
(FN1) is laid out again without the footnote's room. Where the
reference's line then lands at the top of a later column, it stays
there, as at the top of any column, its footnote asks for the room
again, and the reference moves on again, round and round: paginate never
returned. Of 600 random 2-column documents with footnotes, master hung
on 100.

The layout now stops where a reference moves on a second time, as
whether Word moves the line on from the top of a column, or what is
above it too, isn't known. Guessing, it moves on. It also no longer
lists a moved footnote twice.
2026-10-05 11:05:56 +01:00
Dolan cf02af7fc1 feat(layout): lay out what the standard and Cambria Math settle: equation symbols, list styles and bound content controls (#3684)
* feat(layout): lay out what the standard and Cambria Math settle: equation symbols, list styles and bound content controls

* fix(layout): leave the equations probe's equations alone when ONLY leaves EQ22 out

The EQ22 injection looked for EQ22's equation from where its marker was,
and with the marker missing, from the start of the document, so with
ONLY leaving EQ22 out, it rewrote the first equation there. It throws
now, which write ignores under ONLY, as for the other markers.
2026-10-05 10:37:21 +01:00
Dolan bd5ab7ace6 feat(layout): lay out header pictures, contextual spacing in cells, header rows and tabs past the margin, as Word does (#3678)
* feat(layout): lay out header pictures, contextual spacing in cells, header rows and tabs past the margin, as Word does

* fix(layout): keep what was guessed at in a table laid out again from the next page for its header rows

Guessing, a paragraph kept with the next above the table, or header rows at a column's foot, is noted as a guess before the table is laid out again from the next page. Going back to where the table started dropped that note, so the pages didn't say they were guessed at.

* test(layout): check the lines beside a header's drawing placed against the column

The test checked a line above the drawing, so it passed whether or not the body went round it.

* docs(layout): header rows at a column's foot stop the layout, and end the line spacing sentence

The table paragraph said header rows aren't left alone at a column's foot either, where the layout stops instead. The line spacing paragraph ran into the contextual spacing one without a full stop.

* fix(layout): keep only the guesses about moving a table's header rows when it is laid out again from the next page

A table laid out again from the next page, as its header rows would be
alone at the foot of this one, kept every guess made while laying it out
here, such as the break of a table with space between its cells and
borders, which doesn't happen once the table moves. Only the guesses
about moving the header rows are kept now. A row kept whole whose header
rows go on to the next page with it isn't a break of such a table
either, so the layout doesn't stop there.
2026-10-05 10:06:19 +01:00
Dolan 2fd675a0c4 feat(layout): lay out equations of text, as Word does (#3675)
* feat(layout): lay out equations of text, as Word does

* docs(layout): say a line's equation alone in its paragraph is lined up as its justification says

A line's text is lined up in its room as the paragraph's alignment says,
but Word centres an equation alone in its paragraph in a paragraph aligned
left (word-equations.docx EQ2c, EQ2d), as its m:jc, or the document's
m:defJc, says. The layout gives each line's room and how wide its text is,
not where the text starts in it, so nothing it lays out moves.

* fix(layout): stop at a displayed equation beside text, and at equations alone together or after a number

Word shows an equation in a line of text in the line, and one alone in its
paragraph displayed, on a line of its own (word-equations.docx EQ2). An
m:oMathPara is displayed, so one beside text in its paragraph was laid out
in the line, where Word hasn't been seen putting it. More than one equation
alone in a paragraph, and one alone after its list's number, haven't been
seen either, so the layout stops at them, as it does at what Word's
behaviour isn't known for.

* fix(layout): stop at equations in maths settings the layout doesn't follow

An equation's widths are Cambria Math's, so one in a document whose maths
settings (m:mathPr) give another maths font was laid out too wide or too
narrow. Margins and space around equations on lines of their own
(m:lMargin, m:rMargin, m:preSp, m:postSp) haven't been seen in Word either.
The layout now stops at the equations of such a document, and follows the
settings Word writes: Cambria Math and margins of 0. Text without
equations is laid out as it was.

* fix(layout): count only the equations the reader reads in a paragraph

An equation deleted, or moved elsewhere, in a tracked change is left out
of its paragraph, but the check of a paragraph's equations counted it from
the XML, so text, an equation and a deleted equation stopped as two
equations alone in a paragraph. It now counts the equations read, the
boxes that stop where they don't fit on their line, and looks for an
equation displayed (m:oMathPara) only where the reader reads.
2026-10-04 02:30:10 +01:00
Dolan d8bb79de5f feat(layout): lay out text frames, drop caps and VML text boxes and shapes, as Word does (#3674)
* feat(layout): lay out text frames, drop caps and VML text boxes and shapes, as Word does

* fix(layout): let a VML shape overlap other drawings unless it says not

A VML shape that text flows around was read as one that may not overlap other
drawings, so two that overlapped stopped the layout as Word moves one out of the
way. VML lets a shape overlap unless o:allowoverlap says not, as DrawingML's
allowOverlap does, and Word wraps text round a VML shape as round a DrawingML one
(word-vml.docx VM9 to VM11, VM15), so it is read from the shape.
2026-10-04 00:37:49 +01:00
Dolan afccf39884 feat(layout): lay out text around tables that it wraps around, as Word does (#3673)
* feat(layout): lay out text around tables that it wraps around, as Word does

A table that text flows around (w:tblpPr) is laid out as Word lays it out: the paragraph after it goes beside it, as beside a drawing with square wrapping, kept from it by its distances from the text, and it is placed against the page, its margins, the column or the top of the paragraph after it, as word-floats2.docx (G24 to G29) and word-floats3.docx (H1 to H15) showed. Its room is its rows' width with the halves of its borders left and right, 0.75 points wider without borders there, its indent doesn't move it, and the paragraph after it has all its space before below the space after the paragraph before.

It still stops where Word's way hasn't been followed: one in a cell, a header, a footer or a note, one without a paragraph after it, kept with the next, with a footnote in it or a border on one side only, two that may not overlap, and one going past the bottom of the page, which Word breaks across pages. Guessing, those are laid out in the text, as master guessed them, but for two that may not overlap.

* chore(layout): let the spell check know the attributes a floating table is placed by

CSpell splits tblpXSpec and tblpX into words, and tblp isn't one.
2026-10-04 00:05:50 +01:00
Dolan 070e104c68 feat(layout): lay out the footnotes word-watertight-notes settled, as Word does (#3658)
* feat(layout): lay out the footnotes word-watertight-notes settled, as Word does

Word's PDF of word-watertight-notes.docx (round 10, FN1 to FN15) showed what
it does where docx/layout still stopped at footnotes after #3651:

- FN1: a reference that moves on when its columns are laid out again for its
  footnote leaves the page as it was without the footnote
- FN2, FN3: a footnote continues in columns from the top of the page's
  columns, or of a column a section starts in, as far as it fits below the
  lines of every column, with the text going on above it
- FN4, FN5: the rest of a footnote has pages of its own before any section,
  and a continuous one starts on a new page after them
- FN6 to FN8: text and footnotes after one that starts on the next page go
  after it, and a reference below a page's top moves to the next page first
- FN9, FN10, FN12: a footnote breaks before a kept paragraph, before those
  kept with the next, and before a table whose header row would be alone
- FN13: the footnote of a line kept with a table goes below its first row
- FN14, FN15: footnotes of other sections go in the first one's columns

FN11 (a row broken in a footnote) and FN3's case from below the top of the
columns, which Word lays out again, still stop.

* fix(layout): check and measure a footnote split in the columns the page's footnotes are in

splitLast took the columns from the section being laid out, while the
page's footnotes are laid out in its first footnote's section's columns
(word-watertight-notes.docx FN14, FN15), so a split could be checked for
columns of different widths, and given its room, by the wrong section's
columns.
2026-10-03 01:04:02 +01:00
Dolan d51de2487b feat(layout): lay out text around drawings that overlap, kept paragraphs and tables beside drawings, as Word does (#3671) 2026-10-03 00:55:40 +01:00
Dolan 621bfbfee4 feat(layout): kern text and join letters into ligatures in the width tables' fonts and fonts' files, as Word does (#3661)
* feat(layout): kern text and join letters into ligatures in the width tables' fonts and fonts' files, as Word does

Word kerns text that asks for it and joins letters into ligatures, and its Normal template turns both on. The width
tables now have Word's kerning of every pair of the characters of Windows-1252, and the ligatures of each setting of
Word's Font dialog, in Calibri, Cambria, Arial, Times New Roman and Courier New, from Word's PDF of
scripts/layout-probes/word-kerning.docx, and fonts given as files join letters with their GSUB ligatures. Where Word's
PDFs don't show how it kerns or joins text, the layout stops: across runs measured together, beside a soft hyphen or a
character that takes no room, in a word longer than its line, and at kerning and ligatures the tables don't have.

The kerning demo's 202 lines are all where Word's PDF of it puts them.

* fix(layout): look for kerning and ligatures not yet followed in the parts of text between tabs, as they are measured

measureTextWidthAsDrawn measures the parts of text either side of a tab typed in it apart, but unknownShaping left the
tabs out and looked at the text as one, so it checked pairs and ligatures across a tab the measurement never has, and
could miss a pair it does. It now checks each part, as the font-file measurer does.

Raised by CodeRabbit's review of #3661.
2026-10-03 00:53:51 +01:00
Dolan af1078f592 feat(layout): lay out the .docx files a template imports (w:altChunk) as Word does (#3669)
* feat(layout): lay out the .docx files a template imports (w:altChunk) as Word does

Word's PDFs of the word-imported-* probes (AC1 to AC16) show what Word does with a .docx
a document imports when it opens it:

- its body goes where w:altChunk is, in the body, a table cell, a header, a footnote or
  another imported document, without its section's properties and headers, and with an
  empty paragraph at its end when it doesn't end with one
- a style of the same type and name, whatever its id or the case of its name, is the
  document's, as are its defaults, theme and settings; a style only it has keeps how it
  looks there, with new ids where the document has its ids
- its lists are lists of their own, and its footnotes are numbered with the document's
- a bookmark of a name the document has is the document's

patchDocument unzips the .docx files a template imports for the estimator, and the .docx
adapter turns them into the template's own before laying it out. An imported document of
several sections, one whose formatting is kept (w:matchSrc), one with a page reference or
number of pages, and one in another format, such as HTML, RTF or plain text, still stop,
now saying why.

* feat(layout): keep the look of the styles only an imported document has, as word-imported-styles.docx shows

Word's PDF of word-imported-styles.docx (AS1 to AS9) settles how Word keeps the look of
an imported document's own styles:

- a paragraph style keeps what the styles it is based on there and the imported
  document's defaults give it, whatever the document's of their names (AS1, AS2, AS4)
- a character style keeps only what it gives, not the defaults (AS3)
- a table style is based on the document's Normal Table (AS6)
- paragraphs of no style are in the imported document's default style (AS5)

Where the imported document's defaults leave out some of the document's, which Word's
PDFs haven't shown, the layout stops. Keeping source formatting (w:matchSrc) still
stops: Word keeps the text's look, but gives the last paragraph none of its space
after (AS9), and keeps the document's table defaults and theme (AS7, AS8).

* docs: say the imported documents' reader reads all six of the probe's documents

The reader's usage comment still said four documents, from before the probe wrote
word-imported-bookmarks and word-imported-styles, so following it left those two out.

* docs: say the best guess still stops only at the imported documents it doesn't lay out

Since the .docx adapter lays out imported .docx files as Word does, a guess only stops
at those it doesn't, such as one in HTML, rather than at every imported document.

* fix(layout): read backslashes in a relationship's target as slashes, as patchDocument does

patchDocument unzips an imported .docx at its relationship's target with backslashes
read as slashes, as some tools write them, but the .docx adapter resolved the target
as it was written, so it didn't find the document and stopped at it.
2026-10-03 00:33:42 +01:00
Dolan c46cba414b feat(layout): lay out a document grid, and text that runs down the page, as Word does (#3670)
* feat(layout): lay out a document grid as Word does

Word's PDFs of word-grid, word-grid2 and word-grid3 (scripts/layout-probes) showed how Word lays out a section's
document grid (w:docGrid): each line takes as many of the grid's lines as its own height needs, with multiple and
at-least spacing on them and the room below its text allowed below the page; a grid of lines and characters adds its
charSpace after each character and a quarter of a character between East Asian characters and Latin letters; and a
grid that snaps to characters puts them in cells of each column. The layout follows them, and stops where Word's
PDFs didn't show what it does. A section whose text runs across the page with a direction of its own no longer stops.

* feat(layout): lay out text that runs down the page as Word does

Word's PDF of word-vertical.docx (scripts/layout-probes) showed that Word lays out a section whose text runs down the
page as a page turned on its side: each line from the top margin to the bottom one, the lines across the page from the
right (tbRl, btLr) or the left (tbRlV, tbLrV), ideographs an em down the line and Latin text on its side, and a header
that doesn't push the lines (word-grid3.docx VH1). The layout follows it, and layoutDocument gives each line where it
is on the page, with textRunsDown on the page. It stops at what Word's PDFs didn't show down the page.

* fix(layout): stop at a grid that snaps to characters on text that runs down the page

A grid that snaps to characters measures its cells across a column of the page, where the lines of text that runs down
the page run along its height, and Word's PDFs showed only a grid of lines and characters there (word-vertical.docx V3).

* docs(layout): name the reader of word-grid3's PDF, word-grid.py

word-grid.py reads the H probes of word-grid3 too, as the probes' README says; there is no word-grid3.py.

* fix(layout): read V10 and V11's lines from the left in word-vertical.py

tbRlV and tbLrV put their lines across the page from the left, so the reader printed them in reverse. It now also takes
each page's direction from the probe on it, as its words don't show it, and leaves out the header and footer of a page
of text down it.
2026-10-03 00:23:49 +01:00
Dolan edbb770e3f feat(layout): lay out past what it would stop at with a best guess, when asked (#3672)
* feat(layout): lay out past what it would stop at with a best guess, on request

Decision D6 of the watertight report: an opt-in best guess past the stops.
estimatePageNumbersWith({ guess: true }), and layoutDocument(doc, { guess: true }),
lay out past each stop with the best guess the layout has, and say where they
guessed: the estimate's guesses give why and the page it was laying out then,
and each page of layoutDocument's result says what was guessed at on it.

Every stop goes through one path. In paginate, a stop is stopAt(reason): it
throws without a guess, and with one notes the guess on the page and goes on
with what the layout has. What the reader marks on a block, section or the
document is laid out as it was read; a line marked by the line breaker as it
was broken; text in a font or with a character the measurer doesn't know as
the measurer measures it, the most similar font in the width tables. In the
reader, read with a guess, what it can't read is left out of its paragraph,
which keeps why, unless the place it stops at gives a better guess: a date as
written, a run's formatting ignored, a ruby's base, a content control bound to
custom XML as written. A stop added later gets one of those paths, or, written
as throw new Unsupported in paginate, or as a block with nothing read in it, a
clear no guess. Off by default, so the default stays watertight, and the
default layout of every committed probe and Word-saved demo is unchanged.

* test(layout): check the guesses against Word's PDFs, and cover their last branches

scripts/layout-probes/guess-lines.ts lays out a document saved from Word with a guess, and finds each line from the first page it guessed on among the lines of Word's PDF. The docs say which floating drawing stops still have no guess.
2026-10-02 23:49:42 +01:00
Dolan 85773e0f01 feat(layout): lay out documents with the compatibility settings Word lays out lines alike with, as Word does (#3668)
* feat(layout): lay out documents with the compatibility settings Word lays out lines alike with, as Word does

docx/layout stopped at any of the schema's compatibility settings turned on,
and at Word's allowHyphenationAtTrackBottom and
allowTextAfterFloatingTableBreak turned on (decision D4), as several change
lines by their definitions. Word's PDFs of word-compat-settings.docx, with
each of eight groups of them on, of word-compat-settings2.docx, with each
setting of the two groups that changed lines on alone, and of
word-compat-settings2-together.docx, with all the others on at once, showed
that in compatibility mode 15 only suppressTopSpacing and useFELayout change
Word's lines. The other 62, and Word's two settings, at most move the text
inside a line of exact height or leave a justified line before a line break
unstretched, so they no longer stop the layout.

* fix(layout-probes): report only the probe that moves the pages after it, in the settings probe's reader

compare took each probe's page shift from its first line and reported any
shift, so a probe that added a page made every probe after it read as
starting on another page, though its docstring says they don't differ. It
now carries on from the page the probe before ended on, and reports a move
only where a probe starts somewhere that doesn't explain. Word's PDFs had
no such move, so what the reader printed for them is unchanged.

* fix(layout-probes): don't report a probe as moved when it is on its own page, in the settings probe's reader

A probe whose last line moved onto the next probe's page made that probe read
as starting a page early, though it was on the page it had been. compare now
reports a move only when a probe starts on another page than it did and the
probe before didn't end as many pages later. Its own lines' places are still
compared, so a probe pushed down its page reads as such.
2026-10-02 23:25:17 +01:00
Dolan 8a86bfd5f8 feat(layout): lay out text around pictures and shapes that it wraps around, as Word does (#3667)
* feat(layout): lay out text around pictures and shapes that it wraps around, as Word does

docx/layout stopped at any drawing that text wraps around. Word's PDF of a new
probe, word-floats.docx (F1 to F40), showed how Word lays the text out around
them, and this follows it: lines beside a drawing have the room beside it, with
its distances and effects, on the sides its wrapping says, both sides in rows,
a room the next word doesn't fit left empty, and lines with no room below it.
Drawings are placed against the page, margins, column, paragraph or line, with
offsets, alignments and percentages. The text before a drawing's paragraph on
its page goes round it too, a paragraph whose drawing would go past the bottom
of the page moves to the next page with it, and a table that doesn't fit beside
a drawing goes below it. It keeps stopping where Word hasn't shown its way, such
as drawings that overlap, paragraphs kept with the next beside a drawing, and
floating tables.

A new layout demo, text-around-pictures, checks it against LibreOffice.

* fix(layout): put a line below a drawing when its indents leave none of the room beside it

The room beside a drawing that a paragraph's indents left nothing of gave the
line no room of its own, so it was laid out across the paragraph, over the
drawing. It goes below the drawings beside it now, as a line with no room
beside them does. Only a paragraph whose indents leave no room even without a
drawing keeps its lines as they are.

* docs(layout): say what each function of the word-floats reader reads
2026-10-02 23:10:46 +01:00