-
Notifications
You must be signed in to change notification settings - Fork 49
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
Comments
Here's a Draw2d snippet to reproduce the problem. Requirements:
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: Windows 200% scaling: |
The underlying issue comes from SWT: |
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.) |
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 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;
}
}
} |
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. |
@Phillipus is this issue also improved throw your fix in PR #248? No, this is still the same underlying issue in SWT. |
This is now fixed upstream in SWT: |
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:
And here it is at 200% scaling:
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.
The text was updated successfully, but these errors were encountered: