Repository navigation
Tolerate PDFium glyph-mask rasterization in conformance comparison - #565
Merged
Merged
Conversation
PDFium draws text from cached glyph masks: it snaps each glyph's origin to a whole pixel vertically and a quarter pixel horizontally, and its masks cover more than the exact outline on small text. Safe-PDF fills exact outlines at exact positions, so glyph edges differed on nearly every text page and text-heavy pages crossed the mismatch tolerance. When a page exceeds the tolerance, accept same-hue differences inside Safe-PDF's glyph bounds whose darkness fits the other image's 3x3 neighbourhood range widened by 40%, then decide pass or fail again. Document the behavior in the conformance README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conformance readsDocuments that Safe-PDF reads differently from the base commit, compared with PDFium. A read pdf.js corpus1008 documents compared with Improvements
840 documents of the PDFium corpus read as on Details are in the job summaries of the workflow run. Rerun a case locally with |
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.
Problem
Almost every conformance page with text showed differences at glyph edges against PDFium (for example #479 and #480). PDFium (Skia) draws text from cached glyph masks:
Safe-PDF fills each glyph's exact outline at its exact position. The comparison only tolerated anti-aliasing and whole-pixel displacement, so these differences counted as mismatches and pushed text-heavy pages over the 0.2% tolerance.
Change
compare.rs: newComparison::tolerate_glyph_rasterization. Inside glyph boxes it accepts a differing pixel when both images show the same hue and each image's darkness lies within the other image's 3x3 darkness range, widened byGLYPH_COVERAGE_SLACK(40%). Accepted pixels are drawn yellow and the mismatch ratio is recalculated.worker.rs: when a page exceeds the tolerance, take Safe-PDF's glyph bounds (grown by 1 px) from the trace the worker already runs, apply the tolerance, then decide pass or fail. Passing pages do no extra work.README.md: new "Text rasterization" section and an updated diff legend.The tolerance applies only inside glyph bounds. Applying it to the whole page also cleared real color-shift and missing-ink failures.
Results (
cargo conformance repro, all cases)The pages that flipped in #485 and #490 had mostly text differences. Their other differences still count but now total less than 0.2% of the page. The #479 pages that still fail are real bugs, for example wrong glyphs on the
FRC_8.2.4pages.Testing
cargo fmt --checkandcargo clippy --all --workspaceare clean.cargo test -p pdf-conformance --profile regressionpasses (21 tests).cargo test --workspacedidn't run locally because its Skia build had to be downloaded, so CI covers it.🤖 Generated with Claude Code