Hairline strokes under fractional display metrics
Kirill Grouchnikov
kirill.grouchnikov at gmail.com
Tue May 24 23:48:35 UTC 2022
I'm trying to figure out what is the right way to draw paths such
rectangles or rounded rectangles, such that horizontal and vertical parts
always fall on a full pixel and are displayed at hairline stroke width.
A long time ago there was an option to specify stroke width of 0 for that,
but then it was quickly reverted.
My understanding is that I need to query scale x and scale y of the
device's config's transform, and use that to compute the stroke width.
Here's my code -
https://github.com/kirill-grouchnikov/radiance/blob/sunshine/demos/theming-demo/src/main/java/org/pushingpixels/radiance/demo/theming/main/Hairlines.java
(no dependency on anything from Radiance, just the core Swing / AWT stuff).
Now, running this on a Windows 10 laptop with recommended / default 250%
scale factor gets the correct value of 2.5 as scale. But the visuals switch
between hairline and "smudged" as I horizontally resize the frame one pixel
at a time and the component shifts horizontally -
https://raw.githubusercontent.com/kirill-grouchnikov/radiance/sunshine/docs/images/hairlines.png
(and the horizontal lines are also not hairline)
How do I make this work in Java2D across all display scale factors so that
I get consistent hairlines? I see the same behavior on Java 9 and Java 17
Thanks
Kirill
More information about the client-libs-dev
mailing list