Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Williams2019-09-09 16:00:01 +0000
committerEric Williams2019-09-11 14:02:12 +0000
commitf1cec2dde6ea77ca066ebe3a405f7ced98098903 (patch)
tree4d4900b0ca2ddbb38ab639067a40b97c3465fe56
parent890b5826e457d87824a6c61a9fdda45bd407811a (diff)
downloadeclipse.platform.swt-f1cec2dde6ea77ca066ebe3a405f7ced98098903.tar.gz
eclipse.platform.swt-f1cec2dde6ea77ca066ebe3a405f7ced98098903.tar.xz
eclipse.platform.swt-f1cec2dde6ea77ca066ebe3a405f7ced98098903.zip
Bug 545953: Device#getDPI method can return incorrect values
Use gdk_screen_get_resolution() as width/height returned by GDK does not take EDID into account, and is therefore inaccurate. Furthermore, getScreenDPI() and getDPI() are the same so remove the duplicate method and simplify the code that was calling it. Tested on GTK3.24 on X11, no AllNonBrowser JUnit tests fail. Change-Id: I16b22d734b3b153af0f1161bb9df3996d58b7f19 Signed-off-by: Eric Williams <ericwill@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java28
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java10
2 files changed, 7 insertions, 31 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
index b96dc1a0ad..6e0e4dfd9e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
@@ -399,7 +399,10 @@ public int getDepth () {
*/
public Point getDPI () {
checkDevice ();
- return getScreenDPI();
+ long screen = GDK.gdk_screen_get_default();
+ int dpi = (int) GDK.gdk_screen_get_resolution(screen);
+ Point ptDPI = dpi == -1 ? new Point (96, 96) : new Point (dpi, dpi);
+ return ptDPI;
}
/**
@@ -472,24 +475,6 @@ public FontData[] getFontList (String faceName, boolean scalable) {
return result;
}
-Point getScreenDPI () {
- int dpi = 96; //default value
- if (GTK.GTK_VERSION >= OS.VERSION(3, 22, 0)) {
- long display = GDK.gdk_display_get_default();
- long pMonitor = GDK.gdk_display_get_primary_monitor(display);
- if (pMonitor == 0) {
- pMonitor = GDK.gdk_display_get_monitor(display, 0);
- }
- int widthMM = GDK.gdk_monitor_get_width_mm(pMonitor);
- if (widthMM == 0) return new Point (dpi, dpi);
- int scaleFactor = GDK.gdk_monitor_get_scale_factor(pMonitor);
- GdkRectangle monitorGeometry = new GdkRectangle ();
- GDK.gdk_monitor_get_geometry(pMonitor, monitorGeometry);
- dpi = Compatibility.round (254 * monitorGeometry.width * scaleFactor, widthMM * 10);
- }
- return new Point (dpi, dpi);
-}
-
/**
* Returns the matching standard color for the given
* constant, which should be one of the color constants
@@ -694,11 +679,6 @@ protected void init () {
defaultFont = defaultFontArray [0];
}
defaultFont = OS.pango_font_description_copy (defaultFont);
- Point dpi = getDPI(), screenDPI = getScreenDPI();
- if (dpi.y != screenDPI.y) {
- int size = OS.pango_font_description_get_size(defaultFont);
- OS.pango_font_description_set_size(defaultFont, size * dpi.y / screenDPI.y);
- }
systemFont = Font.gtk_new (this, defaultFont);
overrideThemeValues();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java
index 21e63f974e..055548d2ec 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java
@@ -197,8 +197,6 @@ public FontData[] getFontData() {
C.memmove(buffer, family, length);
String name = new String(Converter.mbcsToWcs(buffer));
float height = (float)OS.pango_font_description_get_size(handle) / OS.PANGO_SCALE;
- Point dpi = device.dpi, screenDPI = device.getScreenDPI();
- float size = height * screenDPI.y / dpi.y;
int pangoStyle = OS.pango_font_description_get_style(handle);
int pangoWeight = OS.pango_font_description_get_weight(handle);
int style = SWT.NORMAL;
@@ -210,7 +208,7 @@ public FontData[] getFontData() {
buffer = new byte [length + 1];
C.memmove (buffer, fontString, length);
OS.g_free (fontString);
- FontData data = new FontData(name, size, style);
+ FontData data = new FontData(name, height, style);
data.string = buffer;
return new FontData[]{data};
}
@@ -254,8 +252,6 @@ public int hashCode() {
void init(String name, float height, int style, byte[] fontString) {
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Point dpi = device.dpi, screenDPI = device.getScreenDPI();
- float size = height * dpi.y / screenDPI.y;
if (fontString != null) {
handle = OS.pango_font_description_from_string (fontString);
if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
@@ -264,8 +260,8 @@ void init(String name, float height, int style, byte[] fontString) {
if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
byte[] buffer = Converter.wcsToMbcs(name, true);
OS.pango_font_description_set_family(handle, buffer);
- if (size > 0) {
- OS.pango_font_description_set_size(handle, (int)(0.5f + size * OS.PANGO_SCALE));
+ if (height > 0) {
+ OS.pango_font_description_set_size(handle, (int)(0.5f + height * OS.PANGO_SCALE));
}
OS.pango_font_description_set_stretch(handle, OS.PANGO_STRETCH_NORMAL);
int pangoStyle = OS.PANGO_STYLE_NORMAL;

Back to the top