Skip to content

Commit

Permalink
Workaround connection line dash spacing bug on Windows 200% scale
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillipus committed Jun 5, 2023
1 parent dcf42f1 commit 8c07252
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ public void setLineDash(int[] dash) {
public void setLineDash(float[] dash) {
currentState.lineAttributes.dash = dash;
setLineStyle(Graphics.LINE_CUSTOM);
swtGraphics.setLineDash(dash);
swtGraphics.setLineDash(dash, false);
}

/*
Expand Down
30 changes: 30 additions & 0 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/SWTGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,22 @@ public void setInterpolation(int interpolation) {

@Override
public void setLineAttributes(LineAttributes lineAttributes) {
setLineAttributes(lineAttributes, true);
}

@SuppressWarnings("restriction")
public void setLineAttributes(LineAttributes lineAttributes, boolean adjustForWindowsHiDPI) {
copyLineAttributes(currentState.lineAttributes, lineAttributes);

/*
* Hack to workaround bug on Windows 200% scaling where dashes are half size
* See https://github.com/eclipse-platform/eclipse.platform.swt/issues/687
*/
if(adjustForWindowsHiDPI && currentState.lineAttributes.dash != null && "win32".equals(SWT.getPlatform()) && org.eclipse.swt.internal.DPIUtil.getDeviceZoom() == 200) { //$NON-NLS-1$
for(int i = 0; i < currentState.lineAttributes.dash.length; i++) {
currentState.lineAttributes.dash[i] *= 2;
}
}
}

/**
Expand Down Expand Up @@ -1315,13 +1330,28 @@ public void setLineDash(int[] dashes) {
*/
@Override
public void setLineDash(float[] value) {
setLineDash(value, true);
}

@SuppressWarnings("restriction")
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 to workaround bug on Windows 200% scaling where dashes are half size
* See https://github.com/eclipse-platform/eclipse.platform.swt/issues/687
*/
if(adjustForWindowsHiDPI && "win32".equals(SWT.getPlatform()) && org.eclipse.swt.internal.DPIUtil.getDeviceZoom() == 200) { //$NON-NLS-1$
for(int i = 0; i < value.length; i++) {
value[i] *= 2;
}
}

currentState.lineAttributes.dash = value.clone();
currentState.lineAttributes.style = SWT.LINE_CUSTOM;
Expand Down

0 comments on commit 8c07252

Please sign in to comment.