Skip to content

Commit 033d733

Browse files
akoch-yattaHeikoKlare
authored andcommitted
[win32] Use consistent font zoom retrieval
This commit unifies the extraction of the target zoom of a font to be affected by the zoom context of the underlying Widget. Before there were different strategies like getting it from the Shell.
1 parent 62c2cb0 commit 033d733

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public Font getFont () {
152152
checkWidget();
153153
if (font == null) {
154154
long hFont = defaultFont ();
155-
return Font.win32_new (display, hFont, getZoom());
155+
return Font.win32_new (display, hFont, getNativeZoom());
156156
}
157157
return font;
158158
}
@@ -478,8 +478,7 @@ public void setFont (Font font) {
478478
if (font != null && font.isDisposed ()) {
479479
error (SWT.ERROR_INVALID_ARGUMENT);
480480
}
481-
Shell shell = parent.getShell();
482-
this.font = font == null ? null : Font.win32_new(font, shell.nativeZoom);
481+
this.font = font == null ? null : Font.win32_new(font, getNativeZoom());
483482
if (hasFocus ()) setIMEFont ();
484483
}
485484

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ LRESULT WM_PAINT (long wParam, long lParam) {
15251525
Control control = findBackgroundControl ();
15261526
if (control == null) control = this;
15271527
data.background = control.getBackgroundPixel ();
1528-
data.font = Font.win32_new(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0), nativeZoom);
1528+
data.font = Font.win32_new(display, OS.SendMessage (handle, OS.WM_GETFONT, 0, 0), getNativeZoom());
15291529
data.uiState = (int)OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0);
15301530
if ((style & SWT.NO_BACKGROUND) != 0) {
15311531
/* This code is intentionally commented because it may be slow to copy bits from the screen */

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ int defaultBackground () {
721721
}
722722

723723
long defaultFont() {
724-
return display.getSystemFont(getShell().nativeZoom).handle;
724+
return display.getSystemFont(getNativeZoom()).handle;
725725
}
726726

727727
int defaultForeground () {
@@ -1315,7 +1315,7 @@ public Font getFont () {
13151315
if (font != null) return font;
13161316
long hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
13171317
if (hFont == 0) hFont = defaultFont ();
1318-
return Font.win32_new (display, hFont, getShell().nativeZoom);
1318+
return Font.win32_new (display, hFont, getNativeZoom());
13191319
}
13201320

13211321
/**
@@ -3330,7 +3330,7 @@ public void setCursor (Cursor cursor) {
33303330
}
33313331

33323332
void setDefaultFont () {
3333-
long hFont = display.getSystemFont (getShell().nativeZoom).handle;
3333+
long hFont = display.getSystemFont (getNativeZoom()).handle;
33343334
OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);
33353335
}
33363336

@@ -3432,7 +3432,7 @@ public void setFont (Font font) {
34323432
Font newFont = font;
34333433
if (newFont != null) {
34343434
if (newFont.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
3435-
newFont = Font.win32_new(newFont, getShell().nativeZoom);
3435+
newFont = Font.win32_new(newFont, getNativeZoom());
34363436
}
34373437
long hFont = 0;
34383438
if (newFont != null) {
@@ -5869,7 +5869,7 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
58695869
if (!(widget instanceof Control control)) {
58705870
return;
58715871
}
5872-
resizeFont(control, control.getShell().nativeZoom);
5872+
resizeFont(control, control.getNativeZoom());
58735873

58745874
Image image = control.backgroundImage;
58755875
if (image != null) {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,7 @@ public void setFont (Font font){
870870
error (SWT.ERROR_INVALID_ARGUMENT);
871871
}
872872
Font oldFont = this.font;
873-
Shell shell = parent.getShell();
874-
Font newFont = (font == null ? font : Font.win32_new(font, shell.nativeZoom));
873+
Font newFont = (font == null ? font : Font.win32_new(font, getNativeZoom()));
875874
if (oldFont == newFont) return;
876875
this.font = newFont;
877876
if (oldFont != null && oldFont.equals (newFont)) return;
@@ -936,7 +935,7 @@ public void setFont (int index, Font font) {
936935
}
937936
Font oldFont = cellFont [index];
938937
if (oldFont == font) return;
939-
cellFont [index] = font == null ? font : Font.win32_new(font, nativeZoom);
938+
cellFont [index] = font == null ? font : Font.win32_new(font, getNativeZoom());
940939
if (oldFont != null && oldFont.equals (font)) return;
941940
if (font != null) parent.setCustomDraw (true);
942941
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
@@ -1282,10 +1281,9 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
12821281
}
12831282
Font[] cellFonts = tableItem.cellFont;
12841283
if (cellFonts != null) {
1285-
Shell shell = tableItem.parent.getShell();
12861284
for (int index = 0; index < cellFonts.length; index++) {
12871285
Font cellFont = cellFonts[index];
1288-
cellFonts[index] = cellFont == null ? null : Font.win32_new(cellFont, shell.nativeZoom);
1286+
cellFonts[index] = cellFont == null ? null : Font.win32_new(cellFont, tableItem.getNativeZoom());
12891287
}
12901288
}
12911289
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TreeItem.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,7 @@ public void setFont (Font font){
13881388
error (SWT.ERROR_INVALID_ARGUMENT);
13891389
}
13901390
Font oldFont = this.font;
1391-
Shell shell = parent.getShell();
1392-
Font newFont = (font == null ? font : Font.win32_new(font, shell.nativeZoom));
1391+
Font newFont = (font == null ? font : Font.win32_new(font, getNativeZoom()));
13931392
if (oldFont == newFont) return;
13941393
this.font = newFont;
13951394
if (oldFont != null && oldFont.equals (font)) return;
@@ -1445,8 +1444,7 @@ public void setFont (int index, Font font) {
14451444
}
14461445
Font oldFont = cellFont [index];
14471446
if (oldFont == font) return;
1448-
Shell shell = parent.getShell();
1449-
cellFont [index] = font == null ? font : Font.win32_new(font, shell.nativeZoom);
1447+
cellFont [index] = font == null ? font : Font.win32_new(font, getNativeZoom());
14501448
if (oldFont != null && oldFont.equals (font)) return;
14511449
if (font != null) parent.customDraw = true;
14521450
if ((parent.style & SWT.VIRTUAL) != 0) cached = true;
@@ -1828,10 +1826,9 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
18281826
}
18291827
Font[] cellFonts = treeItem.cellFont;
18301828
if (cellFonts != null) {
1831-
Shell shell = treeItem.parent.getShell();
18321829
for (int index = 0; index < cellFonts.length; index++) {
18331830
Font cellFont = cellFonts[index];
1834-
cellFonts[index] = cellFont == null ? null : Font.win32_new(cellFont, shell.nativeZoom);
1831+
cellFonts[index] = cellFont == null ? null : Font.win32_new(cellFont, treeItem.getNativeZoom());
18351832
}
18361833
}
18371834
for (TreeItem item : treeItem.getItems()) {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Widget.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,10 @@ GC createNewGC(long hDC, GCData data) {
26902690
return GC.win32_new(hDC, data);
26912691
}
26922692

2693+
int getNativeZoom() {
2694+
return nativeZoom;
2695+
}
2696+
26932697
int getZoom() {
26942698
return DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
26952699
}

0 commit comments

Comments
 (0)