Open mipastgt opened 3 years ago
The screen-class is quite unreliable in combination with JPro - because it doesn't reflect the Screen of the user.
It's possible to access the screen information through javascript.
WebAPI.executeScriptWithReturn("window.devicePixelRatio",(result) -> <doSomething>);
We should add this information to the the WebAPI, so they can be accessed for each user.
A small change, we should be able to provide a test version with this.
I guess you meant executeScriptWithListener
. I got that working but actually this should directly be tracked by JPro because it can change dynamically if the user moves the browser window around on his desktop and thereby going from one screen to another with different properties.
I would add the following methods to the WebAPI:
Double getDevicePixelRatio()
ReadonlyDoubleProperty devicePixelRatio()
This would match your use case, right?
By the way, it's possible to implement the auto-update functionality with the WebAPI. With registerJavaFunction you can register a function you can call from a listener in JavaScript, which will then be executed in the JVM.
Checkout this for some samples
Yes that is my use case.
I would make getDevicePixelRatio()
return a double
and not a Double
for consistency and performance reasons. Would it be possible to provide the DPI settings in the same way because when the pixel ratio changes, the DPI value almost always changes too unless the browser always returns a constant value of 96? If both values are returned, it might also make sense to combine them in a single object property, so that you have to register only one listener and only get notified once and not twice.
For what do you use this Information? JavaFX seems to scale Canvas automatically based on the devicePIxelRatio, and JPro does the same. It seems hard to find a use case for it - because most cases are solved by the underlying rendering.
One possible use case is for example creating something like a map display. Depending on the screen resolution you have to pick different map tiles. In my case either 256x256 or 512x512 pixel variants. There are further issues when you want to draw very thin but still sharp lines, etc.
That makes sense.
The version 2021.1.0-PREVIEW2
is stable and contains the new WebAPI methods!
I can confirm that this works now with 2021.1.0-PREVIEW3
but would it be possible to add corresponding methods for the DPI value too?
Forgot to mention it, dpi is rather tricky. The PixelDeviceRatio was tricky, and actually "the internet" was pretty wrong on how to add listeners to the value. For DPI, Safari doesn't seem to support it, and the rest doesn't provide an API to get the value - only media-queries. https://developer.mozilla.org/en-US/docs/Web/CSS/@media/resolution So I guess a solution would be too tricky and therefore wrong and unreliable (for now). Most places recommend multiplying the devicePixelRatio by 96, as a practical approximation.
Ok, I understand and I can (have to) probably live with that :-)
My application only works as intended when I have the correct DPI and screen scale of the current display but JPro does not seem to provide these correctly.
Some code like this
prints
when run with JPro although the correct output should be
I am running locally on a Mac with the following config:
The Mac is attached to a high-resolution Screen and is scaled by a factor 2 like a normal retina display. The browser was the latest Chrome browser.