diff options
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java | 17 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java | 10 |
2 files changed, 20 insertions, 7 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 6e0e4dfd9e..b3ae175771 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,10 +399,7 @@ public int getDepth () { */ public Point getDPI () { checkDevice (); - 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; + return getScreenDPI(); } /** @@ -475,6 +472,13 @@ public FontData[] getFontList (String faceName, boolean scalable) { return result; } +Point 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; +} + /** * Returns the matching standard color for the given * constant, which should be one of the color constants @@ -679,6 +683,11 @@ 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 055548d2ec..21e63f974e 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,6 +197,8 @@ 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; @@ -208,7 +210,7 @@ public FontData[] getFontData() { buffer = new byte [length + 1]; C.memmove (buffer, fontString, length); OS.g_free (fontString); - FontData data = new FontData(name, height, style); + FontData data = new FontData(name, size, style); data.string = buffer; return new FontData[]{data}; } @@ -252,6 +254,8 @@ 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); @@ -260,8 +264,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 (height > 0) { - OS.pango_font_description_set_size(handle, (int)(0.5f + height * OS.PANGO_SCALE)); + if (size > 0) { + OS.pango_font_description_set_size(handle, (int)(0.5f + size * OS.PANGO_SCALE)); } OS.pango_font_description_set_stretch(handle, OS.PANGO_STRETCH_NORMAL); int pangoStyle = OS.PANGO_STYLE_NORMAL; |