-
Notifications
You must be signed in to change notification settings - Fork 177
Deprecating Display#getDPI #2260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/imageanalyzer/ImageAnalyzer.java
Outdated
Show resolved
Hide resolved
6495a16
to
a8605ae
Compare
a8605ae
to
f9aee36
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general the change looks harmless, but I'm missing some context here. Could you please add some @deprecated
comment to the JavaDoc of Display::getDPI
and explain why it is wrong to use it? Replacing the value with 100
seems a bit esoteric.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current change does actually not fit to what it is supposed to be (as mentioned in the PR title): it should be about deprecating Device.getDPI()
, not Display.getDPI()
, and about overwriting that deprecation for Printer.getDPI()
as for the Printer
class the method is still useful while for Display
it is not. It would also need to be applied to the implementations on every OS.
f9aee36
to
523a47f
Compare
523a47f
to
b4cc5e3
Compare
@HeikoKlare PR title is updated now. It indeed deprecate the Display#getDPI and we keep the Printer#getDPI as is. @fedejeanne I have added javadoc stating why is it being deprecated. also I adapted the value from 100 to 96 as Default Dots Per Inch (DPI) similar to here: https://github.com/eclipse-gef/gef-classic/pull/750/files |
But that's not what we want to do: it does not really make sense to deprecate an overwritten method, as consumers may just operate on the abstraction (i.e., |
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
Outdated
Show resolved
Hide resolved
87df443
to
5129cc6
Compare
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
Show resolved
Hide resolved
Having the scale factor being based on the screen DPI leads to unexpected result e.g. Image too big/small. Having a screen dpi independent factor leads to consistent results
5129cc6
to
cf94ac5
Compare
@HeikoKlare @fedejeanne @ShahzaibIbrahim Hi all, since you are now planning to deprecate In NatTable I added code to render the table according to the DPI. I used As I didn't find information about how to migrate anywhere, I digged into the code and searched for information in tickets. I changed the usage of
If I start the SWT application with
If I set
In Is there an additional change in the upcoming SWT implementation that takes care of this? Of course I can manually check the value of the system property Is this the intention when deprecating BTW, I checked the Plug-in Migration Guide in the Eclipse Help and do not find any information about this topic. And actually I think the help generation is broken somehow, because the Incompatibility section of almost all entries is the same, which doesn't seem correct to me. |
Hi @fipro78, thanks for reaching out. Generally, it should not be necessary to do any scaling at all on client side. This is of course only the case if some assumptions that SWT has are the same as yours. I'll try to explain, what I understand from your comment
Yes and no. Before talking about a solution I would like to understand what you would like to achieve. Let's say, i am on a 150% monitor - do you always want to draw on a 1,5 scale independent of the value of swt.autoScale? So do you always want to link your scaling to the monitor zoom? |
Correct.
I want to scale the NatTable according to the rest of the SWT application. Fonts, grid lines, images etc. In the past I had to inspect the DPI setting and do the calculation manually, because on the As NatTable also supports zooming in and out of the table, I need to set the initial value according to the setting of the application, so it looks like the rest of the application on startup. |
Sounds like a yes to me. In SWT the semantics of zoom got a bit messy over the years, but its hard to clean up or streamline it fully now, because a lot of workarounds (like yours) were build because of this. For example swt.autoScale=200 means images will be scaled by 200 (independent of monitor zoom), but fonts are still relying on the monitor zoom and the value of Display#getDPI is hardly unusable in this scenario.
I assume you are fully drawing on a GC, am I correct? This sounds like a similar scenario GEF is facing and I assume your current solution is mostly similar to the solutions in GEF. I think the solution for you is to incorporate the monitor zoom into your custom table zoom. Two questions:
|
Yes
I hope not. Even the embedded controls like dropdowns are affected by the custom table zoom.
Yes, see and |
Follow-up question: How/where is the custom zoom applied to the GC, e.g. respective to coordinates/sizes etc. Are your using GC#setTransform similar to SWTGrapics or scaling it up yourself similar to ScaledGraphics before calling the GC API? |
I am scaling myself before calling the GC API. |
Okay, so, as I assumed, the situation looks quite similar to GEF. We are currently spending quite some time to evaluate what is the best solution for this scenario and started to implement some hidden features for that in SWT. Short disclaimer first: what I will describe is under development, not API, will probably change until it is done and is currently windows only and could break GTK and MacOS. Compatibility with GTK and MacOS are probably quite easy to achieve, but we are focusing on having a proper solution for windows first. One big problem with drawing (or partially drawing complex elements) on a GC is when you use an autoScale mode like quarter and draw on uneven monitor zooms like 125% or 175% -> This will most certainly result in rendering artifacts because the conversions from points to pixels and vice versa leads to rounding issues.
If you have follow-up questions, I would propose to either open a discussion here in the repo and continue there or we switch over to a discussion/issue in the NatTable repo. |
@akoch-yatta I opened a discussion in the NatTable forum: eclipse-nattable/nattable#164 Would be great if you could share any updates there or point to other discussions with informations, so I can update NatTable and probably also some Nebula widgets accordingly (e.g. the RichTextPainter is basically the same). |
Having the scale factor being based on the screen DPI leads to unexpected result e.g. Image too big/small. Having a screen dpi independent factor leads to consistent results.
When calling getDPI method as Device even with Printer instance, it will show you deprecation warning but should be fine when using the Printer object while calling getDPI. Here's the example:
