Skip to content

Commit 4295083

Browse files
ShahzaibIbrahimakoch-yatta
authored andcommitted
[GTK] Replaceing usages of Display#getDPI from gtk
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.
1 parent 9740516 commit 4295083

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ public boolean equals(Object object) {
184184
*/
185185
public FontData[] getFontData() {
186186
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
187-
187+
final int DOTS_PER_INCH = 96;
188188
long family = OS.pango_font_description_get_family(handle);
189189
int length = C.strlen(family);
190190
byte[] buffer = new byte[length];
191191
C.memmove(buffer, family, length);
192192
String name = new String(Converter.mbcsToWcs(buffer));
193193
float height = (float)OS.pango_font_description_get_size(handle) / OS.PANGO_SCALE;
194-
Point dpi = device.dpi, screenDPI = device.getScreenDPI();
195-
float size = height * screenDPI.y / dpi.y;
194+
Point dpi = device.dpi;
195+
float size = height * DOTS_PER_INCH / dpi.y;
196196
int pangoStyle = OS.pango_font_description_get_style(handle);
197197
int pangoWeight = OS.pango_font_description_get_weight(handle);
198198
int style = SWT.NORMAL;
@@ -254,8 +254,9 @@ public int hashCode() {
254254
void init(String name, float height, int style, byte[] fontString) {
255255
if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
256256
if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
257-
Point dpi = device.dpi, screenDPI = device.getScreenDPI();
258-
float size = height * dpi.y / screenDPI.y;
257+
final int DOTS_PER_INCH = 96;
258+
Point dpi = device.dpi;
259+
float size = height * dpi.y / DOTS_PER_INCH;
259260
if (fontString != null) {
260261
handle = OS.pango_font_description_from_string (fontString);
261262
if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5053,7 +5053,8 @@ String debugInfoForIndex(long index) {
50535053
}
50545054

50555055
void dpiChanged(int newScaleFactor) {
5056-
DPIUtil.setDeviceZoom (DPIUtil.mapDPIToZoom(getDPI().x * newScaleFactor));
5056+
final int DOTS_PER_INCH = 96;
5057+
DPIUtil.setDeviceZoom (DPIUtil.mapDPIToZoom(DOTS_PER_INCH * newScaleFactor));
50575058
Shell[] shells = getShells();
50585059
for (int i = 0; i < shells.length; i++) {
50595060
shells[i].layout(true, true);

0 commit comments

Comments
 (0)