Skip to content

[Win32] Drawing produces unsymmetric results without swt.autoScale=false for 4k monitor with zooming #1596

@tmssngr

Description

@tmssngr

Describe the bug
Code that draws a circle and and a line symmetric with 100% zoom causes asymmetric results with 175% zoom factor.

To Reproduce
Run following snippet

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class HiDpiDrawing {
	public static void main(String[] args) {
//		System.getProperties().putIfAbsent("swt.autoScale", "false");
		final Display display = new Display();

		final Shell shell = new Shell(display);
		shell.addListener(SWT.Paint, event -> {
			final GC gc = event.gc;
			gc.setAntialias(SWT.ON);
			gc.setLineWidth(3);
			final Path path = new Path(display);
			int radius = 3;
			path.moveTo(15, 0);
			path.lineTo(15, 15 - radius);
			path.moveTo(15, 15 + radius);
			path.lineTo(15, 100);
			gc.drawPath(path);
			path.dispose();
			gc.setBackground(gc.getForeground());
			drawOval(gc, radius + 2);
			gc.setBackground(new Color(255, 255, 255));
			drawOval(gc, radius);
		});

		shell.setSize(400, 300);
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}

		shell.dispose();
	}

	private static void drawOval(GC gc, int radius) {
		gc.fillOval(15 - radius, 15 - radius, 2 * radius + 1, 2 * radius + 1);
	}
}

on Windows with 100% zoom level and with 175% zoom level.

Expected behavior
The dot is always drawn symmetric to the line, no matter what zoom level (otherwise it would look ugly).

Screenshots
With 100% zoom level:
100
close-up:
100%-zoomed
With 175% zoom level:
175
close-up:
175%-zoomed

When removing the // from the comment line, the result looks fine for 175% zoom, too.

Environment:

  1. Select the platform(s) on which the behavior is seen:
    • All OS
    • Windows
    • Linux
    • macOS
  1. Additional OS info (e.g. OS version, Linux Desktop, etc)
    Tried on Windows 11 with 4k monitor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions