Skip to content

Commit 1a59c87

Browse files
committed
Updated for net 9.0 and Paint.NET 5.1+
1 parent 6b06189 commit 1a59c87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+980
-716
lines changed

SvgFileType.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "resvg.net", "..\resvg.net\r
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PaintDotNet.IndirectUI.Fluent", "..\PaintDotNet.IndirectUI.Fluent\PaintDotNet.IndirectUI.Fluent\PaintDotNet.IndirectUI.Fluent.csproj", "{0A612B08-8FC5-4068-9437-FC38476EA808}"
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "resvg.net.SourceGenerator", "..\resvg.net\resvg.net.SourceGenerator\resvg.net.SourceGenerator.csproj", "{829DA38A-DC43-4A9F-AEB6-C2208390B6B0}"
15+
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1618
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
3335
{0A612B08-8FC5-4068-9437-FC38476EA808}.Debug|Any CPU.Build.0 = Debug|Any CPU
3436
{0A612B08-8FC5-4068-9437-FC38476EA808}.Release|Any CPU.ActiveCfg = Release|Any CPU
3537
{0A612B08-8FC5-4068-9437-FC38476EA808}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{829DA38A-DC43-4A9F-AEB6-C2208390B6B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{829DA38A-DC43-4A9F-AEB6-C2208390B6B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{829DA38A-DC43-4A9F-AEB6-C2208390B6B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{829DA38A-DC43-4A9F-AEB6-C2208390B6B0}.Release|Any CPU.Build.0 = Release|Any CPU
3642
EndGlobalSection
3743
GlobalSection(SolutionProperties) = preSolution
3844
HideSolutionNode = FALSE

SvgFileType/Ensure.cs

Lines changed: 0 additions & 75 deletions
This file was deleted.

SvgFileType/Export/PreviewMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Osman Tunçelli. All rights reserved.
1+
// Copyright 2025 Osman Tunçelli. All rights reserved.
22
// Use of this source code is governed by GNU General Public License (GPL-2.0) that can be found in the COPYING file.
33

44
namespace SvgFileTypePlugin.Export;

SvgFileType/Export/PropertyNames.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Osman Tunçelli. All rights reserved.
1+
// Copyright 2025 Osman Tunçelli. All rights reserved.
22
// Use of this source code is governed by GNU General Public License (GPL-2.0) that can be found in the COPYING file.
33

44
namespace SvgFileTypePlugin.Export;

SvgFileType/Export/ScanMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Osman Tunçelli. All rights reserved.
1+
// Copyright 2025 Osman Tunçelli. All rights reserved.
22
// Use of this source code is governed by GNU General Public License (GPL-2.0) that can be found in the COPYING file.
33

44
namespace SvgFileTypePlugin.Export;

SvgFileType/Export/SvgExport.cs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Copyright 2023 Osman Tunçelli. All rights reserved.
1+
// Copyright 2025 Osman Tunçelli. All rights reserved.
22
// Use of this source code is governed by GNU General Public License (GPL-2.0) that can be found in the COPYING file.
33

44
using System;
5+
using System.ComponentModel;
56
using System.IO;
67
using System.Text;
78
using System.Threading;
@@ -17,7 +18,7 @@ namespace SvgFileTypePlugin.Export;
1718

1819
internal static partial class SvgExport
1920
{
20-
private static Lazy<string> ShapesDirectory => new(() =>
21+
private static Lazy<string?> ShapesDirectory => new(() =>
2122
{
2223
try
2324
{
@@ -35,7 +36,7 @@ internal static partial class SvgExport
3536
}
3637
});
3738

38-
public static string ShowSaveShapeDialog()
39+
public static string? ShowSaveShapeDialog()
3940
{
4041
if (!UIHelper.IsSaveConfigDialogVisible())
4142
{
@@ -51,13 +52,25 @@ public static string ShowSaveShapeDialog()
5152
});
5253
}
5354

55+
private static T ThrowIfOverflow<T>(Func<T> action, string message)
56+
{
57+
try
58+
{
59+
return action();
60+
}
61+
catch (OverflowException ex)
62+
{
63+
throw new WarningException(message, ex);
64+
}
65+
}
66+
5467
public static void Export(Surface input, Stream output, PropertyCollection props, ProgressEventHandler progressCallback, string shapePath)
5568
{
56-
Ensure.IsNotNull(input, nameof(input));
57-
Ensure.IsNotNull(output, nameof(output));
58-
Ensure.IsNotNull(props, nameof(props));
59-
Ensure.IsNotNull(progressCallback, nameof(progressCallback));
60-
Ensure.Test(() => checked(input.Stride * input.Height), StringResources.CanvasIsTooBig);
69+
ArgumentNullException.ThrowIfNull(input);
70+
ArgumentNullException.ThrowIfNull(output);
71+
ArgumentNullException.ThrowIfNull(props);
72+
ArgumentNullException.ThrowIfNull(progressCallback);
73+
ThrowIfOverflow(() => checked(input.Stride * input.Height), StringResources.CanvasIsTooBig);
6174

6275
#pragma warning disable format // @formatter:off
6376
ScanMode scanMode = props.GetPropertyValue<ScanMode>(PropertyNames.ScanMode);
@@ -81,7 +94,7 @@ public static void Export(Surface input, Stream output, PropertyCollection props
8194
#pragma warning restore format // @formatter:on
8295

8396
PotraceBitmap bm;
84-
TraceResult trace;
97+
TraceResult? trace;
8598
ImageInfo imginfo;
8699
SvgBackEnd backend = new SvgBackEnd
87100
{
@@ -206,7 +219,7 @@ void OnProgress(float prog)
206219
}
207220
}
208221

209-
if (dialogVisible && scanMode == ScanMode.Transparent && shapePath != null)
222+
if (dialogVisible && scanMode == ScanMode.Transparent && shapePath.Length > 0)
210223
{
211224
PdnShapeBackEnd pdnbackend = new PdnShapeBackEnd
212225
{
@@ -221,7 +234,7 @@ void OnProgress(float prog)
221234
StringBuilder msg = new StringBuilder();
222235
msg.AppendFormat(StringResources.ShapeSaved, shapePath);
223236

224-
if (Path.GetDirectoryName(shapePath)?.StartsWith(ShapesDirectory.Value, StringComparison.OrdinalIgnoreCase) == true)
237+
if (ShapesDirectory.Value != null && Path.GetDirectoryName(shapePath)?.StartsWith(ShapesDirectory.Value, StringComparison.OrdinalIgnoreCase) == true)
225238
{
226239
msg.AppendLine();
227240
msg.AppendLine();
@@ -236,12 +249,12 @@ void OnProgress(float prog)
236249

237250
public static void Export(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback, string shapePath)
238251
{
239-
Ensure.IsNotNull(input, nameof(input));
240-
Ensure.IsNotNull(output, nameof(output));
241-
Ensure.IsNotNull(token, nameof(token));
242-
Ensure.IsNotNull(scratchSurface, nameof(scratchSurface));
243-
Ensure.IsNotNull(progressCallback, nameof(progressCallback));
244-
Ensure.Test(() => checked(scratchSurface.Stride * scratchSurface.Height), StringResources.CanvasIsTooBig);
252+
ArgumentNullException.ThrowIfNull(input);
253+
ArgumentNullException.ThrowIfNull(output);
254+
ArgumentNullException.ThrowIfNull(token);
255+
ArgumentNullException.ThrowIfNull(scratchSurface);
256+
ArgumentNullException.ThrowIfNull(progressCallback);
257+
ThrowIfOverflow(() => checked(scratchSurface.Stride * scratchSurface.Height), StringResources.CanvasIsTooBig);
245258

246259
input.Flatten(scratchSurface);
247260
Export(scratchSurface, output, token.Properties, progressCallback, shapePath);
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Osman Tunçelli. All rights reserved.
1+
// Copyright 2025 Osman Tunçelli. All rights reserved.
22
// Use of this source code is governed by GNU General Public License (GPL-2.0) that can be found in the COPYING file.
33

44
using System;
@@ -11,26 +11,28 @@ internal static class ControlExtensions
1111
{
1212
public static IEnumerable<Control> Descendants(this Control root)
1313
{
14+
ArgumentNullException.ThrowIfNull(root);
15+
1416
foreach (Control control in root.Controls)
1517
{
1618
yield return control;
1719
if (control.HasChildren)
18-
{
1920
foreach (Control child in Descendants(control))
20-
{
2121
yield return child;
22-
}
23-
}
2422
}
2523
}
2624

27-
public static object RunOnUIThread<T>(this Control control, T action, params object[] args) where T : Delegate
25+
public static object? RunOnUIThread<T>(this Control control, T action, params object[] args) where T : Delegate
2826
{
27+
ArgumentNullException.ThrowIfNull(control);
28+
2929
return control.InvokeRequired ? control.Invoke(action, args) : action.DynamicInvoke(args);
3030
}
3131

32-
public static object RunOnUIThread<T>(this Control control, T action) where T : Delegate
32+
public static object? RunOnUIThread<T>(this Control control, T action) where T : Delegate
3333
{
34+
ArgumentNullException.ThrowIfNull(control);
35+
3436
return control.InvokeRequired ? control.Invoke(action) : action.DynamicInvoke();
3537
}
3638
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
// Copyright 2023 Osman Tunçelli. All rights reserved.
1+
// Copyright 2025 Osman Tunçelli. All rights reserved.
22
// Use of this source code is governed by GNU General Public License (GPL-2.0) that can be found in the COPYING file.
33

4+
using System;
45
using PaintDotNet;
56

67
namespace SvgFileTypePlugin.Extensions;
78

89
internal static class DocumentExtensions
910
{
10-
public static void SetDpi(this Document doc, double dpi)
11+
public static void SetDpi(this Document doc, double x, double y)
1112
{
13+
ArgumentNullException.ThrowIfNull(doc);
14+
1215
doc.DpuUnit = MeasurementUnit.Inch;
13-
doc.DpuX = dpi;
14-
doc.DpuY = dpi;
16+
doc.DpuX = x;
17+
doc.DpuY = y;
18+
}
19+
20+
public static void SetDpi(this Document doc, double dpi)
21+
{
22+
SetDpi(doc, dpi, dpi);
1523
}
1624
}

0 commit comments

Comments
 (0)