Repository navigation
fix(docx): space a centred or right-aligned line of its own to the page's width - #841
Merged
Merged
Conversation
…ge's width Word sets a size the page gives to the tenth at the half point, and a centred line moves its first letter by half the width that makes, a right-aligned one by all of it: CenteredHeadline's 8.3pt contact line stood 4pt left of the page's. Where the difference is a point or more, the line's letters are now spaced by it (w:spacing), the size left as Word sets it, and the line is given room for the page's width; a tracked line and a difference under a point are left alone. Lines more than 2pt off across fall from 23 to 12 in Word and from 29 to 18 in LibreOffice; nothing moves down.
…tting it at twentiethsToThePage decides once, from the layout's line, whether and how far a centred or right-aligned line's letters are spaced, and the room oneLinesMeasure gives it follows: the page's width where it is spaced, its own at Word's size where not. Reckoned from Word's wider width, a line condensed back kept room it no longer needed, which in a cell comes off the right and moved a right-aligned line right. A line with a picture or a shape is left alone; the runs are wrapped through the non-deprecated XWPFRun constructor. The Linux LibreOffice baseline is this branch's CI measure.
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 states a type size in half points, so it sets a size the page gives to the tenth a little larger or smaller, and a line that much wider or narrower. A line set from its left keeps its first letter where the page puts it; a centred line moves it by half the difference, a right-aligned one by all of it.
CenteredHeadline's 8.3pt contact line, set at 8.5, stood 10pt wider in Word, its first letter 4pt left of the page's.ClassicSerif's 8.7pt one stood 4pt right.Scaling the glyphs (
w:w) stays out: a scale would stay on the text a reader types next, and measured, it changed where Word brokeCompactMono's lines.What changed
twentiethsToThePagedecides, from the layout's line, how far apart to space a centred or right-aligned left-to-right paragraph the layout set on one line: the difference between the page's width and Word's at its half-point size (askedWidthagainstwidthAtWordsSize) spread over its letters, in twentieths of a point, to the nearest. Twentieths, not whole tenths: on the corpus they put 74 lines in Word nearer the page where whole tenths put 64.setTheLineAsWideAsThePage(afterwriteParagraphRuns) writes that as character spacing (w:spacing) on every run, an internal link's included (runsIn). The size is left as Word sets it.giveBackWidth).TealPulse's tracked tagline went from +0.44 to −1.00.ObsidianInvoice's 9.34pt amounts, half a point wider by the size alone, came out as wide as the page's in Word, and spacing them moved them half a point off.oneLinesMeasure. A centred or right-aligned line of its own is given room for the width Word ends up setting it at, a few hundredths past it: the page's where its letters are spaced, its own at Word's size where not. Reckoned from Word's wider width, a line condensed back to the page's would keep room it no longer needs, and in a cell, where the left edge cannot give it, that room comes off the right and moves a right-aligned line right.Verification
scripts/docx-visual/word-fidelity.ps1 -Update(Word 16.0.20430) → BUILD SUCCESS.MerchantInvoice−0.29 → +0.31); the down column is unchanged in every row.MeteredInvoice's amounts,BlueBanner,VioletGrid,CenteredHeadline's contact line (−3.96 → +0.60) andClassicSerif's (+4.03 → −0.53).MeteredInvoiceamounts at most 0.11pt further (+0.17 → −0.28); nothing moved down.Panel's right-aligned contact lines: they move the same point right on every platform, nearer the page on Windows in both editors (Word −0.72/−0.42 → +0.36/+0.30) and further on Linux, where LibreOffice already set them 7.4pt right.DocxWordSizeMeasureTest, four new:./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 -am→ BUILD SUCCESS (qa 1820 tests).CommittedAssetDriftTest→ 3/3 green.Notes
Lane: shared-engine (render-docx).