* feat(layout): break lines of Chinese, Japanese and Korean, and measure East Asian and right-to-left text, as Word does
* refactor(layout): keep the language and East Asian marks of text out of shapes' spans
* test(layout): cover the remaining branches, and check docx/layout against Word's kinsoku probes
* docs(layout): list word-unicode and word-unicode2 among the layout probes
* style(layout): format the wrapping of a word wider than a line
* fix(layout): keep a character with its marks and what a zero-width joiner joins to it when a long word is split, across runs
A word wider than a line was split after the last character that fits, grouping each character with its marks only within
one run, and breaking after a zero-width joiner, where findLineBreaks never breaks. An accent in a run of its own, or a
joined emoji, could be split across lines.
A table row refers to footnotes as a line does, as word-probes.docx's U3
shows: a row whose footnote doesn't fit below it moves to the next page
with it, one whose footnote can continue stays, each line of a row broken
across pages has its footnote on its own page, and the row breaks after
the line whose footnote continues. Stops where a footnote holds back the
lines of a cell beside it, which Word hasn't shown.
* feat(layout): write page numbers in every format, with chapter numbers, as Word does
docx/layout wrote page numbers in decimal, roman numerals, letters and a few
more, and stopped at the rest and at chapter numbers. Two probes saved from
Word settle how Word writes each of ST_NumberFormat's formats in page numbers,
page references and lists, and how it writes chapter numbers, and the layout
now writes them so: the scripts of other languages, words, enclosed numbers and
counting systems, up to the numbers Word writes, and the chapter number of the
last heading its style numbers before each page reference.
Lists a paragraph's style numbers it in are numbered too. pageNumbers takes
chapterHeadingLevel, written as w:chapStyle, and PageNumberSeparator.EN_DASH is
written as the schema's enDash.
* fix(layout): take a style's list and level each from the nearest style that gives it
A paragraph style based on another can give its level (w:ilvl) alone and take
its list (w:numId) from the style it is based on, as Word's styles inherit
each property on its own. The reader only kept a style's numbering when it gave
the list, so such a style's paragraphs were numbered at the base style's level.
* docs(layout): say page numbers are written in Word's formats but for those listed as left blank
The line said every format was written, but the list of what is left blank names
Thai and Hindi words, and page numbers Word writes as an error.
* feat(layout): continue footnotes across pages as Word does
Word's PDF of word-probes.docx (U2a to U2q) showed how it continues the
footnotes docx/layout stopped at: a footnote keeps its own widow and
orphan control, and breaks between its paragraphs and table rows as the
body does; where too little of it can stay, its reference's line moves
to the next page with it; the body's widow control, keepLines and
keepNext apply first; and one longer than a page fills whole pages.
The footnote area is now a stack of blocks laid out as the body is, and
the four stops are gone. Narrow ones stay where Word hasn't shown its
rule: a footnote's own paragraph kept together or with the next, a
table row of more than a line or header rows in one, a footnote
continued below a paragraph kept with a longer one, and a long
footnote's rest after a section break.
A line or table row that doesn't fit below the end of a footnote
continued from the page before goes on the next page, and lines kept
with the next decide where their footnote goes on the page they move
to.
* fix(layout): stop at a table in a footnote whose columns can't be sized, as in the text
A footnote's table was measured with the widths fitColumns gave it,
even when it marked them as unknown, so the layout went on with them
rather than stopping. It is sized with sizedToPlace now, as a table in
the text is, and as master measured footnotes before the footnote area
was laid out in blocks.
* fix(layout): keep lines as tall as Word has them, unrounded, and break table rows as Word does
Word doesn't round the height of a line: Calibri 11 is 268.55 twips, where LibreOffice
and docx/layout had 269. The width tables keep each font's height unrounded, Cambria's as
Word's 2401/2048 of an em, and lines are no longer rounded to whole twips.
With exact heights, tables-across-pages showed that docx/layout broke table rows across
pages differently from Word. word-line-heights.docx, saved from Word, settled how: where
a table breaks across pages, the last of it on the page needs room for the table's bottom
border; a paragraph that ends in a cell's part on the page needs room for its space
after; and a row of an at-least height only breaks where the page has room for its
height, which takes out the stop at a row of a set height across pages.
* docs(layout): say a line is as tall as Word makes it only for one font
Word's heights were checked for lines in one font. A line in several fonts is as tall as
its tallest, which hasn't been checked in Word, so the docs say what the layout does.
Word breaks each column's lines at its own width, so a paragraph that goes on
into a column of another width is broken again there, and evens out columns
of different widths by height (word-rules2.docx Q7). docx/layout broke a
paragraph's lines once, at one width, so it stopped at columns of different
widths.
Each line can now have its own width in layoutLines, and the layout breaks a
paragraph's lines column by column: the part of it that goes on into a column
of another width, after a column break or where it doesn't fit, is broken
again at that column's width. Paragraphs kept with the next are measured at
the width of the column they move to. A paragraph kept together that is taller
than one of columns of different widths stops the layout, as how Word lays one
out down the first column of each page (#3607) isn't known for them.
A probe saved from Word (scripts/layout-probes/word-column-widths.ts) settled
the rest:
- Widow control counts the lines left for the next column as they are broken
in the column before. 2 narrow lines left go on 1 wide line, alone at the top
of the wide column, and 1 wide line left moves a line with it, though it
would go on 3 narrow ones. LibreOffice counts them as they are broken in the
next column, and moves lines until 2 are there.
- A table sized to its text keeps the widths it has in a narrow column in a
wider one, given no width or 100%. What Word does in a narrower column, where
they might not fit, isn't known, so the layout stops there.
* feat(layout): lay out footnotes in columns as Word does
docx/layout stopped at the first footnote in a section in columns. Word's PDFs
of word-rules2.docx Q6 and a new probe, word-footnotes-in-columns.docx, show
how Word lays them out: in the section's columns, at the column's width, one
after the other from the first column, evened out as columns before a
continuous section break are, with widow control. Every column of the page ends
above them, whichever column they are referred to from. LibreOffice puts each
below the column its reference is in instead.
The layout now does the same. When a footnote referred to from a later column
needs more room than the columns before it left, the page's columns are laid
out again from where they start, with that room kept for the footnotes. The
page each of the probes breaks at is the line Word breaks it at.
It still stops at a footnote in columns that doesn't fit below its reference,
at one that moves its reference to the next page when the columns are laid out
again above it, at footnotes referred to from two sections on a page, the
first of them in columns, and at a footnote in a section that starts in the
next column when a column of the section before goes down too far for it, which
Word hasn't been seen to lay out.
The probe, its reader, the .docx Word opened and Word's PDF are in
scripts/layout-probes, and the new demo layout/footnotes-in-columns has
chapters that open with a summary in two columns, with a footnote.
* fix(layout): read the second line of a footnote that wraps in the probe of footnotes in columns
The reader of word-footnotes-in-columns found each line by the probe name it
starts with, so the second line of N7's footnote, which wraps in its column,
was left out, and the footnote read as one line ending a line above the
bottom of the page. A line without a probe name now goes with the line before
it in its block of pdftotext's HTML, the paragraph it goes on from. N7 reads
as 2 lines, down to the bottom of the page, and nothing else changes.
* feat(layout): stop at footnotes in columns of different widths
The footnotes of a page in columns are laid out in the section's columns at
the width of the first, which is every column's while columns of different
widths stop when the document is read. Word has only been seen to lay out
footnotes in columns of the same width, so once columns of different widths are
laid out, a page whose footnotes are in them stops, rather than laying them out
at a width that might not be Word's.
* feat(layout): repeat a table's header rows at the top of each column, as Word does
Word and LibreOffice repeat a table's header rows at the top of each column it
goes on into, as at the top of each page (word-rules2.docx Q4). docx/layout
stopped there. Word's PDF of a new probe, word-header-columns.docx, showed the
same in columns evened out before a continuous section break, and that the
empty paragraph that ends a section after a table has a line of its own below
the last column, where LibreOffice gives it no room.
* test(layout): keep the space after the empty paragraph's line after a table below it, as Word does
The empty paragraph that ends a section after a table is a line of its own,
and its space after is the larger with the next section's space before, as
between any two paragraphs. Word's PDF of the columns demo puts the heading
after its table a line and 12 points below the columns: the larger of the
empty paragraph's 5 after and the heading's 12 before, not 7.
* feat(layout): widen a column for a word longer than its cells give it, as Word does
In a table whose cells all have widths, Word makes a column as wide as its
longest word, grows a table with no width of its own up to the room, keeps the
width of one with its own, and narrows the other columns toward their longest
words, each by its share of the width they can give up. Probed in
scripts/layout-probes/word-long-words.ts. A word longer than the table can make
room for, a long word in a table wider than its cells, and one in a table with
cells merged across columns still stop the layout.
* chore(layout): keep Word's PDF of word-long-words beside it, read by word-autofit.py
* docs(layout): list word-long-words among the layout probes
* fix(layout): lay out a paragraph kept with a table whose columns can't be widened before stopping there
The lookahead for a paragraph kept with the next sized the table, which threw
when Word's widening of it isn't known, so the layout stopped before placing the
paragraph and its bookmark went without a page number. It now stops only where
the table is placed, as it does for a table it can't read.
* fix(layout): keep the space before a continuous section's first paragraph after a page break, and stop at merges across pages, as Word does
Word's PDF of word-probes.docx showed three places where docx/layout put lines
on a different page from Word without stopping:
- U7a to U7c: the first paragraph of a continuous section with a page break
before it keeps its space before at the top of the new page, less the space
after of the empty paragraph that ends the section before: 1440 before after
200 is 1238 in Word (LibreOffice 1240). docx/layout left it out.
- U8a7: spaces before a page break that ends a paragraph are on a line as tall
as the paragraph's mark, not the break. docx/layout made a 28-point break's
line 28 points, moved it to the next page, and put the text after the break
a page later than Word.
- U4a: a cell merged down several rows whose text doesn't fit on the page is
broken across pages by Word. docx/layout moved the merge's last row whole and
counted all the merged lines on the page before. It now stops there, before
the merge's first row, until merged rows are laid out across pages.
The probe script, its reader, the .docx and Word's PDF are committed under
scripts/layout-probes, and section-start-space.ts checks U7a to U7c.
* fix(layout): move a merge's first row kept whole to the next page before stopping at the merge
A row kept whole (cantSplit, or of an exact height) that doesn't fit moves to
the next page. When it starts a merge, it moved only after the merge was
checked against the room left on the page, so the layout stopped at a merge
that fits on the next page. The row now moves first, and the merge is checked
where it goes.
* chore(layout): create the folder of the probe document's given path
word-probes.ts created build/word-probes whatever path it was given, so a path
in a folder that didn't exist failed.
* feat(layout): lay out a paragraph kept together that is taller than a column as Word does
Word lays such a paragraph out down only the first column of each page,
from the top of a new page unless it is at the top of the page's first
column, and what follows it goes on below it in that column and into the
next (word-balance.docx W3, and word-keep-together.docx K1 to K5).
LibreOffice breaks it across all the columns. The layout stopped there.
* fix(layout): stop where a paragraph kept together taller than a column would move away from one kept with it
A paragraph kept with the next before it, such as a heading, would be left
on its own at the bottom of the page. Word's probes didn't have one, so what
Word does there isn't known, and the layout stops rather than guessing.
* feat(layout): measure text with Pretext in a page's fonts, and lay it out as Word does
docx/layout can now measure how wide text is with a function the caller
gives it, through estimatePageNumbersWith({ measureWidth }). measureWithPretext
builds one on Pretext, taken from the caller, so docx doesn't depend on it.
Lines still break, tabs still move to their stops, and lines are still as
tall as Word makes them.
* fix: answer only the DevTools messages the Pretext comparison is waiting for
CodeQL flagged calling a callback looked up by an id from Chrome's
messages. Only a number id with a callback waiting for it is answered now.
* fix(docs): open the live examples' editor without a package's types when they can't be fetched
A package's types only help with editing, so a failed fetch or an error
page leaves them out rather than stopping the editor.
* fix(layout): leave out contextual spacing as Word does
Word's PDFs of word-rules.docx (P1) and word-rules2.docx (Q1) showed how it
leaves out the space between two paragraphs of the same style when one has
contextual spacing: it leaves out only that paragraph's own share of the
space, the first's space after, or the part of the second's space before that
is more than the first's space after. 200 after a contextual paragraph and
400 before the next leave 200, and 400 and 400 leave none. docx/layout, as
LibreOffice, left out the whole of the contextual paragraph's space and took
the larger of what was left, 400 and 400.
scripts/layout-probes/word-contextual.ts probes the cases those PDFs don't
settle: next to the empty paragraph that ends a section, and with
doNotUseHTMLParagraphAutoSpacing.
* fix(layout): put the space after the empty paragraph that ends a section only where the next section's space before is less, as Word does
Word's PDFs of word-contextual.docx and word-contextual-adding.docx settle
the cases of contextual spacing the earlier probes didn't:
- With doNotUseHTMLParagraphAutoSpacing, contextual spacing leaves out the
paragraph's own space, as docx/layout had it: 600, 200, 400, 400, 200, 0.
- Next to the empty paragraph that ends a section, Word put 0, 0 and 400
twips where docx/layout put 200, 200 and 600. The empty paragraph's 200
after is never on the page itself: it only takes from the next section's
space before, as it does at the top of a page. word-rules2.docx's Q6b and
Q7b show the same without contextual spacing: 0 after the last line, 200
after the empty paragraph and 0 before leave none, where docx/layout had
200.
Records Word's results in the probe script.
* chore(layout): commit the contextual spacing probes' .docx and Word's PDFs, as the other layout probes are
Follows scripts/layout-probes/README.md, which came with the earlier probes:
the .docx Word opened and the PDF it saved go beside the script, which
writes to build/word-probes by default, and the README lists the probe.
* feat(layout): start a section in the next column as Word does
A section that starts in the next column (SectionType.NEXT_COLUMN) starts in the
next column of the page when the section before has the same columns and one is
left, without evening out the columns before it, and on a new page otherwise, as
Word lays out word-rules2.docx's Q5a to Q5d. It stops at what Word hasn't shown
yet, which scripts/layout-probes/word-next-column.ts probes.
* feat(layout): keep the space before a section's first paragraph in the next column, as Word does
Word's PDF of word-next-column.docx showed the rest: the space before is kept at
the top of the column as at the top of a page (N1, N2), 3 columns into 2 starts
a new page (N3), as many columns of other widths start in the next column (N4),
and columns below text aren't evened out, without the empty paragraph's space
after below them (N6). It still stops at columns of other widths, whose line
width isn't known, and at evening out after a section that started before the
last of 3 or more columns.
* chore(layout): keep the next-column probe's .docx and Word's PDF of it beside it, as the other probes are
* test(layout): say what the next-column test of a paragraph kept with the next checks
Its comment said the paragraph moves to the column after, but a paragraph at the
top of a column stays there, with its space before, as at the top of a page: the
keepNext check only moves what is below something in the column.
Word's PDF of word-rules2.docx showed that the first paragraph of a section
that starts on a new page keeps as much of its space before as is more than
the space after the empty paragraph that ends the section before: 1440 before
after 200 is 1240 (Q2a), and 100 before is 0 (Q2b). With a page break before
the paragraph it is the same, 1240 (Q2c), as the page is already new.
docx/layout already did this since #3602, as it takes no page break at the
start of a new-page section, but nothing tested it. This adds tests of Q2a to
Q2c, a comment where the page break before a paragraph is taken, and a probe in
scripts/layout-probes that checks docx/layout against Word's result.
The documents that showed how Word lays out pages, and the PDFs Word saved of
them, were only in a git-ignored build folder. They are now committed in
scripts/layout-probes, with the .docx Word opened for each PDF and the scripts
that read them, and a README that says what each probe settles, how to make
its .docx, lay it out in LibreOffice and read Word's PDF.
The scripts import from docx, as the demos do, and write their .docx to
build/word-probes.
* fix(layout): make a paragraph's last line as tall as its text, not its mark
The layout made the last line of every paragraph at least as tall as the
paragraph's mark. Word and LibreOffice don't: a line of 8-point text in a
paragraph whose mark is 11 points is 8 points tall, as a document of
probes saved as a PDF from Word 16 for Mac and laid out by LibreOffice
26.8 showed. Text given a smaller size than its style's, as a TextRun's
size does, was laid out too tall, which put a heading of the
text-and-spacing demo on the page after Word's.
The mark now only sets the height of a line with no text on it, such as
an empty paragraph's, or a page break's at the end of a paragraph.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken
* ci: draw Calibri Light in Carlito in the shape demos' LibreOffice
LibreOffice has no font for Calibri Light, the heading font of Office's
theme and of docx's default heading styles, and drew it in Noto Serif,
whose lines are 12% taller. So the layout comparison checked docx/layout,
which measures Calibri Light as Calibri, against headings taller than
Word's: Calibri Light is as tall as Calibri. A fontconfig alias makes
LibreOffice draw it in Carlito, as wide and tall as Calibri.
The title of charts-in-templates, in the template's heading font, is now
drawn in Carlito, so its reference image is drawn again. The other 30
pages don't change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* feat(layout): break table rows across pages between the lines of their cells
Word and LibreOffice break a table row that doesn't fit across the pages
unless it is kept whole (cantSplit), but the layout moved every row to the
next page whole, which put the headings after a table of long rows on the
wrong page. Rows now break between the lines of their cells, with the
header rows repeated above the rest, and without widow control inside
them, as LibreOffice does. Rows kept whole, of an exact height, or whose
text fits but not their set height, still move whole. A row that would
break with merged cells, a table in it, or a height set taller than its
text stops the layout, as nothing checks how those break yet.
LibreOffice's lines are whole twips tall, so lines are rounded to twips:
that matches its line pitch for 80 of 90 font sizes measured, against none
before. The tables demo is at 12 points, as LibreOffice's lines of Times
New Roman at 10 points are a twip taller than the font's metrics.
A new layout demo, tables-across-pages, has rows of each kind across page
breaks. All 185 headings of the 7 demos are on LibreOffice's page.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken
* feat(layout): lay out footnotes at the bottom of their pages, and endnotes after the text
The layout stopped at the first footnote, so most reports lost every page
number after it. Now a page's footnotes take room at its bottom, below
their separator, with the space between them, but not before the
separator or after the last, as LibreOffice lays them out. A line whose
one-line footnote doesn't fit below it moves to the next page with it, as
in LibreOffice. LibreOffice continues a longer footnote on the next page,
splitting even one widow control would keep together, and which of its
lines stay isn't followed yet, so the layout stops there, and at a
footnote in a table row that breaks across pages.
Endnotes follow the text, after their separator, as Word and LibreOffice
lay them out. Footnotes are numbered 1, 2, 3 and endnotes i, ii, iii, and
their numbers are as narrow as superscript and as tall as their font.
A new layout demo, footnotes-and-endnotes, has 40 footnotes over 8 pages.
All 18 of its headings are on LibreOffice's page.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken
* feat(layout): lay out sections in columns
The layout stopped at the first section in columns. Now each page's
columns are filled in turn, each as wide as the section gives, before the
next page: text moves to the next column when it doesn't fit, or is kept
with what is there, and a column break starts the next column, or a new
page in the last. A section in columns that starts on the same page as
the text before it starts its columns below that text.
Word and LibreOffice even out a section's columns before a continuous
section break, so the next section starts below the longest, and which
lines go in which column isn't followed yet, so the layout stops there,
as it does at a footnote in columns and at a table's header rows repeated
at the top of a column.
scripts/compare-layout.sh reads LibreOffice's text in reading order, so a
page's columns come one after the other rather than side by side. A new
layout demo, columns, has sections of one, two and three columns. All 227
headings of the 9 demos are on LibreOffice's page.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken
* feat(layout): write the numbers of pages into NUMPAGES and SECTIONPAGES fields
paginate counted the pages, but nothing wrote the count, so "Page 3 of"
footers were written without their number, which applications that show
fields as they are written show blank. Now docx/layout works out the
number of pages of the document, when it lays all of it out, and of each
section whose pages are its own, laying the pages out again until the
numbers, which can change how lines wrap, stay the same.
EstimatedPageNumbers gains pageCount and sectionPageCounts, and docx
writes them into the NUMPAGES and SECTIONPAGES fields of the body, and
of the headers and footers once the body is written, with the page
references in them. A header or footer shows the number of pages of the
sections it is on only when they all have the same. A section that
shares a page with another, or has a blank page before or after it, is
left blank, as is a field in a number format of its own. Like PAGEREF
fields, those with a numeric picture (\#) are left as they are.
scripts/compare-layout.ts checks the numbers of pages written into the
demos against the pages of LibreOffice's PDFs: both demos with them match.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken
* fix(layout): keep a paragraph with the next on a new page when they fit there
Whether what is kept together fits in a fresh column was measured from
where the page's columns start, which is partway down the page below a
continuous section break. When the column is the last, the kept
paragraphs go on a new page, whose text starts at the top, so a heading
that would fit there with the next paragraph stayed at the bottom of the
page, and the paragraph moved on alone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken
* fix(layout): stop at a section whose columns differ in width
A paragraph is broken into lines at the width of the column it starts
in, and a paragraph that goes on into a column of another width kept
those lines, so its height, and the pages after it, were wrong. Breaking
the rest of a paragraph again needs to know where each line starts in
its text, so a section with columns of different widths stops the
layout, and the page numbers after it are left blank.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken
* fix: fail the layout comparison when LibreOffice didn't lay out a document
The comparison skipped a document without the text of LibreOffice's
pages, as when LibreOffice fails to convert it, and reported its
headings as matching, so CI could pass without comparing it. Now it
fails, and names the documents LibreOffice didn't lay out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NijyutGmb3bNR3dNRWJken
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* feat: math from LaTeX in docx/math, with accents, bars, braces, boxes, phantoms and large operators
latexToMath turns LaTeX math into docx's math components, to go in a Math.
It reads what LaTeX, MathJax and KaTeX write: fractions, roots, scripts,
large operators, functions, \left and \right, accents, braces, boxes,
fonts, \text, and the environments for matrices, cases and aligned
equations, with \tag. It throws for what it can't read, saying where.
The parts LaTeX needs are public components too: MathLargeOperator,
MathAccent, MathBar, MathBrace, MathBox and MathPhantom in docx/math, and
in docx, MathRun's style, script and literal, MathFraction's type, and
limits on MathSum and MathIntegral.
Closes#2994
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix: draw MathRun alphabets upright unless given a style, and escape the \middle| table cell
A run with a script but no style wrote no m:sty, which Word draws as italic, so sansSerif came out italic
sans-serif rather than the upright 𝖠 its docs show. A script other than roman now defaults to a plain style,
as LaTeX draws its alphabets; a given style is kept. latexToMath already gave each alphabet its style.
The | after \middle in the LaTeX docs' table ended the cell, splitting the row into three.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
docx 9.8.0 is the first release with docx/math, and its types import the math classes from docx and
export them again. The check renamed only the classes declared in an entry point's own types, then
looked for that renamed copy of every exported class, so it reported all 24 math classes as breaking.
It now renames only the classes an entry point declares. The ones it imports from docx resolve to the
build's classes, and are compared in docx's own check.
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* chore: organise the demos into a folder for each topic
The demos were one flat list of 124 numbered files, which made it hard to
find the one you wanted. Each is now in a folder for its topic, such as
demo/tables/basic-table.ts, with a name that says what it shows instead of
a number.
npm run demo lists every demo and narrows the list as you type. It also
takes a demo's path or name, a topic, or search words.
The demos' images moved to demo/assets/images, as images is now a topic.
The docs' links, the Demos workflow, the shape render script and its
reference images use the new paths and names.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix: list only a topic's own demos, and drop stale output file names
npm run demo text also offered the text-boxes demos and others with
"text" in their name, so a topic now searches for "text/". Three demos
logged their old numbered file name after writing My Document.docx.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(demos): give each image its type, and each revision in demo 98 an id of its own
ImageRun's type is required, but 11 demos left it out. The image was then written as <hash>.undefined, which isn't in
the package's content types, so Word can't open it and the Open XML SDK validator stops there. The demos now give the
type of the file or base64 data they read, as demos 5 and 114 do.
Demo 98 gave the same revision id to each mark of one change, such as every cell of an inserted row. Word needs each
w:ins, w:del, w:cellIns, w:cellDel and property change to have an id of its own, so they are now numbered in order.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(shapes): write a custom dash or gap of 0 as the smallest length Office accepts
A custom dash of length 0 with round caps draws dots, as demo 111 does. ISO allows a:ds d="0", but Office's schema
wants d and sp to be at least 1, so the Open XML SDK validator rejected it. A dash or gap of 0 is now written as 1,
a thousandth of a percent of the line width.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(numbering): write a level's alignment as left, center or right
Office's schema only allows left, center and right in w:lvlJc, where a paragraph's w:jc takes every AlignmentType.
Levels default to AlignmentType.START, so every numbering part failed the Open XML SDK validator.
A level's alignment is now written as Office allows: START and the justified alignments as left, END as right.
The alignment option's type is unchanged.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(numbering): write a level's children in the schema's order
A level wrote w:suff before w:isLgl, and w:pStyle after w:lvlJc. CT_Lvl puts w:pStyle after w:numFmt, and w:isLgl
before w:suff, so a level with a paragraph style, or with legal numbering and a suffix, didn't match the schema.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(demos): write demo 19's base64 string as the document it encodes
Demo 19 wrote the base64 text itself to My Document.docx, which isn't a document, so Word can't open the file and it
can't be checked. It now decodes the string before writing it, which also shows that the string is the whole document.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix: write paragraph borders in the schema's order
Paragraph borders were written top, bottom, left, right, where CT_PBdr wants
top, left, bottom, right, between. Word files with left or right paragraph
borders didn't match the schema, which the Open XML SDK reports as an
unexpected element.
Table, cell and page borders were already in their schemas' order.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix: stop writing w:highlightCs, which is in no schema
Every highlight was written twice: as w:highlight and as w:highlightCs. There
is no w:highlightCs in WordprocessingML, so documents with highlighted text
didn't match the schema, and the Open XML SDK reports it as an invalid element
in the run properties. w:highlight already highlights all of a run's text,
complex script included.
highlightComplexScript is kept, deprecated, and has no effect.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix: write tab stop positions as whole twips
A tab stop's position was written as given, so one worked out as a fraction,
such as TabStopPosition.MAX / 4 * 3 (6769.5), was written as a decimal. w:pos
is ST_SignedTwipsMeasure, a whole number of twips, so the document didn't
match the schema. Positions are now rounded down, as indents already are.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix: write shading without a pattern as clear shading
w:shd's w:val is required, but shading given only a fill or a color, with no
type, was written without it. The document didn't match the schema, and the
Open XML SDK reports a missing required attribute. Shading with no type is now
written with w:val="clear", the fill color only, which is what Word writes.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(fonts): write an embedded font's key in upper case
w:fontKey is an ST_Guid, whose pattern only allows upper-case hex digits, but the key docx generates is lower case,
so the Open XML SDK validator rejected the font table of every document with an embedded font. The key is now written
in upper case. The font is obfuscated with the same bytes either way, since the obfuscation reads the hex digits in
either case.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(textbox): stop writing insetmode on a VML text box
A VML text box was written with insetmode="auto", without the o: prefix it needs. With the prefix, the Open XML SDK
validator still rejects it, as Office only takes o:insetmode on the shape. It's no longer written: its default, custom,
uses the inset attribute, which defaults to Word's usual margins when it's left out, as it always is for a text box.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(patcher): put merged run properties in the schema's order
With keepOriginalStyles, a patched run that has run properties of its own takes the placeholder's too. They were
written with the placeholder's first and the run's after, so a run with a font whose placeholder had a size got w:sz
before w:rFonts. ISO 29500 allows any order, but Office's schema doesn't, and the Open XML SDK validator rejected
demo 89. The merged properties are now put in Office's order: CT_RPr's elements, then Word 2010's text effects and
OpenType features, then any it doesn't know, then w:rPrChange.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(styles): write each style id once, and the document defaults first
Two styles could share an id, which a styles part doesn't allow:
- with externalStyles, docx's default styles were written in front of the external ones, so a style such as Heading1
was there twice, as were w:docDefaults. The external w:docDefaults and w:latentStyles also came after docx's styles,
where CT_Styles wants them first;
- a paragraph or character style with a default style's id, such as Heading2, was written after the default one
instead of replacing it.
Styles now writes the document defaults, then the latent styles, then the styles, and a style replaces an earlier one
with its id. So external styles take the place of docx's default styles, docx's fill in the ones they leave out, and
paragraph and character styles take the place of the default ones.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(settings): write the settings in the schema's order
w:evenAndOddHeaders and w:updateFields were written before w:defaultTabStop and the hyphenation settings, and
w:hyphenationZone before w:consecutiveHyphenLimit, where CT_Settings wants them after. Word's validator rejected
settings.xml whenever a default tab stop or hyphenation was set, as in demo 75.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(settings): write the compatibility mode last in w:compat
w:compatSetting was written first in w:compat, where CT_Compat puts it after every other element, so a document with
any compatibility option, as in demo 76, didn't match the schema.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(sections): write a section's previous properties after the document grid
w:sectPrChange was written before w:docGrid, where CT_SectPr puts it after every other element, so a section with a
tracked change, as in demo 98, didn't match the schema.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(tables): write a floating table's overlap beside w:tblpPr
The float option's overlap was written as w:tblOverlap inside w:tblpPr, which CT_TblPPr doesn't allow children in, so
a floating table with an overlap, as in demo 34, didn't match the schema. It's now written in w:tblPr right after
w:tblpPr, where CT_TblPrBase puts it. createTableFloatProperties no longer writes it.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(tables): write a row's cantSplit and tblHeader, and a table's bidiVisual, as off when false
These were written as w:val="false". ISO allows that, but Office's schema only takes on and off for them, so Word's
validator rejected a row with cantSplit or tableHeader set to false, as in demo 98's row revision, and a table with
visuallyRightToLeft set to false. Off is now written as "off", which both schemas accept.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(tables): write a table's cell spacing after its alignment
w:tblCellSpacing was written last in w:tblPr, after w:tblLook, where CT_TblPrBase puts it between w:jc and w:tblInd.
Word's validator rejected any table with cellSpacing and another property after it, such as the borders every table
has.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(math): write sums, integrals and pre-scripts in the schema's order
- A sum or integral without a limit left out its m:sub or m:sup. CT_Nary needs
both, so a hidden limit is now written empty, as Word writes it
- m:naryPr wrote supHide before subHide; the schema wants subHide first
- m:sPre wrote the base before the scripts; the schema wants sub, sup, e
The other math structures already match shared-math.xsd.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix: write a run given in a run's children beside it, not inside it
A FootnoteReferenceRun in a TextRun's children, as demo 60 has, wrote a w:r
inside a w:r, which the schema doesn't allow.
- A run with a run in its children now ends before it. The inner run, such as
the footnote reference with its own style, comes next, and the children
after it go in a run with the outer run's properties, as Word writes it
- The same goes for a DeletedTextRun's children
- A component can now be written as several side by side (writtenAs), which
the serializer and the patcher use for such a run
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* ci: check the demos with the Open XML SDK validator, with none left out
Every demo's document now passes Microsoft's Open XML SDK validator, which checks each part against Office's schemas,
so the demos are checked with it instead of xmllint, and the list of demos left unchecked is gone.
xmllint only checked document.xml and the theme against the bundled schemas, which are Word 2007's: they don't declare
the Word 2010 extensions that templates and shapes use (w14:paraId, w14:checkbox, wps, wpg, mc:AlternateContent), so
26 demos weren't checked at all. The validator understands them, checks every part, and found the bugs fixed before
this. The validator is 80 MB, so it's installed only in this workflow rather than as a dependency.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(styles): let the default styles given in styles.default take the place of external ones
With externalStyles, a default style given in styles.default, such as heading1, or the document defaults given as
document, was replaced by the external style with its id, so the option did nothing. Now the external styles replace
only the default styles that weren't given, and the ones given replace the external ones.
Before, both were written, the default one first. ISO 29500 has the first of two styles with an id keep it, so the
style given in styles.default was the one that applied, as it is again.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(tables): write a cell's merge revision before its previous properties
w:cellMerge was written after w:tcPrChange, where CT_TcPr puts it before, so a cell with both a merge revision and a
property revision didn't match the schema, which the Open XML SDK validator reports as an unexpected element.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(numbering): leave highlight, math and revision out of a level's run properties
Office's schema doesn't allow w:highlight, w:oMath or w:rPrChange in a numbering level's run properties, so the Open
XML SDK validator rejected the numbering part of a document whose level's run style had a highlight. None of them
applies to a level's number, so they're no longer written. The option's type is unchanged.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* fix(demos): make parrots.bmp a bitmap
demo/images/parrots.bmp, the bitmap demos 5, 23 and 114 show, held PNG data, so those documents had a part typed
image/bmp that wasn't a BMP. It's now the same picture as a 24-bit BMP, with the same pixels.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
* Add schemas and validators
* Fix dependencies
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- `paths` draws a custom shape from several paths, each filled with the
shape's fill, not at all, or lighter or darker, and with or without its line
- A closed part of a path inside another is a hole, whichever way round it
is drawn: parts are turned round so both fill rules cut the same holes
- `textArea` sets where a custom shape's text goes, and "fitText" fits it
- `connectionPoints` gives a custom shape its own connection points
- Connection sites and text areas are guides that keep their share of the
shape when it is resized, as PowerPoint writes freeforms
- Demo 120, with a reference render, and docs in shapes.md
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Shapes in a ShapeGroupRun or the new ShapeCanvasRun can have an `id`, and a
child with `type: "connector"` joins two of them:
{ type: "connector", from: "start", to: { id: "step", side: "top" }, route: "elbow" }
The connector is drawn from one shape to the other, so it needs no size or
position. It attaches at the shapes' connection sites (a:stCxn/a:endCxn),
choosing the facing sides unless a side is given, and routes as Word does:
a straight line, or elbow and curved connectors that leave and arrive at right
angles and loop around shapes when they have to.
Word only keeps connectors attached when shapes move on a drawing canvas, so
ShapeCanvasRun writes a wpc:wpc canvas with an optional background and outline.
Connection sites come from the preset shape definitions of ECMA-376:
scripts/generate-preset-shape-geometry.ts extracts each shape's sites and the
guides they depend on, and a small evaluator calculates them for a shape's size
and adjustments. A test also checks the adjustments table against the
definitions.
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>