Skip to content

Word reference corpus and verification ​

This page records the checked-in corpus of Word-authored documents, what is compared against it and the current results. It is evidence for the listed cases only. It is not a claim of Word parity, and it does not certify glyph metrics, fonts other than the one used, or Microsoft 365 subscription behaviour.

What is in the corpus ​

src/core/docx/__fixtures__/word-corpus/ holds thirteen small documents authored by desktop Word through COM (Word.Application), generated by src/core/scripts/docx-word-corpus.ps1. Recorded with Word build 16.0.20527, US Letter, 1 inch margins. Every body and heading style is set to Courier New, whose advance is 0.6 em, so a headless test can measure text exactly. That makes the comparison one of line breaking and pagination, not of font metrics.

DocumentFeatures
01-headings-stylesTitle, headings, bold, italic, alignment, indents, exact line spacing
02-lists-numberingBullets, numbered list, multilevel outline
03-tables-mergedTable with horizontally and vertically merged cells, header row, shading
04-header-footerHeader text, footer with PAGE field, two pages
05-footnotes-endnotesTwo footnotes (one wrapping) and one endnote
06-sections-columnsPortrait, landscape and two-column sections (three pages)
07-imagesInline picture and a square-wrapped floating picture
08-equationTwo OMML equations (fraction and root, summation)
09-fields-tocTable of contents, heading page breaks, date field
10-tracked-commentsTracked insertion, deletion and replacement, one comment
11-content-controlsText, drop-down and check-box content controls
12-chartInline Word chart (default clustered column)
13-equation-shapesDisplay equations of six shapes and an inline fraction, with text after each

Each document has <name>.docx, <name>.facts.json and <name>-p<N>.png per page (about 50 DPI, rendered from Pages(N).EnhMetaFileBits). The folder is about 0.55 MB. The facts file records the Word build, page count, line count, per-paragraph start page, position and the character offset at which each line starts (scanned with Range.Information), floating shape geometry, section setup and counts of notes, comments, revisions and tables.

Regenerating ​

pwsh -File src/core/scripts/docx-word-corpus.ps1

Needs desktop Word on Windows. The script waits up to 15 minutes for a running WINWORD.EXE, always quits Word in a finally block, and overwrites the folder. Review the diff of the facts before committing: a different Word build or printer driver can legitimately move line breaks.

Comparison test ​

src/core/docx/word-corpus.test.ts loads each .docx with loadDocx, lays it out with layoutDocumentModel and a monospace measurer (0.6 em per character), and compares with the facts:

  • page count: exact;

  • each non-table paragraph's start page: exact;

  • each paragraph's line count and line-start offsets: exact (monospace text leaves no rounding room, so any tolerance would hide a real difference).

  • the page position of each paragraph's first line (x and y, in points): within 1 pt. Word records twips and the layout works in CSS pixels, so a rounded pixel (0.75 pt) or line height can differ without being a layout difference; the differences found so far are several points;

  • floating pictures: page, left, top, width and height within 1 pt (the corpus has one, anchored to the page).

Not compared: paragraphs inside tables (Word's end-of-cell marks make the numbering differ), paragraphs with no letters (equation-only paragraphs, whose text Word linearises), inline picture sizes, and anything between the first lines (per-line y).

Paragraphs are matched by their first eight letters in document order, so list labels, note marks and field results do not matter. Differences that are real layout gaps are named in acceptedGaps (word-corpus-gaps.ts: id, document, Word paragraph numbers, aspect, reason). The test fails if an accepted gap starts to pass, so the entry has to be removed when the gap is fixed.

Raster comparison ​

The core has no headless rasteriser, so the PNG pages are not compared in src/core. They are the reference images for the browser suite (e2e/docx) and for manual inspection; a pixel comparison needs a recorded browser and font version, as the roadmap requires.

Current results ​

Line breaks, line counts and page counts match Word for all thirteen documents (as recorded; the bullets below are results for this corpus only). Fixed after this comparison was first made:

  • Justified text now squeezes its spaces to fit one more word. The 01 paragraph 5 gap was this, not indent handling: Word fits 64 characters where 63 fit only by narrowing 11 spaces by about 14%. The squeeze limit (SPACE_SHRINK = 0.145 of a space) is fitted to probes of Courier New at 9 to 13 pt; it reproduces all but 2 of 106 line-end decisions (Word accepted 0.20 at 13 pt and refused 0.14 at 10 pt), so it is an approximation, not Word's rule.

  • Square wrapping with wrapText="bothSides" now continues a line past the picture, as Word does (07 paragraph 3: 12 lines like Word). Other wrapText values keep the larger-side approximation.

  • The first line of a paragraph starts at character 0 even when the paragraph begins with an anchor or field code that draws nothing (07 paragraph 1, 09 paragraph 2). That was a layout difference, not only the recorder: the first line reported offset 1 or 3, so it did not "start the block".

  • The 06 paragraph 10 gap was a recording error: the facts script scanned at most 1200 characters of a paragraph, so a 1386 character paragraph was recorded with 39 lines. Rescanned in full, Word has 45 lines, as the layout does (the committed 06 facts file was regenerated; all other facts files are byte-identical from a full regeneration).

  • Vertical positions exposed real spacing bugs, now fixed; the rules are measured in the paragraph spacing probe below.

  • The bullet line height gap was the marker font: Word's Symbol bullet lines are 14.25 pt apart at 11 pt (1.29 em) against 12.46 pt for Courier New. The layout already measures the marker's font, so the headless test measurer now gives Symbol that height and the gap is gone.

  • The indented-first-character-x gap was a recording error, not a layout error. For a collapsed range, and often for a one-character range, Range.Information(wdHorizontalPositionRelativeToPage) returns the column edge (72 pt for an indented or a centred paragraph). Selecting the first character and reading Selection.Information(5) returns the caret position (126 pt and 84.8 pt for 01 paragraphs 5 and 7, which is where the layout starts the text), and it agrees with Information(wdHorizontalPositionRelativeToTextBoundary) added to the column edge. The recorder (Get-CaretX) now selects the character. Only the x values of 01, 02, 03 and 08 changed in the facts files; everything else is byte-identical. Comparing against the true caret exposed two further differences, both fixed: the test took a list label as the first character (Word's caret is on the first source character), and a paragraph numbered directly takes its numbering level's indents over its style's (02 paragraph 9: List Paragraph says 720 twips, the level says 360, Word draws the text at 90 pt, the layout drew it at 108 pt).

  • The display-equation-height gap was the equation line height. 13-equation-shapes holds a display equation of each of six shapes and an inline fraction, with a plain paragraph after each, so the line height Word gives each shows in where the next paragraph starts. Measured line heights at 11 pt (the difference between successive following paragraphs, minus the plain line; about 0.4 pt of noise): plain run 12.5 pt (1.14 em), subscript plus superscript 13.4 pt, display fraction 25.2 pt, inline fraction 18.7 pt, 2 by 2 matrix 21.9 pt, radical with a power 16.3 pt, display summation with limits 36 pt. The box model (src/core/math/omml-box*.ts) now reproduces these within 0.5 pt: a math line is at least 0.9 em above and 0.24 em below the baseline; scripts move by TeX-style rules, so a lone script adds little; display fractions keep their full size and inline ones are set at 0.7; matrix rows have no extra gap; radicals and display n-ary operators reserve more room. The numbers are fitted to this corpus at 11 pt Cambria Math, not Word's own rule, so other sizes and constructs (delimiters around tall content, accents, limits on inline operators) are unchecked.

  • Two more gaps were closed by probes (below): the table height of 03 (a vertical merge was sized with its first row, and the border of a table with merged cells was not counted) and the check-box line height of 11 (the MS Gothic font, not the content control).

No accepted gaps remain in word-corpus-gaps.ts.

Floating picture geometry (07) matches Word within 1 pt. Page counts match for all thirteen.

Paragraph spacing probe ​

src/core/scripts/docx-word-spacing-probe.ps1 writes small documents by hand (Courier New 11 pt, no default spacing) for each compatibility mode (15, 14, 12) with and without w:doNotUseHTMLParagraphAutoSpacing, opens them in Word 16.0.20527 and records the page and top y of every paragraph (__fixtures__/word-spacing/spacing-probe.json). word-spacing.test.ts rebuilds the same documents (word-spacing-docs.ts), lays them out and compares every paragraph (page exact, y within 1 pt; Word reports 0.75 pt pixels). Measured gap between two paragraphs (first has space after A, second space before B), the same in all three modes unless noted:

CaseOption off (default)Option on
Two paragraphs (A, B in 0, 6, 12, 18 pt)max(A, B)A + B
afterAutospacing / beforeAutospacing14 pt each, then maxflag ignored, the twips are used
Paragraph into a table, cell paragraph before BA + B (sum)A + B
Out of a table (cell after A, next paragraph before B)A + B (sum)A + B
Continuous section break between the twomax(A, B)A + B
Next-page section break (y of the first paragraph)max(0, B - A), so B - A when B is biggerB
Explicit page break in the first paragraph0 (dropped)0
Natural overflow to the next page, or next column0 (dropped)0
pageBreakBefore, compatibility mode 150 (dropped)0
pageBreakBefore, compatibility modes 12 and 14max(0, B - A)B

The compatibility mode changes only the pageBreakBefore row. Measured in Word, not derived from the specification. Not measured: other fonts or sizes, spacing in headers, footers, notes and text boxes, and w:contextualSpacing (the corpus covers it for list items). A one-row table that Word moves whole to the next page keeps the space after its last cell paragraph (12 pt); the layout lost it when a row was cut at a page boundary because the paragraph boxes do not carry that space, so a row now records the trailing space of each cell and the continuation keeps it.

Table row probe ​

src/core/scripts/docx-word-table-probe.ps1 (with docx-word-probe-common.ps1) measures how Word sizes table rows in 43 small documents (__fixtures__/word-table/table-probe.json, Word 16.0.20527); word-table.test.ts rebuilds them (word-table-docs.ts) and compares the top y of every paragraph. Measured:

CaseWord
Vertical merge whose text fits the rows it coversrows keep the height of their own cells
Vertical merge taller than its rows (2 or 3 rows, either column)the LAST spanned row grows, the rows above keep their height
Row with a 0.5, 1.5 or 3 pt single borderrow height = content + one border width, the first row also starts one border width lower
Double 0.5 pt borderthree times the width of a single one
atLeast / exact row heightsthe height, plus one border width when the table has borders

Fixed in the layout: a merged cell's text no longer sizes its first row (table-merged-rows.ts; a merge that does not fit the room left on the page keeps the old behaviour so the row splitter can cut it), and a body table whose cells are merged, vertically or by column span, now reserves its borders like any other fully bordered table (nested-frame-profile.ts; nested tables stay as they were, they have their own native evidence). Word draws a 0.5 pt border one whole 0.75 pt pixel wide, so bordered tables differ by up to 0.25 pt per row edge and a three-row merge by up to 1.6 pt; the test allows 2 pt there and 1 pt for tables without borders. Known and not fixed: a double border is not a solid edge, so no space is reserved for it (bd_dbl4, asserted as a gap). Word reports a merged-away cell's paragraph at the top of the merge; the test skips those labels.

Content control line probe ​

src/core/scripts/docx-word-content-control-probe.ps1 measures the line height of lines with content controls and symbol fonts (__fixtures__/word-content-control/line-probe.json); word-content-control.test.ts rebuilds the document. A check box content control and a plain MS Gothic run have the same 14.25 pt line at 11 pt (1.295 em; Courier New is 12 to 12.75 pt, a plain text or drop-down control 12 to 12.75 pt too), so the 2 pt gap in 11 was the font of the symbol, which the host's measurer owns, not the control. The shared headless measurer (word-measurer.ts) now carries the measured heights (MS Gothic 14.25, Segoe UI Symbol 15, Symbol 14.25 pt at 11 pt). Not modelled: a symbol in a Courier New run inside a check box is 15.75 pt (a font fallback that depends on the installed fonts); a Latin run set in MS Gothic is 15 pt against 14.25 pt here.

Reopen check ​

src/core/scripts/docx-word-corpus-reopen.ps1 (a step of node scripts/office-acceptance.mjs word) loads each corpus document with the core, appends a marker word to the first plain paragraph, saves with saveDocx, reopens the result in Word and fails on a thrown open, a "Repaired" caption, a missing marker, or a page count more than one page from Word's original. Last run: all twelve documents reopen without repair, with the marker present and the same page count as the original. This shows Word opens the saved packages; it does not show that unrelated parts are unchanged.

Released under the Apache-2.0 License.