Skip to content

SWTGraphic scaling inconsistent across platforms #945

@ptziegler

Description

@ptziegler

This was brought up here and here. When a plain SWTGraphic is used, scaling is done internally using an SWT Transform. This class seems to behave differently on different platforms.

For example the following snippet:

package test;

import org.eclipse.draw2d.SWTGraphics;
import org.eclipse.draw2d.ScaledGraphics;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Pattern;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Test {
	public static void main(String[] args) {
		// System.setProperty("swt.autoScale.updateOnRuntime", "true");
		Shell shell = new Shell();
		shell.setSize(400, 400);

		Display d = shell.getDisplay();

		Color white = new Color(255, 255, 255);
		Color gray = new Color(128, 128, 128);

		shell.addPaintListener(event -> {
			GC gc = event.gc;

			for (int y = 0 ; y < shell.getSize().y; y += 50) {
				gc.setBackground(y % 20 == 0 ? white : gray);
				gc.fillRectangle(0, y, shell.getSize().x, 50);
			}
			
			SWTGraphics g1 = new SWTGraphics(gc);
			g1.translate(50, 100);
			g1.scale(2.5f);
			g1.setBackgroundColor(white);
			g1.drawText("Hello World", 0, 0);
			g1.dispose();

			gc.setTransform(null);
			

			ScaledGraphics g2 = new ScaledGraphics(new SWTGraphics(gc));
			g2.translate(50, 100);
			g2.scale(2.5f);
			g2.setBackgroundColor(white);
			g2.drawText("Hello World", 0, 0);
			g2.dispose();
		});

		shell.open();
		
		while(!shell.isDisposed()) {
			while(!d.readAndDispatch()) {
				d.sleep();
			}
		}
	}
}
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions