Skip to content

Commit 695bc20

Browse files
wahlbrinkHeikoKlare
authored andcommitted
[Win32] Return unrounded value in FontMetrics.getAverageCharacterWidth
The value for getAverageCharacterWidth was rounded, even though its method signature returns a double. The unrounded value provides a better estimation of the average character width for non-integer zoom factors. Fixes: #2461
1 parent f9cbbf7 commit 695bc20

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ public static float pixelToPoint(float size, int zoom) {
197197
return (size / scaleFactor);
198198
}
199199

200+
public static double pixelToPoint(double size, int zoom) {
201+
if (zoom == 100 || size == SWT.DEFAULT) return size;
202+
double scaleFactor = getScalingFactor (zoom, 100);
203+
return size / scaleFactor;
204+
}
205+
200206

201207
/**
202208
* Auto-scale image with ImageData

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public int getAscent() {
108108
* @since 3.107
109109
*/
110110
public double getAverageCharacterWidth() {
111-
return getAverageCharWidth();
111+
return DPIUtil.pixelToPoint((double) handle.tmAveCharWidth, getZoom());
112112
}
113113

114114
/**

0 commit comments

Comments
 (0)