Hairline strokes under fractional display metrics
Kirill Grouchnikov
kirill.grouchnikov at gmail.com
Thu May 26 21:47:18 UTC 2022
Haven't heard anything here, but in the meanwhile I got great pointers from
Karl, the developer of JFormDesigner and FlatLaf over at
https://github.com/kirill-grouchnikov/radiance/issues/39#issuecomment-1137649208
and subsequent comments.
The core of the idea is to force scale factor of 1.0 on the graphics
context, compute new origin and bounding box similar to how it's done in
the internals of Java2D, and then strokes with width of 1.0f will be
treated as full pixels (if no VALUE_STROKE_PURE hint is set).
On Tue, May 24, 2022 at 7:48 PM Kirill Grouchnikov <
kirill.grouchnikov at gmail.com> wrote:
> 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