fix(docx): anchor a drawing that is all its table cell holds in that cell, so it moves with its row - #798
Merged
Conversation
…cell, so it moves with its row
… a repeated header's later copies, and leave a padded stack to the page
…cell's only drawing, and drop a header's copies only on later pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Every shape the DOCX export draws is anchored to the page:
positionH/positionVrelativeFrom="page", at the layout's coordinates. A drawing that sits alone in a table cell (an icon beside its label in a row, which the export writes as a Word table) therefore stays at its page position, while Word lays the rows above it out a fraction of a point taller or shorter than the page.CobaltRota, the three band icons stood 4pt, 9pt and 14pt above their labels in Word. The last one stood above its navy strip.DocumentTableCell.node) has no place of its own in the layout. Its fragments are the table's, under the table's path, so nothing tied them to their row.What changed
DocxDrawings.drawingInCell/CellOrigin. A drawing anchored in a table cell's paragraph:layoutInCell="1", placed from the cell's text column (positionH relativeFrom="column") and the paragraph's top (positionV relativeFrom="paragraph").DocxDrawingAnchors.anchorInCellputs it in a given paragraph.drawingCellFor,DrawingCell).paintsInsideItsBox).queueDrawingsanchors the drawing's shapes there.anchorComposedDrawing,DocxCellDrawings).drawCellDrawingkeeps the table's drawings waiting (tableDrawings) instead of anchoring them at once.DocxLayoutMetrics.cellBoxesgives every box where the layout placed the table's cell being written, first placement first. It is found by the cell's name among the table's own rows, once per table, so an unnamed table nested in a cell does not lend its cells' boxes to the outer one (as long as the nested table stops short of the outer table's width).w:tblHeader) is repeated by Word together with the drawing anchored in it. So the header's copies in its boxes on later pages are dropped rather than drawn a second time on the page.DocxDrawingAnchors.Ordered). A shape takes its place in the paint order when it is drawn, not when it finds a paragraph.DocxCellDrawings.holdsALine). A line alone in a cell, or in a stack of one layer, is a rule written as a paragraph border.queueDrawings, so a badge alone in its cell is anchored there.CHANGELOG.md, the composed-cell paragraph ofdocs/recipes/docx-export.md, and the rectangle and ellipse rows ofdocs/architecture/backend-capability-matrix.md.Verification
./mvnw -B -ntp clean verify -pl :graph-compose-core,:graph-compose-render-pdf,:graph-compose-render-docx,:graph-compose-render-pptx,:graph-compose-templates,:graph-compose-testing,:graph-compose-qa,:graph-compose-coverage -amgives BUILD SUCCESS (1791 + 127 tests).DocxCellDrawingTest(new, 14 tests).DocxComposedCellTest.aTileHoldingOnlyDrawing…now also asserts the composed tile stays on the page.DocxDrawingsTest.aBadgeOutsideAPanelHoldsItsInitialsToonow expects the badge, alone in its row's cell, to be anchored in that cell.2.5-dev: five documents change. The figures below are measured on exactly the output this branch writes.CobaltRota, Word: p90 drift 11.7pt → 6.4pt, lines more than 2pt off 45 → 42.CobaltRota, LibreOffice: p90 10.2pt → 7.3pt, lines more than 2pt off 47 → 46.CobaltRotastays one page. In Word and in LibreOffice each band icon stands beside its label.ProposalNorthline: lines more than 2pt off in Word 7 → 6.MerchantInvoice,PlatformInvoiceandProposalEditorial: text drift and page count unchanged in Word and in LibreOffice.Known limits
ownRows' width test, so its composed drawings stay on the page.placedRow,rowHeightandtableColumnsshare that test.MerchantInvoicestill runs to two pages in Word. That comes from its payment panel's border, which Word keeps inside the row, and is a separate change.Lane: shared-engine (render-docx). No public API change.