mirror of
https://github.com/dolanmiu/docx.git
synced 2026-11-30 16:47:55 +01:00
* 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>