Repository navigation
feat(layout): tab stops with leaders in paragraphs - #653
Merged
Merged
Conversation
A tab in a paragraph was always drawn as a space, so a table of contents or a figure column could not be built with Layout. Paragraph.TabStops now places the text after a tab at a left, right, centre or decimal stop, and fills the gap with a dot, dash or rule leader. A leader is a stroked path, not glyphs, so it stays out of extracted text and, in a tagged document, is an artifact outside the paragraph. The text before a tab ends in a space so words stay apart for readers. Stops beyond the content width and leaders at an unwritable size are refused before layout; a renderer laid out narrower than a stop reports a diagnostic. Paragraphs without stops are drawn as before.
… rule A right, centre or decimal segment that did not fit after the text before its tab was set as ordinary text from the left edge, losing its stop. It now goes to the next line and is placed again at the same stop, with its leader running from the left edge. A tab landing on a stop with no leader no longer vanishes when another tab follows with no stop to its right: the line always records where the first tab put the pen, and every stopless tab is one space. A line whose tab text moved on drops the separator space, and only a tab placed at a stop takes the line off the paragraph alignment. A stop at the content width is accepted when two ways of computing the width differ by a rounding step. The leader-size refusal also runs when a ParagraphRenderer builds its wrap, so a renderer of the caller's cannot write a negative or all-zero dash array.
# Conflicts: # src/VellumPdf.Layout/PublicAPI.Unshipped.txt # src/VellumPdf.Layout/Rendering/ParagraphRenderer.cs
…he placement rule
…topless tabs A right stop at the width could drop its number to the next line when two ways of summing the same widths rounded one step apart. The fit test now uses the written-token scale. A segment that fits at its stop nowhere no longer ends the line; it is ordinary text from the pen. A stop the separator space carried the pen past is still found. A paragraph whose stops all lie beyond a custom renderer's width keeps the one-space rule for its tabs.
… fresh-line tolerance
# Conflicts: # src/VellumPdf.Layout/Rendering/ParagraphRenderer.cs
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.
Closes #298
What changed
Paragraph.TabStopstakes a list ofTabStopvalues. A tab character in the text then places thetext after it at the first stop to the right of the end of the text before it. Without stops (null
or empty) a tab is a space, as before.
New public API (Layout,
PublicAPI.Unshipped.txt):TabStop(double position, TabAlignment alignment = Left, TabLeader leader = None)withPosition,Alignment,Leaderand an init-onlyDecimalCharacter(default'.').TabAlignment(Left,Right,Center,Decimal) andTabLeader(None,Dots,Dashes,Rule).Paragraph.TabStops(IReadOnlyList<TabStop>?, init-only, copied by the setter).LayoutDiagnosticCode.TabStopBeyondWidth = 106, severityError.The rule
14.8.2.6.2 requires the white space that separates words to be present in tagged text; without it
a structure-order extractor reads
Inleiding12. It is written whether or not the document istagged, so output does not depend on
Tagged.DecimalCharacterat it (text with none ends at the stop).start left of the pen starts at the pen.
tab is that advance when text comes straight before it; a tab after another tab, or at the start
of a line, is drawn as a space of its own. A stop at position 0 is therefore never used (a tab
looks for a stop greater than the pen); it is accepted and documented as "Do not pass".
paragraph checks whether it fits at the same stop on a fresh line. If it does, the line ends
(the separator space is dropped when the line ends straight after it) and the text is placed
there, its leader running from the left edge. If it fits at its stop nowhere, the line does not
end: the text is ordinary text from the pen, so a centred
1at the right edge draws asInleiding 1. Text at a left stop needs room for its first word only, starts at the stop, wrapsword by word with continuation lines at the left edge, and when its first word does not fit at
the stop is ordinary text from the pen with no leader.
itself stayed short of is still the stop for the tab; when one does, the tab goes to that one.
A Left stop follows the same fresh-line check as the others when its first word does not fit
after the text before the tab.
justified; a line whose tabs use no stop follows the alignment like any other.
the second half of a split paragraph reuse it.
Leaders
A leader is a stroked path drawn after the paragraph's text object, not glyphs, so extractors do not
print it. Per leader:
/Artifact BMC(tagged documents only),q,r g b RGof the text theleader leads to, cap, dash, width,
m,l,S,Q,EMC. With sizes:1 J[0 0.5s] 0 d(zero-length dashes with round caps, ISO 32000-2 8.5.3.2)0 J[3w 2w] 0 d0 J[] 0 dLine width
w = 0.08s. The leader starts and ends 0.25s clear of the texts and is left out whenshorter than 0.5s. Dot positions are multiples of 0.5s from the content edge, so dots of consecutive
lines line up. The leader takes its size and colour from the first piece of the text after the tab
(from the run holding the tab when nothing follows). In a tagged document it is an artifact outside
the paragraph's
BDC ... EMC, so it stays out of the structure tree (ISO 14289-1 7.1).Refusals
TabStopposition NaN, infinite or negative; undefined alignment or leaderArgumentOutOfRangeExceptionfrom the constructorDecimalCharacterwhite space, control or surrogateArgumentExceptionfrom the setterTabStopswith a null stop, or positions that do not strictly increaseArgumentNullException/ArgumentExceptionfrom the setterInvalidOperationExceptionfrom the save, before any layout; the message prints both numbers withRwhen they format alike. The document stays saveable: widening the page lets the retry save once0InvalidOperationExceptionbefore any layout for the document's own paragraphs, and fromParagraphRenderer.Layoutfor a renderer of the caller's (so[0 -6] 0 dor0 wis never written)ParagraphRendererlaid out by a custom renderer at a width narrower than a stop, whose text holds a tab in a styled runTabStopBeyondWidth(from the piece that starts at line 0 only); strict mode refuses it. A tab then uses the next stop within the width, and is one space only when none remains, including when every stop lies beyond the width: such a paragraph still takes the tab path with an empty stop list, so the one-space rule holds. A paragraph with noTabStopstakes the unchanged plain path, so its bytes are as beforeA stop that lies past the width by less than 5e-6 points, the scale the file is written at, is the
right edge, and a segment overflows only when it ends 5e-6 points or more past the width:
PageSize.A4withEdgeInsets(42.52)and a stop atWidth - 42.52 - 42.52differ fromthe library's
Width - (42.52 + 42.52)by one rounding step. Such a stop is placed at the width.The stop and leader-size checks run in
DocumentRenderer.RunLayout, beforeHasStartedLayoutisset. The size threshold is
5e-6 / 0.08points, the smallest size at which the leader's line widthis written as non-zero by
PdfCanvas; it is checked on every run of the paragraph.Existing documents
New API only. A paragraph with no stops, or with an empty list, takes the unchanged wrap path, and
the tokenisation change only acts when stops exist. The existing golden and byte-pinning tests in
VellumPdf.Layout.Testspass unchanged, andWithoutStops_aTabIsASpacecompares aTitle\t12paragraph with and without an empty list against the
Title 12paragraph. No deliberate outputchange.
Tests
TabStopTests(93 cases). Positions are computed from font metrics and the constants above, notfrom the layout code.
VellumPdf.Layout.Tests, Release, whole project, merged with mainThe 2 failures per TFM are
RunsHeadingListItemGoldenTests.EmbeddedHeadings_pinTheBytesandEmbeddedLists_pinTheBytes. They fail the same way, with the same computed hashes, on origin/mainwithout this branch (the pins from #654 meet the font change from #656); a re-pin PR is in flight.
Every other test passes, including all
TabStopTests.Run with the external tools required (qpdf 12.4.2, veraPDF 1.30.4, poppler). Oracles in
TabStopTests:qpdf --check("No syntax or stream encoding errors found") on dots, dashes andrule, tagged and untagged;
pdftotext -layoutprintsInleidingand12apart and nothing butletters, digits and white space (dots, dashes and rule leaders), and
-rawon a tagged page keepsthe words apart. Each oracle test first asserts that the fixture holds two leaders and the
(Inleiding ) Tjshow string; veraPDF 1.30.42uwith an embedded fontand leaders.
Mutations
Each applied to a detached worktree, built, run against
TabStopTestsandRunBoundaryTests,then restored.
q/Qaround the leaderDraw)WrapCalls == 1with a footer)Not done
/Type /Layout(ISO 19005-2 6.7.3.1 asks for layout artifacts at Level A, asa "should"); the typed artifact needs a property list the canvas does not write yet.
2arun: whether its 2a profile checks wordseparation was not checked, so a green run would not show the separator. The value-level test
does.
Paragraphholds them.not changed here.
cached wrap and the segmentation is rebuilt with it.