Repository navigation
M7: justify paragraphs whose font shows the space with another code - #1832
Merged
Merged
Conversation
Word spacing reaches only single-byte code 32 (ISO 32000-1 §9.3.3). Justify was therefore turned off for a composite source font, so the paragraph came out left-aligned. And the generated Type 3 fallback, whose codes are numbered from 1, had its 32nd character widened instead of its spaces. Where word spacing doesn't reach the space, each space of a stretched row is now followed by a TJ adjustment of the same amount, and word spacing stays 0. Fonts whose space is code 32 keep using Tw as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thank you @komo1iddin for justifying paragraphs in composite and Type 3 fonts by adjusting after each space! It's merged into main now. If you haven't already, please come and join us on Discord: https://discord.gg/artcraft |
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.
What this changes
A justified paragraph stretches its spaces with word spacing (
Tw). ButTwapplies only to the single-byte code 32 (ISO 32000-1 §9.3.3). Two kinds of font show a space with some other code:Twanyway. That widened that one character and left the spaces as they were, so the rows didn't reach the right edge.Now
rewrite_blockchecks whether word spacing reaches the font's space: does the space encode as a single-byte code 32?Twstretches the spaces as before. That covers simple fonts and the standard-14 substitute.TJadjustment of the same amount (-1000 · extra / size), andTwstays 0. The space glyph is still drawn, so the text reads back unchanged.Underlines keep the stretched width, as before.
How you verified it
cargo fmt --all --check: cleancargo clippy -p pdfcraft-edit --all-targets -- -D warnings: cleancargo test -p pdfcraft-edit: 134 passedcargo test -p pdfcraft-automation --test automation: 153 passedcargo test -p pdfcraft-engine: everything passed (lib: 233)CRAFT_FONTS_DIRset, the way CI's Linux job does. I also rancargo test -p pdfcraft-fonts(56 passed) andcargo test -p pdfcraft-ui-egui --test control --test fonts(47 and 10 passed).cargo test -p pdfcraft-ui-egui --test editing: 116 passed, 1 failed. The failing test,password_prompt_opens_and_security_tab_reports_the_details, also fails onmainat 7437bde; test(ui): extend native opening and continuation regression coverage #1764 addresses that area.Tests.
justified_text_in_a_composite_font_fills_each_row_with_adjustments_after_its_spaces. It uses a synthetic Identity-H font, so no font asset is needed. It justifies a three-row paragraph and checks:TJadjustments are present andTwstays 0.justified_text_in_the_type3_fallback_stretches_its_spaces. It justifies Japanese words separated by spaces, with more than 32 different characters, so one of them gets code 32. It checks the same row ends, and that noTwis set. Like the existing Type 3 tests, it skips itself when the build has no Japanese face. It runs in CI's job with craft-fonts.Both fail without this change: the rows stop short of the right edge.
Never-crash
unwrap,expectorpanic!outside tests, and nounsafe.split_inclusive(' '), and each piece goes through the same encoders and errors as a whole row.Provenance
TJadjustments). No other implementation was read.Parity and reach
text_editwithalign: "justify".docs/editing-existing-text.mddescribes how justified rows are stretched.Anything a reviewer should look at first
rewrite_styled_block, which still treats justify as left alignment. I left that for a separate PR, because open PRs (M7: keep the source operators of rows a text edit doesn't reach #1754 and its follow-up) are changing that row layout. The docs say so.Tjper word plus oneTJper space. Folding a row into a singleTJarray would be tidier; I'd rather do that together with the glyph-per-BTcleanup in the shaped path, as a separate change.🤖 Generated with Claude Code