Indeed .. something very close to that is what is being proposed in a current PR here :
https://github.com/openjdk/jdk/pull/7449/files

Just bear in mind some of the same constraints and that if printed on a 1200dpi printer with a scale of 16.67 .. your one pixel line might be too thin to be seen at all.

I suggest you should have an upper limit on the unscaling.

I don't remember why the change a long time ago was backed out .. indeed I
am not sure I remember it will enough for it to be more than a figment of my imagination but "0" used to have a special meaning in some graphics systems - X11 took it to
mean "draw a line the fastest way you can, I do not care about accuracy".

-phil.

On 5/26/22 2:47 PM, Kirill Grouchnikov wrote:
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.grouchni...@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


Reply via email to