Repository navigation
fix(docx): keep a colour's translucency where Word holds it, and flatten and name it where it does not - #865
Merged
Merged
Conversation
…ten and name it where it does not Text is written with its transparency as Word's text fill (w14:textFill), w:color keeping the colour as authored; an opaque run or list marker under a translucent Normal style writes an opaque fill of its own, a paragraph's mark takes its text's fill, and each fill is settled last among its run's properties on a part marked mc:Ignorable. A cell's shading, a border and a rule hold an opaque colour only: a translucent panel fill, table cell fill, rule and chip shading are flattened against what the layout paints under them (a row's unwritten fill left out), a panel's borders and a cell's rules against the block's own fill, a header's separator against white, and each is named in the report as translucency.
…nt on the panel as written The header and footer parts made in an export are found through the document's relations: POI lists in getHeaderList() and getFooterList() only the parts it read, so their text fills were not moved last and their roots not marked mc:Ignorable. Inside a panel or cell the export shaded, a chip, a rule, a panel and a table cell flatten against that shading as written, so a panel flattened at its centre is one colour wherever its content stands; the layout is read on the page. The empty index with no layout is not asked for a cell.
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
A translucent colour (
DocumentColor.rgba(...),withOpacity(...)) lost its alpha in the DOCX export, and the report said nothing:w:shdandw:tcBorders, which take an RGB and nothing else.NavySidebar's sidebar rules — white at 115/255 — came out pure white over the navy sidebar the page background paints. A header's separator was flattened against white.Drawings, page backgrounds and pictures already kept their alpha (DrawingML
a:alpha, PNG).What changed
DocxTranslucency.writeTextAlpha).w14:textFillwith a transparency (Word's Font → Text Effects → Transparency).w:colorkeeps the colour as authored. Measured in Word 16.0.20430 and LibreOffice: Word takes the colour from the text fill, LibreOffice fromw:color, each with the fill's transparency. A flattenedw:colorwould be lightened twice in LibreOffice.copyTextFill), since a nested level's marker is drawn in the mark's style.DocxTranslucency.settlemoves each fill last among its run's properties — a decoration, a chip's shading or a direction is written on a run after its colour. It also marks the namespacemc:Ignorableon each part that holds one: the body, the styles, the numbering, and each header and footer, found through the document's relations since POI lists only the headers and footers it read. A part with none is untouched.DocxLayoutMetrics.colourUnder): the fills painted before the block's first fragment, composited at its centre over white. That covers rectangles, ellipses, polygons and paths, throughDocxInkOutline's outlines, and table cells, a page background included.row paint).colourUnderCell, at the cell's centre, its table's first row on that page cached);translucency,APPROXIMATED: once per panel, once per table, per rule, and once per separator however many header parts it is written into. A chip's flattened fill is named on itsinline chipnote, as before.DocxTranslucency.toHexColoruses itshex.DocxNodeFieldLedgerTest): these move toREPORTED, each naming its translucency case:fillColor,strokeandborders;strokeand a shape'sfillColor;rowsand cell styles;inlineRuns, and a list'sitemsandnestedItems, for a chip's fill;headersAndFootersoption.render-docx/README.md;DocumentColor.rgba's Javadoc, which said the DOCX backend renders the colour fully opaque;Verification
./mvnw -B -ntp install -pl :graph-compose-render-docx→ BUILD SUCCESS: 1122 tests, 0 failures, 1 skipped (the property-gated fidelity probe).DocxTranslucencyTestis new, with 26 tests, all laid out (none falls back to an export without a layout). Every expected colour is worked out by hand from the authored channels.w:coloras authored and a text fill at its transparency; opaque text has none;mc:Ignorable="w14"while the styles part, with no fill, is untouched;mc:Ignorable="w14"on its root and each fill last of its properties;495266, not white);ContainerNode's fill;2E5990), a rule (072042) and a translucent cell (074EA6) in its white half composite over the panel as written.572850), named once; a cell merged across two rows, flattened as one, its covered position too.828896— and a line over white (7F7F7F); a rule in a filled row, over white.mc:Ignorable, a header's and a footer's parts settled;DocxFidelityCorpusTest -Dgraphcompose.docxFidelity=export), SHA-256 per file against the export before the change. 61 are byte-identical;cv-navy_sidebardiffers in exactly its four sidebar rules,w:color="FFFFFF"→858B93, which is white at 115/255 over the sidebar'sNAVY(32, 44, 59). Word 16.0.20430 renders the rule under EDUCATION at (133, 138, 146), where the PDF draws (131, 138, 146); before this change Word drew it at (255, 255, 255).-Dtest='com.demcha.documentation.**'→ 166 tests, 0 failures; qa documentation guards plusDocxPageZoneTest,DocxTransparentWrapperTest,TimelineRailAcrossBackendsTestandRtlAcrossBackendsTest→ 50 tests, 0 failures.Known limits
Lane: render-docx backend, plus tests and docs.