Repository navigation
Snap solid filled rectangles to whole pixels - #637
Merged
Merged
Conversation
A solid fill of a single rectangle that stays axis-aligned in device space now covers every pixel it touches, at least one pixel wide and tall, without anti-aliasing. Thin barcode bars drawn with `re f` stay solid instead of turning grey and narrow, matching PDFium. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rounding a rectangle out to every pixel it touches can make a 1.13 px bar 3 px wide and close the gap next to it, so narrow barcodes filled in as solid blocks. When the outer pixel span is a full pixel wider than the rectangle's rounded-up size, drop the pixel on the side with more slack, as PDFium does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rounding a rectangle out can only grow it, so bars separated by gaps of about one pixel still merged into solid blocks at low zoom. Move each edge to the nearest pixel boundary instead, keeping at least one pixel per axis: bars stay solid and the gaps between them stay open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
re frectangles rendered thin and grey: each bar was filled at its exact fractional position with anti-aliasing.CanvasPath::axis_aligned_rect, which detects a single four-corner subpath that stays axis-aligned under a given pixel mapping. It is backend-agnostic so the web and FemtoVG backends can reuse it.Rect::snapped_to_pixels, which moves each edge to the nearest pixel boundary and keeps at least one pixel per axis.fill_pathuses both for solid fills (no shader): the rectangle is snapped in the canvas's current pixel grid (so tiling-pattern tiles snap in their own backing pixels) and drawn without anti-aliasing. Pattern and shading fills are unchanged.Notes
B(fill and stroke), the fill part also snaps.Test plan
cargo clippy --workspace --all-targets -- -D warnings,cargo fmt --checkcargo conformance renderof the TCPDF barcode example at 1x and 2x: Code 39, Standard 2 of 5, and Code 128/EAN bars are solid and separatecargo test(not run locally: the test configuration needs a fresh Skia build that the sandbox blocked)🤖 Generated with Claude Code