Repository navigation
Justify every line through its glyph offsets; leave forced breaks alone - #187
Merged
Merged
Conversation
Knuth-Plass builds justification into its positions, but when it found
no solution within its tolerance and fell back to the greedy breaker,
the stretch existed only as Tw. Tw never applies to registered (Type0)
fonts, so those paragraphs were drawn ragged. After layout justifies a
line, any gap left before the column edge is now shared out over its
spaces, so a registered font is justified by its positioned TJ. Where
Knuth-Plass already filled the line the gap is nil and nothing moves.
On a line drawn with Tw, each styled group now starts at its own first
glyph. The running cursor left out the stretch Tw gives a group's
trailing space, so the next group started that much early and
overlapped it ("leaders" ran into "(finance"), a regression in 0.26.0.
A line that ends at a forced break is no longer justified, as CSS
text-align-last specifies: the line breakers mark it with hard_break.
The three new tests fail on main; the byte wall and all 15 template
corpus documents are byte-identical to main.
Addresses #186.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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.
Addresses #186. Thanks @jarvis-ai-ia for the reproduction; all three problems reproduced on main.
Tw.Twnever applies to Type0 fonts (ISO 32000-1 9.3.3), so the paragraph was drawn ragged. This was broken in every version: 0.26.0's positionedTJcovered only the lines Knuth-Plass justified. After layout justifies a line, any gap left before the column edge is now shared out over its spaces, so a registered font is justified by itsTJ. Where Knuth-Plass already filled the line, the gap is nil and nothing moves.Tw, each group started where the previous group's glyphs ended, which leaves out the stretchTwgives that group's trailing space: "leaders" ran into "(finance" by 7.1pt. Groups on such lines now start at their own first glyph, as registered-font groups already did.hard_break, and layout leaves them unjustified, as CSStext-align-lastspecifies.\nstretchedTests (all three fail on main)
test_justified_registered_font_reaches_the_edge_when_knuth_plass_falls_back: the reporter's paragraph in Liberation Sans (metric twin of Arimo), plain and as runs; every line but the last reaches the edge in layout, and is drawn where it is laid out.test_justified_styled_runs_do_not_overlap: the reporter's bold/italic paragraph in Helvetica; replaying the content stream, each group's drawn pen end (advances,Tc,Twon its spaces) meets the next group's start.test_justified_line_before_a_forced_break_is_not_stretched: Helvetica and Liberation, plain and runs; the line before\nhas no word spacing and the wrapped line after it is justified.What moves
For the next changelog: the 0.26.0 notes said justified registered-font text was fixed; that held only where Knuth-Plass found a solution.