diff --git a/durian-swt/build.gradle b/durian-swt/build.gradle index eaba880e..3d71b141 100644 --- a/durian-swt/build.gradle +++ b/durian-swt/build.gradle @@ -17,6 +17,7 @@ p2deps { into 'testImplementation', { p2repo "https://download.eclipse.org/eclipse/updates/$SWT_VERSION/" install 'org.eclipse.swt' + install 'org.eclipse.swt.svg' } } dependencies { diff --git a/durian-swt/src/main/java/com/diffplug/common/swt/Shells.kt b/durian-swt/src/main/java/com/diffplug/common/swt/Shells.kt index 0a4f8695..3fe71915 100644 --- a/durian-swt/src/main/java/com/diffplug/common/swt/Shells.kt +++ b/durian-swt/src/main/java/com/diffplug/common/swt/Shells.kt @@ -38,7 +38,7 @@ class Shells private constructor(private val style: Int, private val coat: Coat) private var title: String? = null private var image: Image? = null private var alpha = SWT.DEFAULT - private val size = Point(SWT.DEFAULT, SWT.DEFAULT) + private val size = SwtKt.Point(SWT.DEFAULT, SWT.DEFAULT) private var positionIncludesTrim = true private var location: Map.Entry? = null private var dontOpen = false @@ -86,7 +86,7 @@ class Shells private constructor(private val style: Int, private val coat: Coat) * Calls [.setLocation] and [.setSize] in one line. */ fun setRectangle(rect: Rectangle): Shells { - return setLocation(Point(rect.x, rect.y)).setSize(Point(rect.width, rect.height)) + return setLocation(SwtKt.Point(rect.x, rect.y)).setSize(SwtKt.Point(rect.width, rect.height)) } /** @@ -290,12 +290,12 @@ class Shells private constructor(private val style: Int, private val coat: Coat) } } val topLeft = - location!!.key.topLeftRequiredFor(Rectangle(0, 0, computedSize.x, computedSize.y), location!!.value) - bounds = Rectangle(topLeft.x, topLeft.y, computedSize.x, computedSize.y) + location!!.key.topLeftRequiredFor(SwtKt.Rectangle(0, 0, computedSize.x, computedSize.y), location!!.value) + bounds = SwtKt.Rectangle(topLeft.x, topLeft.y, computedSize.x, computedSize.y) } else { val computedSize = shell.computeSize(size.x, size.y, true) val topLeft = - location!!.key.topLeftRequiredFor(Rectangle(0, 0, computedSize.x, computedSize.y), location!!.value) + location!!.key.topLeftRequiredFor(SwtKt.Rectangle(0, 0, computedSize.x, computedSize.y), location!!.value) bounds = shell.computeTrim(topLeft.x, topLeft.y, computedSize.x, computedSize.y) } } diff --git a/durian-swt/src/main/java/com/diffplug/common/swt/SwtKt.java b/durian-swt/src/main/java/com/diffplug/common/swt/SwtKt.java new file mode 100644 index 00000000..60f09ce4 --- /dev/null +++ b/durian-swt/src/main/java/com/diffplug/common/swt/SwtKt.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2025 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.common.swt; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; + +public class SwtKt { + public static Point Point(int x, int y) { + return new Point(x, y); + } + + public static Rectangle Rectangle(int x, int y, int width, int height) { + return new Rectangle(x, y, width, height); + } +} diff --git a/durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.java b/durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.java new file mode 100644 index 00000000..ac2f0e9e --- /dev/null +++ b/durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2025 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.common.swt; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(InteractiveTest.class) +public class Issue_2228 { + @Test + public void recreate() { + // testCoat probably takes a title and a lambda that receives the parent Composite + InteractiveTest.testCoat( + "Show the difference between `.svg` and `@x2.png` rendering", + (Composite parent) -> { + // two-column grid + Layouts.setGrid(parent).numColumns(2); + + // “.svg” label + image + Label svgLabel = new Label(parent, SWT.NONE); + svgLabel.setText(".svg"); + + Label svgImage = new Label(parent, SWT.NONE); + ImageDescriptor svgDesc = ImageDescriptor.createFromFile( + Issue_2228.class, "/issue_2228/strikethrough.svg"); + svgImage.setImage(svgDesc.createImage()); + + // “.png” label + image + Label pngLabel = new Label(parent, SWT.NONE); + pngLabel.setText(".png"); + + Label pngImage = new Label(parent, SWT.NONE); + ImageDescriptor pngDesc = ImageDescriptor.createFromFile( + Issue_2228.class, "/issue_2228/strikethrough.png"); + pngImage.setImage(pngDesc.createImage()); + }); + } +} diff --git a/durian-swt/src/test/resources/issue_2228/strikethrough.png b/durian-swt/src/test/resources/issue_2228/strikethrough.png new file mode 100644 index 00000000..2ace5e96 Binary files /dev/null and b/durian-swt/src/test/resources/issue_2228/strikethrough.png differ diff --git a/durian-swt/src/test/resources/issue_2228/strikethrough.svg b/durian-swt/src/test/resources/issue_2228/strikethrough.svg new file mode 100644 index 00000000..3258c665 --- /dev/null +++ b/durian-swt/src/test/resources/issue_2228/strikethrough.svg @@ -0,0 +1,67 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/durian-swt/src/test/resources/issue_2228/strikethrough@2x.png b/durian-swt/src/test/resources/issue_2228/strikethrough@2x.png new file mode 100644 index 00000000..d1166cd3 Binary files /dev/null and b/durian-swt/src/test/resources/issue_2228/strikethrough@2x.png differ diff --git a/gradle.properties b/gradle.properties index 7734a394..392c9ba8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ VER_DURIAN=1.2.0 VER_DURIAN_RX=5.0.1 VER_DURIAN_DEBUG=1.1.0 # SWT Dependencies from P2 -SWT_VERSION=4.21 +SWT_VERSION=4.36 SWT_VERSION_X86=4.7 # Testing