Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line dashes on Windows 200% display scale are half-size #206

Closed
Phillipus opened this issue Jun 5, 2023 · 8 comments
Closed

Line dashes on Windows 200% display scale are half-size #206

Phillipus opened this issue Jun 5, 2023 · 8 comments

Comments

@Phillipus
Copy link
Contributor

This affects Windows only, the problem is not seen on Mac or Linux.

I've not noticed this before now because I only recently purchased a hi-res monitor. I have it set to 200% display scaling.

In Archi, our app using GEF and Draw2d, we use connection lines that have dashes. Here's an example on Windows at 100% display scaling:

a100

And here it is at 200% scaling:

a200

Notice how the dots are closer together in the 200% version.

This does not happen on Linux and Mac at 200% scaling, on those platforms the line dashes look the same as in the first screenshot.

@Phillipus
Copy link
Contributor Author

Phillipus commented Jun 5, 2023

Here's a Draw2d snippet to reproduce the problem.

Requirements:

  • Windows
  • Hi-res monitor capable of displaying at 100% and 200% scaling to compare.
import org.eclipse.draw2d.FigureCanvas;
import org.eclipse.draw2d.Polyline;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class LineDashesDraw2d {

    public static void main(String[] args) {
        Display display = new Display();
        Shell shell = new Shell(display);
        shell.setLayout(new FillLayout());
        shell.setSize(300, 300);

        FigureCanvas fc = new FigureCanvas(shell);
        RectangleFigure root = new RectangleFigure();
        root.setBackgroundColor(new Color(null, 255, 255, 255));
        fc.getLightweightSystem().getRootFigure().add(root);
        
        RectangleFigure rectFigure = new RectangleFigure();
        rectFigure.setBounds(new Rectangle(10, 10, 250, 150));
        rectFigure.setLineWidth(1);
        rectFigure.setLineStyle(SWT.LINE_CUSTOM);
        rectFigure.setLineDash(new float[] { 4 });
        root.add(rectFigure);

        Polyline line = new Polyline();
        line.addPoint(new Point(10, 85));
        line.addPoint(new Point(260, 85));
        line.setLineStyle(SWT.LINE_CUSTOM);
        line.setLineDash(new float[] { 4 });
        root.add(line);

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

Windows 100% scaling:

100

Windows 200% scaling:

200

@Phillipus
Copy link
Contributor Author

The underlying issue comes from SWT:

eclipse-platform/eclipse.platform.swt#687

@azoitl
Copy link
Contributor

azoitl commented Jun 5, 2023

Have you tried with intermediate scaling factors (e.g., 125% or 150%) also? Is this related to the problem I reported here: #106 (comment) ?

@Phillipus
Copy link
Contributor Author

Have you tried with intermediate scaling factors (e.g., 125% or 150%) also? Is this related to the problem I reported here: #106 (comment) ?

Not yet. However, I did try running 4Diac IDE on Windows at 200% scaling to compare and the rendering of figures is broken (contents are displaced.)

@Phillipus
Copy link
Contributor Author

Phillipus commented Jun 5, 2023

This is fundamentally a Windows SWT issue, and I'm not sure whether it's a bug or a "feature".

For Archi, and my Draw2D fork, I've devised an ugly hack in SWTGraphics:

public void setLineDash(float[] value, boolean adjustForWindowsHiDPI) {
    if (value != null) {
        // validate dash values
        for (int i = 0; i < value.length; i++) {
            if (value[i] <= 0) {
                SWT.error(SWT.ERROR_INVALID_ARGUMENT);
            }
        }

        // HACK HERE
        if(adjustForWindowsHiDPI && "win32".equals(SWT.getPlatform()) &&
                org.eclipse.swt.internal.DPIUtil.getDeviceZoom() == 200) {
            for(int i = 0; i < value.length; i++) {
                value[i] *= 2;
            }
        }

        currentState.lineAttributes.dash = value.clone();
        currentState.lineAttributes.style = SWT.LINE_CUSTOM;
    } else {
        currentState.lineAttributes.dash = null;
        currentState.lineAttributes.style = SWT.LINE_SOLID;
    }
}
public void setLineAttributes(LineAttributes lineAttributes, boolean adjustForWindowsHiDPI) {
    copyLineAttributes(currentState.lineAttributes, lineAttributes);
    
    // HACK HERE
    if(adjustForWindowsHiDPI && currentState.lineAttributes.dash != null &&
            "win32".equals(SWT.getPlatform()) && org.eclipse.swt.internal.DPIUtil.getDeviceZoom() == 200) {
        for(int i = 0; i < currentState.lineAttributes.dash.length; i++) {
            currentState.lineAttributes.dash[i] *= 2;
        }
    }
}

@azoitl
Copy link
Contributor

azoitl commented Jun 5, 2023

Have you tried with intermediate scaling factors (e.g., 125% or 150%) also? Is this related to the problem I reported here: #106 (comment) ?

Not yet. However, I did try running 4Diac IDE on Windows at 200% scaling to compare and the rendering of figures is broken (contents are displaced.)

I know that. But AFAIK this only happens if you have two screens with different scaling settings. But I don't have a clue where it is coming from. Especially as only parts are off.

@azoitl
Copy link
Contributor

azoitl commented Aug 24, 2023

@Phillipus is this issue also improved throw your fix in PR #248?

No, this is still the same underlying issue in SWT.

@Phillipus
Copy link
Contributor Author

This is now fixed upstream in SWT:

eclipse-platform/eclipse.platform.swt@e83f6dd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants