From a52f47919abd3043ab7b14b299d86343b83fa792 Mon Sep 17 00:00:00 2001 From: ntwigg Date: Sun, 22 Jun 2025 23:02:10 -0700 Subject: [PATCH 1/7] Bump SWT to 4.36 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 3418c8233dc4b7fe1657e28ac3d32d7e2b649a40 Mon Sep 17 00:00:00 2001 From: ntwigg Date: Sun, 22 Jun 2025 23:02:29 -0700 Subject: [PATCH 2/7] Workaround SWT's new kotlin-incompatible geometry class hierarchy --- .../java/com/diffplug/common/swt/Shells.kt | 10 +++---- .../java/com/diffplug/common/swt/SwtKt.java | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 durian-swt/src/main/java/com/diffplug/common/swt/SwtKt.java 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); + } +} From f16278889da25db37905c4d65b91aad8292ce928 Mon Sep 17 00:00:00 2001 From: ntwigg Date: Sun, 22 Jun 2025 23:03:30 -0700 Subject: [PATCH 3/7] Add the SVG rasterizer. --- durian-swt/build.gradle | 1 + 1 file changed, 1 insertion(+) 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 { From 3fcbe5118ffb387059d408a1f01db24ecaebb250 Mon Sep 17 00:00:00 2001 From: ntwigg Date: Sun, 22 Jun 2025 23:03:45 -0700 Subject: [PATCH 4/7] Recreate the issue. --- .../com/diffplug/common/swt/Issue_2228.kt | 32 +++++++++ .../resources/issue_2228/strikethrough.png | Bin 0 -> 433 bytes .../resources/issue_2228/strikethrough.svg | 67 ++++++++++++++++++ .../resources/issue_2228/strikethrough@2x.png | Bin 0 -> 725 bytes 4 files changed, 99 insertions(+) create mode 100644 durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.kt create mode 100644 durian-swt/src/test/resources/issue_2228/strikethrough.png create mode 100644 durian-swt/src/test/resources/issue_2228/strikethrough.svg create mode 100644 durian-swt/src/test/resources/issue_2228/strikethrough@2x.png diff --git a/durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.kt b/durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.kt new file mode 100644 index 00000000..39abacac --- /dev/null +++ b/durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.kt @@ -0,0 +1,32 @@ +package com.diffplug.common.swt + +import com.diffplug.common.swt.jface.ImageDescriptors +import org.eclipse.jface.resource.ImageDescriptor +import org.eclipse.swt.SWT +import org.eclipse.swt.widgets.Label +import org.junit.Test +import org.junit.experimental.categories.Category + +@Category(InteractiveTest::class) +class Issue_2228 { + @Test + fun recreate() { + InteractiveTest.testCoat("Show the difference between `.svg` and `@x2.png` rendering") { + Layouts.setGrid(it).numColumns(2) + Label(it, SWT.NONE).apply { + text = ".svg" + } + Label(it, SWT.NONE).apply { + val imgDesc = ImageDescriptor.createFromFile(Issue_2228::class.java, "/issue_2228/strikethrough.svg"); + image = imgDesc.createImage() + } + Label(it, SWT.NONE).apply { + text = ".png" + } + Label(it, SWT.NONE).apply { + val imgDesc = ImageDescriptor.createFromFile(Issue_2228::class.java, "/issue_2228/strikethrough.png"); + image = imgDesc.createImage() + } + } + } +} \ No newline at end of file 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 0000000000000000000000000000000000000000..2ace5e96621b4a0913401839ec982d407d3645f4 GIT binary patch literal 433 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`3dtTpz6=aiY77hwEes65fITG{ z>K*<_cJMQQ3{<$r{>Uxms7?e=1m}?)haAQu@{Kc?J3cp5@CuYK)^;;LAlOmc7{R|v zlBJHJP+WjJq1aGZDqh^nJGt1uUdm! zcs{T^`stw4Htm4dLd{QN`!aaglkybA*pkdOq^Gp(XZ|RYVeuz@0Wh>BcI!W!X5RV? P7*GtJu6{1-oD!M + + + + + 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 0000000000000000000000000000000000000000..d1166cd384712cbc63ef2c531ed31131f6a99dfa GIT binary patch literal 725 zcmV;`0xJE9P)004R> z004l5008;`004mK004C`008P>0026e000+ooVrmw00004XF*Lt006O$eEU(800001 zb5ch_0Itp)=>Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01m_e01m_fl`9S#0006k zNklh?;Uyf`?p#?T`rr(lH8GEMJr%=UEj|y2|FXE%8|a0jkV(^k6FPpY0a%V0 z{{T*>X+Ve5e&IRiO}Lkq0d-EhHpa#V(=xzy({mo<13iRqX&5l;w431?6ne~S7oYYq zpdjLTscv?leb5Sz;ZwwapTh$DPGZ0-=#(1<+V0%+aVPSH^&x6;9|L}9C!LB3ZU8$1 z-LM2R+2(=*k1-3nRL7t!^sHR2+NLNu|6gRowST#0zR7jvr8G~Y!f!*UKcjHIn5`F7 z!B>xaVLj!l;zg6wUj!fFS+)j@C>SkyoPrHH_hBdOb^3q8jcjv))q$9=<2-zKes4>X zjEn+M94)J64D>mv0j)7>0TW8a<4Fy$aev4&Y#UX|P0qczp40%Nlzas?dyMT@j Date: Sun, 22 Jun 2025 23:16:55 -0700 Subject: [PATCH 5/7] Convert the issue back to Java to be eclipse-friendly. --- .../com/diffplug/common/swt/Issue_2228.java | 55 +++++++++++++++++++ .../com/diffplug/common/swt/Issue_2228.kt | 32 ----------- 2 files changed, 55 insertions(+), 32 deletions(-) create mode 100644 durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.java delete mode 100644 durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.kt 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/java/com/diffplug/common/swt/Issue_2228.kt b/durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.kt deleted file mode 100644 index 39abacac..00000000 --- a/durian-swt/src/test/java/com/diffplug/common/swt/Issue_2228.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.diffplug.common.swt - -import com.diffplug.common.swt.jface.ImageDescriptors -import org.eclipse.jface.resource.ImageDescriptor -import org.eclipse.swt.SWT -import org.eclipse.swt.widgets.Label -import org.junit.Test -import org.junit.experimental.categories.Category - -@Category(InteractiveTest::class) -class Issue_2228 { - @Test - fun recreate() { - InteractiveTest.testCoat("Show the difference between `.svg` and `@x2.png` rendering") { - Layouts.setGrid(it).numColumns(2) - Label(it, SWT.NONE).apply { - text = ".svg" - } - Label(it, SWT.NONE).apply { - val imgDesc = ImageDescriptor.createFromFile(Issue_2228::class.java, "/issue_2228/strikethrough.svg"); - image = imgDesc.createImage() - } - Label(it, SWT.NONE).apply { - text = ".png" - } - Label(it, SWT.NONE).apply { - val imgDesc = ImageDescriptor.createFromFile(Issue_2228::class.java, "/issue_2228/strikethrough.png"); - image = imgDesc.createImage() - } - } - } -} \ No newline at end of file From 3f3a0fedfe267380903d98ad617b1c480fa29448 Mon Sep 17 00:00:00 2001 From: ntwigg Date: Wed, 16 Jul 2025 10:02:09 -0700 Subject: [PATCH 6/7] Add a main, can be run as `./gradlew runIssue2228`. --- durian-swt/build.gradle | 8 +++ .../com/diffplug/common/swt/Issue_2228.java | 63 ++++++++++++------- 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/durian-swt/build.gradle b/durian-swt/build.gradle index 3d71b141..f89dcd38 100644 --- a/durian-swt/build.gradle +++ b/durian-swt/build.gradle @@ -70,3 +70,11 @@ tasks.register('interactiveTest', Test) { } } } + +tasks.register('runIssue2228', JavaExec) { + classpath = sourceSets.test.runtimeClasspath + mainClass = 'com.diffplug.common.swt.Issue_2228' + if (isMac) { + jvmArgs = ['-XstartOnFirstThread'] + } +} \ No newline at end of file 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 index ac2f0e9e..01e5aefb 100644 --- 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 @@ -18,7 +18,9 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -28,28 +30,43 @@ public class Issue_2228 { 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()); - }); + "Show the difference between `.svg` and `@x2.png` rendering", Issue_2228::svg_and_png); + } + + private static void svg_and_png(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()); + + } + + public static void main(String[] args) { + Display display = Display.getDefault(); + Shell shell = new Shell(display, SWT.SHELL_TRIM); + svg_and_png(shell); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); } } From 230548ed72efbd34df5659e812085f6eb820f28f Mon Sep 17 00:00:00 2001 From: ntwigg Date: Wed, 16 Jul 2025 10:04:32 -0700 Subject: [PATCH 7/7] Drop the durian-specific layout stuff. --- .../test/java/com/diffplug/common/swt/Issue_2228.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 index 01e5aefb..bc69e6b7 100644 --- 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 @@ -15,6 +15,7 @@ */ package com.diffplug.common.swt; +import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; @@ -35,15 +36,14 @@ public void recreate() { private static void svg_and_png(Composite parent) { // two-column grid - Layouts.setGrid(parent).numColumns(2); + GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent); // “.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"); + ImageDescriptor svgDesc = ImageDescriptor.createFromFile(Issue_2228.class, "/issue_2228/strikethrough.svg"); svgImage.setImage(svgDesc.createImage()); // “.png” label + image @@ -51,10 +51,8 @@ private static void svg_and_png(Composite parent) { pngLabel.setText(".png"); Label pngImage = new Label(parent, SWT.NONE); - ImageDescriptor pngDesc = ImageDescriptor.createFromFile( - Issue_2228.class, "/issue_2228/strikethrough.png"); + ImageDescriptor pngDesc = ImageDescriptor.createFromFile(Issue_2228.class, "/issue_2228/strikethrough.png"); pngImage.setImage(pngDesc.createImage()); - } public static void main(String[] args) {