Repository navigation
fix(docx): write an auto-sized paragraph's text at the size the page fits it to - #870
Merged
Merged
Conversation
…fits it to The page fits a paragraph with autoSize(...) to the largest size its line holds, smaller or larger than its style's; the export wrote the text at the style's size and named both sizes. Word broke a shrunk headline onto more lines than the page's and set everything under it lower. writtenStyle reads the fitted size off the layout's lines (fittedSize): the share the page sets markdown pieces at (DocxMarkdown.scaleIn), the lines' one size for other plain text, or the size no run's own style has. Text with no style of its own, the paragraph's mark, markdown pieces, a prefix's indent and a badge's initials take it, on every path that writes a paragraph. Where the lines do not tell it, the text keeps its style's size and the note says the fitted size is not measured.
…auto-sized paragraph by what was written A page zone the page draws with other content on its first page than it is written with takes no lines from that page (ZonePlacement.asLaid, zoneTextAsWritten): a footer reading "End", fitted from page 1's longer line, was written at that line's size and not named. Where the pieces of a paragraph read as markdown are not found in its lines and the page dropped a mark, fittedSize says the size is not told: an Arabic heading-only line, shaped before the marks are read, was written at its heading's size, unnamed. The note reads what was written (fittedWritten); fittedSizeUntold answers before writing, for a zone line's height and its parts' widths. A heading's note names its size at Word's half point. laidOutIn is strict only; cell matching reads the share through scaleIn.
…e for a paragraph placed twice A page zone the page draws otherwise on its first page took no lines for any of its parts, so a part drawn as written beside one that changes lost its markdown pieces: `**Acme**` was written with its asterisks. ZonePlacement.laidOtherwise now holds only the parts drawn otherwise (DocxZoneParts.partsReadOtherwise); the others keep their lines. A paragraph added at more than one place is fitted at each apart, and the layout index holds one place's lines: it was written at that size everywhere, unnamed. DocxLayoutMetrics.placedMoreThanOnce counts the places, table cells included, and the size is not told there. fittedStyle returns null where the size is not told, and the writers record by it rather than by the identity of the style they write.
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
autoSize(...)fits a paragraph to the largest size its line holds, smaller or larger than its style's, and the PDF draws that size. The DOCX export wrote the text at the style's size and named both sizes on the paragraph's note. On a page of auto-sized paragraphs in Word 16:What changed
fittedStyle(node, lines)is an auto-sized paragraph's style at the size the page fits it to, where its lines tell it. It isnullwhere they do not.writtenStyleis that style, or the node's own where there is none. A run with a style of its own keeps it, as on the page.fittedSizereads the size off the lines:DocxMarkdown.scaleIn. A heading stands at a multiple of the fitted size, so the lines' first size is not the paragraph's. Where the pieces are not found and the page dropped a mark, the size is not told. One such case is Arabic, which the page shapes before it reads the marks: a heading-only line's one size is the heading's.markdown(false), or an underscore inside a word — is plain text here.DocxLayoutMetrics.placedMoreThanOnce): the size is not told. The page fits it at each place apart, and the layout index, keyed by the node, holds one place's lines.writeParagraphRunswrites text with no style of its own at the fitted size, and reads the markdown pieces at it.markdownPieceshands the written style topagePieces. The pieces are then checked against the lines exactly, tracking included (DocxMarkdown.laidOutIn, now strict only). Before, an auto-sized paragraph's pieces were held to the proportion their first letter set, with tracking not compared.textBadgeParagraph,badgeParagraphXml) take the fitted size on a path of their own.ZonePlacement.laidOtherwiseholds the parts the page drew on the zone's first page with other content than they are written with (DocxZoneParts.partsReadOtherwise, part by part);zoneLinesOfgives those no lines. A footer reading "End" on the last page and a longer line on page 1 no longer takes page 1's fitted size. A part the page drew as written beside it keeps its lines, and its markdown is read from them.indentAsThePrefixDoesmeasures a prefix at the written size, the size the page measures it at.markdownHeadingCutmeasures a heading against the written style. A heading at twice a fitted size is still found where that is smaller than the style's. The heading note, inheadingCut, names the size at Word's half point for every heading, a list item's too.fittedWrittenrecords each auto-sized paragraph written at itsfittedStyle, andautoSizeLostnames the rest: its text is written at its style's size, and the fitted size is not measured. A path that writes a paragraph otherwise is named, not passed.fittedSizeUntoldanswers the same question before writing, for a zone line's height and the width of its parts.DocxLayoutMetrics.setsThePieces→scaleIn), since its fitted size is not known before its lines are found.Verification
./mvnw -B -ntp install -pl :graph-compose-render-docx→ BUILD SUCCESS, 1228 tests, 0 failures, 1 skipped.New
DocxAutoSizeTest(7):DocxSessionMarkdownTest:DocxZoneLineTest:**Acme**part the page sets as written still written bold, its marks dropped.DocxZonePartsTest: the parts read otherwise named one by one.DocxZoneReportTest,DocxParagraphReportTest: notes only where the size is not told, and none for a paragraph fitted to its own style's size.DocxMarkdownTest:scaleIn's share, andlaidOutInagainst pieces read at the fitted size.Word 16 and LibreOffice, on a page of auto-sized paragraphs (a shrunk headline, a grown word, a markdown line, a pair's side, a badge, the body lines after each):
After, every word stands within 0.44pt of the page's baseline, at the page's size, in Word, and in LibreOffice but for the badge.
30 sabotages, each reverting a single decision in the change; 29 are caught by a test. The other lets plain text take its lines' first size where they hold more than one, and is equivalent: plain text the page does not read as markdown is laid out in one size. The caught ones cover:
fittedSize;scaleInand the heading note's size.Core doc guards: 166/0. qa doc and DOCX guards: 50/0.
DOCX fidelity corpus: no paragraph in it is fitted to another size than its style's, and all 62 documents are byte-identical with
2.5-dev. Report notes: 954, unchanged.Known limits
autoSize, only "J" shows. An auto-sized badge fills its disc and meets this too. Word sets it whole.Lane: render-docx (DOCX semantic backend) — no public API change.