fix(docx): stand text on the page's baseline in Word's exact lines - #789
Merged
Merged
Conversation
Word and LibreOffice stand an exact line's baseline four fifths of the way down it whatever the face; the page sets it the face's ascent down. Runs are moved to the page's baseline where the two are half a point or more apart, and lines a container stacks tighter than their face are written a pitch tall, the last to the container's foot.
… whole Word draws an exact line's text on screen only inside the line, though its PDF export draws it whole. Lines a pitch tall cut the title's descenders and capitals; each line of a stack now ends halfway between its letters and the next line's, read from the glyph outlines.
… the page still A stacked line seated off its baseline has its letters' reach read where the page sets them. Lines whose letters meet are still split halfway, so the page does not move; a stack line is seated however small its shift; letters hanging past a container's foot are always taken from the gap below; a line with space above or below it stays out of a stack.
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
In Word,
NorthlineProposal's section headings stood 8pt below the badge icons drawn beside them, and so did everything else on its cover. The icons are drawn where the page puts them; the text in the flow was low for two reasons.What changed
shiftToThePagesBaseline. A paragraph's runs are moved (w:position) by 0.8 × the written exact line less the page's baseline depth in that line, added to theTextVerticalAlignseat of fix(docx): seat text off its baseline as the page does and hang text below its band #787 inseatInTheLine. The page's depth is measured from where Word's line starts:lineTopAbove, from the newDocxLayoutMetrics.firstLineTop);applyLineGaprecords it);A paragraph not written at an exact height is left to Word. A difference under half a point is left too: a line of Lato body text is a quarter point off, and moving every such line would win a quarter point at most. List items and table text cells are not moved yet.
DocxStackedLines. Word draws an exact line's text on screen only inside the line, although its PDF export draws it whole. Lines a pitch tall cut the title there: "Proposal" lost its descenders, "Brand Refresh" the tops of its capitals.DocxInk).hangBelowItsBoxtakes that overhang from the gap below.NaNpath for plain containers ends the last line where its own line ends.EditorialProposal's 41.8pt title, set 41.9pt apart, leaves a point between the "p" of one line and the capitals of the next, and stacks.DocxTextBands.BASELINE_SHAREnow documents the measurement, and is the one constant both uses read.Docs.
CHANGELOG.md, the paragraph row ofbackend-capability-matrix.md, and the line-height and stacked-layers text ofdocs/recipes/docx-export.mdare updated; the earlier v2.5.0 entry for stacked lines is amended to the new rule. A picture among moved text moves with it in Word; LibreOffice keeps a picture on its own baseline, where it stood before.Verification
Full reactor gate:
./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). After install, examples are 93 green, and the knowledge checks andextract-api --checkpass.DocxBaselineSeatTest(new, 5 tests). Each part of the seat was removed in turn, and each removal failed only its own test.DocxStackedLayersTest. Each line of a stack, theNorthlineProposaltitle's included, stands on the page's baseline within 0.3pt, and its letters' tops and feet lie inside its Word line. With the edges put back at the page's line tops, "Proposal"'s feet fail.DocxBaselineSeatTest), and a line holding a picture has no letters to read (DocxInkTest).DocxInkTest(new). A line's reach matches Spectral's ownxandpoutlines read with fontbox, and is less than the face's ascent plus descent.Word on screen. A capture of Word's window, from a private visible instance, shows both titles and
EditorialProposal's "NORTHLINE / STUDIO" whole. Before this change, they were cut.DocxVerticalSeatTestnow measuresTOP/CENTER/BOTTOMfrom theDEFAULTseat, and checks that a label keeps its position when the value beside it is seated.Template corpus (62 documents), converted to PDF by Word, baselines matched by text:
NorthlineProposalEditorialProposalNorthlineProposal's cover is within 1.5pt of the page throughout (at most 1.3pt), and its headings level with their icons. No document's median got worse by more than 0.15pt. In LibreOffice the corpus median falls from 2.01pt to 1.60. Page 2's remaining drift is its table rows, each about 0.7pt taller in Word — a separate change.Lane: shared-engine (render-docx). No public API change.