Use stroked dashes for uniform dotted and dashed borders#2776
Open
Dino0204 wants to merge 3 commits into
Open
Conversation
Member
|
Thanks a lot! |
Member
|
@Dino0204 The idea is cool, the pull request is OK, but we’ll wait after 69.0 to merge because the release is already huge and late. Do you think there’s a way to adapt the function for dashes? If the result is short and readable, it may be interesting to handle them both. |
Author
Thank you for the suggestion. I will look into extending the function to cover dashes as well! |
Author
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.
Fix #2526.
For uniform dotted borders with no rounded corners, stroke one line per
side with a round line cap and a zero-length dash pattern instead of
emitting a filled Bézier circle per dot. Each dot becomes a round-cap of
the stroke, so we replace ~24 numbers per dot with one
moveto+lineto+ dash setup per side.Any other dotted case (mixed colors, different widths, rounded corners)
falls through to the existing slow path.
Results
Repro case from the issue (
<body style="border: 1px dotted black">):curve_tooperators in content streamEquivalent dashed repro (
<body style="border: 1px dashed black">):5-case visual sample (1px / 3px / 5px uniform dotted,
border-radius, 4different colors). BEFORE on the left, AFTER on the right. Cases 4 and
5 take the slow path unchanged.
Same layout for dashed:
Iteration
The first attempt (27896e4) stroked a single closed rectangle with one
dash period applied across the entire perimeter. That collapsed the
whole border into one
re+ dash, but because the perimeter is rarelyan integer multiple of
2 × width, dots near the corners landedslightly off — visible especially in the 5px case below:
The second commit (2e3ef79) strokes each side individually and picks
the dash period per side so dots land exactly on both corners, matching
the per-side spacing of the generic path. Corners snap to dots, and the
pixel diff against the generic path drops from 0.6% to 0.02%:
The third commit (
7544edfc) extends the same function to handledashed borders, per @liZe's suggestion. The dotted/dashed split is
contained to three small knobs (cap, inset, dash array); net delta vs
the dotted-only version is +12 effective lines.
Tests
pytest -k 'dotted or border': 404 passed, 2 xfailed (same as main)pytest -k 'dashed': passes, no new failurespytest: no new failuresruff check: clean