[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-2d-dev
Subject:    Re: Hairline strokes under fractional display metrics
From:       Kirill Grouchnikov <kirill.grouchnikov () gmail ! com>
Date:       2022-05-27 18:36:13
Message-ID: CAMRG33aaiR39+=sKyE65iupRHK0BJGawaY4JWQeNwoGkSX9aJQ () mail ! gmail ! com
[Download RAW message or body]

I also found
https://github.com/apache/netbeans/blob/master/platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/windows8/DPIUnscaledBorder.java
 through that OpenJDK thread that I was reading yesterday, which looks to be
taking a similar approach.

Probably in a world of 4x+ monitors, I would indeed want to go from 1-pixel
to 2+ pixel "hairlines" as otherwise they would be almost invisible.

As for the 0 meaning hairline, I was mostly thinking of
SkPaint::setStrokeWidth in Skia.
https://bugs.openjdk.java.net/browse/JDK-8090551 has been open for quite
some time now on JDK.

On Fri, May 27, 2022 at 2:00 PM Philip Race <philip.race@oracle.com> wrote:

> 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.grouchnikov@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
> > > 
> 
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic