-
Notifications
You must be signed in to change notification settings - Fork 191
Open
Description
Describe the bug
Unlike other fonts like e.g. Arial, the FontMetrics returned for the Monospace font are scaled by the Transform.
To Reproduce
package test;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class Test {
protected static final Font DISPLAY_FONT = new Font(null, "Monospaced", 24, SWT.NORMAL); //$NON-NLS-1$
public static void main(String[] args) {
System.setProperty("swt.autoScale.updateOnRuntime", "true");
Shell shell = new Shell();
shell.addPaintListener(event -> {
GC gc = event.gc;
gc.setFont(DISPLAY_FONT);
Transform t = new Transform(gc.getDevice());
t.scale(3.0f, 3.0f);
gc.setTransform(t);
System.out.println(gc.getFontMetrics().getAverageCharacterWidth());
gc.setTransform(null);
System.out.println(gc.getFontMetrics().getAverageCharacterWidth());
gc.setFont(DISPLAY_FONT);
System.out.println(gc.getFontMetrics().getAverageCharacterWidth());
gc.setTransform(t);
System.out.println(gc.getFontMetrics().getAverageCharacterWidth());
gc.dispose();
});
shell.open();
Display d = shell.getDisplay();
while(!shell.isDisposed()) {
while(!d.readAndDispatch()) {
d.sleep();
}
}
}
}In GEF, I even had a situation where the correct values are returned after calling these no-op operations. Which only works due to calling getFontMetrics() while gc.getTransform() is null:
gc.setTransform(null);
gc.getFontMetrics();
gc.setTransform(transform);Output
-
Linux (with Monospaced)
15, 15, 15, 15 -
Windows (125% zoom, with Monospaced)
53, 53, 18, 18 -
Windows (125% zoom, with Arial)
18, 18, 18, 18
Expected behavior
The average char width should behave the same across all operating systems.
Environment:
- Select the platform(s) on which the behavior is seen:
-
- All OS
-
- Windows
-
- Linux
-
- macOS
Version since
Probably since forever. I can see the same inconsistency with the 2023-12.
Metadata
Metadata
Assignees
Labels
No labels