Repository navigation
fix(docx): stack drawings in Word as the page paints them - #922
Merged
Merged
Conversation
Word stacks drawings by the place each is given (relativeHeight), a later one over an earlier one, and the export gave them their places in the order it happened to draw them: a stack's or a shape container's layers in the order given, columns' marks after the columns' content. A layer the page stacks under another by its zIndex, given after it, then stood over it. Measured in Word and LibreOffice on Windows, a white dot at zIndex 0 given after a disc at zIndex 1 stood over the disc in both, where the page hides it, in a stack that only draws, a shape container, a band of layers with text and a stack nested in such a band. Only the shape container was named for it. Each drawing now takes its place from where the page paints the fragment it is drawn from: the fragment's index in the layout's paint order, eight places a fragment, its shapes in the order they come (DocxDrawingAnchors.ordered, DocxLayoutMetrics.paintIndexOf). Both editors draw the dot under the disc in all four. The text keeps the order it is written in, a drawing's name its old number, and the shape container is no longer named for the order of its layers. The places order the drawings behind the text among themselves, and those in front of it. In the fidelity corpus 34 of the 62 files change, in those places only: 26 stack as before, and the 8 whose order changes render pixel for pixel as before at 96 dpi in Word and in LibreOffice. The Word export example's DOCX is re-rendered for it.
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
Word stacks a document's drawings by the place each is given (
wp:anchor/@relativeHeight), a laterone over an earlier one. The export gave each drawing its place in the order it happened to draw it
(
DocxDrawingAnchors.ordered: a running counter). The page paints a layer stack's and a shapecontainer's layers by
zIndex, while the export draws them in the order given, and draws columns'marks after the columns' own content. A layer the page lays under another, but given after it, came
out on top.
Measured in Word 16 and LibreOffice on Windows: a white dot (
zIndex0) given after a blue disc(
zIndex1). The page hides the dot.Only the shape container was named, with "its layers are written inline"; the other three went
unsaid.
What changed
DocxDrawingAnchors.ordered(shapes, painted): a shape's place is the index of the fragment itis drawn from in the page's paint order, times
PLACES_PER_FRAGMENT(8; a fragment is drawn as fiveshapes at most), plus its index among that fragment's shapes (capped at 7).
zIndex.after its shapes so far, so it ties with none.
docPr, "Drawing N") keeps the running number (Ordered.drawn), so namesare as before.
DocxLayoutMetrics.paintIndexOf(fragment | node): a fragment's index in that order; a node'sis its first own fragment's.
DocxSemanticBackend: every place a drawing is queued passes its fragment's index:paintsOutOfSourceOrderis gone.DocxDrawings.stackHeightholds the value to a signed 32-bit count, which LibreOffice reads. Pastabout 230,000 fragments in one section, drawings would share the top place.
layersentries ofDocxNodeFieldLedgerTestfor the stack and the container;assets/readme/examples/word-export-companion.docxis re-rendered. Its one drawing'srelativeHeightchanges and nothing else.Verification
relativeHeightvalues only;serif_headline, slate_orange, terracotta_rail, violet_grid) render pixel-identical at 96 dpi,
before and after, in Word and in LibreOffice;
DocxLayerPaintOrderTest(new, 9 tests, read off each anchor'srelativeHeight):zIndex.DocxDrawingAnchorsTest(+3):DocxDrawingsTest: the container stacked out of source order is now stacked so, and not named../mvnw -B -ntp clean verify: BUILD SUCCESS (core 821, render-docx 1805, examples 93, qa 1820); the knowledge pack's--checkpasses.The places order the drawings behind the text among themselves, and those in front of it. Word draws
every one behind under every one in front: on a painted panel, a layer framing text stays behind while
one that does not stands in front, whatever their
zIndex. That split is unchanged.Lane: render-docx (semantic backend). DOCX output changes for every document with drawings, in
relativeHeightvalues: where the page stacks overlapping drawings in another order than the exportdrew them, they now stack as on the page.