Repository navigation
stroke: draw thin strokes at their width, not as hairlines - #80
Merged
Merged
Conversation
Strokes thinner than one device pixel are drawn one pixel wide, as PDFium does. At full coverage, many thin lines close together merge into a solid blot: a QR code of 1 pt strokes or a pointing hand outlined at 0.6 pt becomes a black square in a thumbnail, where MuPDF and Ghostscript draw them grey. By default a hairline of non-zero width is now drawn at a coverage scaled by its device width (along the widest direction of the transform), through the mechanism dense dash patterns already use: the scale blitter, no analytic fast path, drawn on its own in a union. Width 0 stays at full coverage. StrokeStyle.FullHairlines keeps the PDFium convention; the harness sets it, so its comparison with PDFium is unchanged.
Scaling a one-pixel hairline by its width counts thin lines closer than a pixel only once: a QR code of 0.31 px strokes came out an even light grey instead of its pattern. By default only strokes of width 0 are hairlines now; a thin stroke of non-zero width is drawn at its width, with the exact area it covers, so that dense thin lines sum to the ink they have (and may join unions like other strokes). StrokeStyle.FullHairlines keeps the PDFium convention for every stroke thinner than a pixel; IsHairline follows it.
This was referenced Nov 16, 2026
timzifer
added a commit
that referenced
this pull request
Nov 16, 2026
v0.20.0 draws thin strokes at their width (#80); a module that requires stilus/gpu alone then gets it.
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.
For timzifer/cera#243.
Strokes thinner than one device pixel were drawn one pixel wide at full coverage, as PDFium does. Many thin lines close together then merge into a solid blot: a QR code of 1 pt strokes or a pointing hand outlined at 0.6 pt becomes a black square in a thumbnail, where MuPDF and Ghostscript draw them grey.
StrokeStyle.FullHairlineskeeps the PDFium convention for every stroke thinner than a pixel;IsHairlinefollows it (so callers that keep hairlines out of unions stay consistent).FullHairlines, so its comparison with PDFium and the reference is unchanged.The first commit scaled the coverage of a one-pixel hairline by its width instead; that counts lines closer than a pixel only once (the QR code came out an even light grey), so the second replaces it. Squash on merge.
Tests:
thin_test.go(coverage via Stroke, FillShape, FillUnion, ClipStroke;FullHairlines; width 0; scaled transforms; dense thin hatch at half coverage), a union case of thin mirrored strokes, a thin style inFuzzStroke(60 s clean). Existing tests asserting the PDFium convention now setFullHairlines.Found by the fuzzer on the way, pre-existing on main and not touched here: a hairline (width 0) under a singular matrix with huge coordinates panics in the sweep on the analytic path (caught by
Canvas.guard, reported asErrInternal). Filed separately.