Skip to content

Commit 3fbfd38

Browse files
committed
Updated for Paint.NET 5.1 and later only. Started targeting net9.0
1 parent cb8eb98 commit 3fbfd38

40 files changed

+3580
-3705
lines changed

PDFiumSharp

PdfFileType/AiFileType.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@
55
using System.IO;
66
using PaintDotNet;
77

8-
namespace PdfFileTypePlugin
8+
namespace PdfFileTypePlugin;
9+
10+
[PluginSupportInfo(typeof(MyPluginSupportInfo))]
11+
public sealed class AiFileType : PdfFileType
912
{
10-
[PluginSupportInfo(typeof(MyPluginSupportInfo))]
11-
public sealed class AiFileType : PdfFileType
13+
private static readonly FileTypeOptions BaseOptions = new FileTypeOptions
1214
{
13-
private static readonly FileTypeOptions BaseOptions = new FileTypeOptions
14-
{
15-
LoadExtensions = new[] { ".ai" },
16-
SupportsCancellation = true,
17-
SupportsLayers = true,
18-
SaveExtensions = Array.Empty<string>()
19-
};
15+
LoadExtensions = [".ai"],
16+
SupportsCancellation = true,
17+
SupportsLayers = true,
18+
SaveExtensions = []
19+
};
2020

21-
public AiFileType() : base(GetName("AI - Adobe® Illustrator® Artwork"), BaseOptions)
22-
{
23-
}
21+
public AiFileType() : base(GetName("AI"), BaseOptions)
22+
{
23+
}
2424

25-
protected sealed override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
26-
{
27-
throw new NotSupportedException();
28-
}
25+
protected sealed override void OnSaveT(Document input, Stream output, PropertyBasedSaveConfigToken token, Surface scratchSurface, ProgressEventHandler progressCallback)
26+
{
27+
throw new NotSupportedException();
2928
}
3029
}

PdfFileType/DocumentProperties.cs

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,97 +3,97 @@
33

44
using System;
55
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.IO;
78
using PaintDotNet;
89
using PDFiumSharp;
910
using PDFiumSharp.Types;
1011

11-
namespace PdfFileTypePlugin
12+
namespace PdfFileTypePlugin;
13+
14+
internal sealed class DocumentProperties
1215
{
13-
internal sealed class DocumentProperties
14-
{
15-
public const string MarkName = "PDN3";
16-
public const string ParamName = "D";
16+
public const string MarkName = "PDN3";
17+
public const string ParamName = "D";
1718

18-
public float DpuX { get; }
19+
public float DpuX { get; }
1920

20-
public float DpuY { get; }
21+
public float DpuY { get; }
2122

22-
public MeasurementUnit Unit { get; }
23+
public MeasurementUnit Unit { get; }
2324

24-
public DocumentProperties(float dpux, float dpuy, MeasurementUnit unit)
25-
{
26-
const float min = (float)Document.MinimumDpu;
27-
const float max = (float)Document.MaximumDpu;
28-
DpuX = Util.Clamp(dpux, min, max);
29-
DpuY = Util.Clamp(dpuy, min, max);
30-
Unit = unit;
31-
}
25+
public DocumentProperties(float dpux, float dpuy, MeasurementUnit unit)
26+
{
27+
const float min = (float)Document.MinimumDpu;
28+
const float max = (float)Document.MaximumDpu;
29+
DpuX = Math.Clamp(dpux, min, max);
30+
DpuY = Math.Clamp(dpuy, min, max);
31+
Unit = unit;
32+
}
3233

33-
private byte[] ToBytes()
34+
private byte[] ToBytes()
35+
{
36+
using var ms = new MemoryStream();
37+
using (var bw = new BinaryWriter(ms))
3438
{
35-
using (var ms = new MemoryStream())
36-
using (var bw = new BinaryWriter(ms))
37-
{
38-
bw.Write(DpuX);
39-
bw.Write(DpuY);
40-
bw.Write((byte)Unit);
41-
bw.Flush();
42-
return ms.ToArray();
43-
}
39+
bw.Write(DpuX);
40+
bw.Write(DpuY);
41+
bw.Write((byte)Unit);
42+
bw.Flush();
4443
}
44+
return ms.ToArray();
45+
}
4546

46-
public static byte[] CreatePayload(Document document)
47+
public static byte[] CreatePayload(Document document)
48+
{
49+
float dpux = (float)Math.Round(document.DpuX, 3, MidpointRounding.AwayFromZero);
50+
float dpuy = (float)Math.Round(document.DpuY, 3, MidpointRounding.AwayFromZero);
51+
MeasurementUnit unit = document.DpuUnit;
52+
return new DocumentProperties(dpux, dpuy, unit).ToBytes();
53+
}
54+
55+
public void CopyTo(Document document)
56+
{
57+
try
4758
{
48-
float dpux = (float)Math.Round(document.DpuX, 3, MidpointRounding.AwayFromZero);
49-
float dpuy = (float)Math.Round(document.DpuY, 3, MidpointRounding.AwayFromZero);
50-
MeasurementUnit unit = document.DpuUnit;
51-
return new DocumentProperties(dpux, dpuy, unit).ToBytes();
59+
document.DpuX = DpuX;
60+
document.DpuY = DpuY;
61+
document.DpuUnit = Unit;
5262
}
53-
54-
public void CopyTo(Document document)
63+
catch
5564
{
56-
try
57-
{
58-
document.DpuX = DpuX;
59-
document.DpuY = DpuY;
60-
document.DpuUnit = Unit;
61-
}
62-
catch
63-
{
64-
document.DpuX = 96.0;
65-
document.DpuY = 96.0;
66-
document.DpuUnit = MeasurementUnit.Inch;
67-
}
65+
document.DpuX = 96.0;
66+
document.DpuY = 96.0;
67+
document.DpuUnit = MeasurementUnit.Inch;
6868
}
69+
}
6970

70-
public static bool TryLoadFromPageObjectMark(in FPDF_PAGEOBJECTMARK mark, byte[] buf, out DocumentProperties props)
71+
public static bool TryLoadFromPageObjectMark(in FPDF_PAGEOBJECTMARK mark, byte[] buf, [NotNullWhen(true)] out DocumentProperties? props)
72+
{
73+
try
7174
{
72-
try
75+
if (PDFium.FPDFPageObjMark_GetParamBlobValue(mark, ParamName, ref buf[0], (uint)buf.Length, out uint out_buflen))
7376
{
74-
if (PDFium.FPDFPageObjMark_GetParamBlobValue(mark, ParamName, ref buf[0], (uint)buf.Length, out uint out_buflen))
75-
{
76-
float dpux, dpuy;
77-
MeasurementUnit unit;
77+
float dpux, dpuy;
78+
MeasurementUnit unit;
7879

79-
using (var ms = new MemoryStream(buf, 0, (int)out_buflen))
80-
using (var br = new BinaryReader(ms))
81-
{
82-
dpux = br.ReadSingle();
83-
dpuy = br.ReadSingle();
84-
unit = (MeasurementUnit)br.ReadByte();
85-
}
86-
87-
props = new DocumentProperties(dpux, dpuy, unit);
88-
return true;
80+
using (var ms = new MemoryStream(buf, 0, (int)out_buflen))
81+
using (var br = new BinaryReader(ms))
82+
{
83+
dpux = br.ReadSingle();
84+
dpuy = br.ReadSingle();
85+
unit = (MeasurementUnit)br.ReadByte();
8986
}
87+
88+
props = new DocumentProperties(dpux, dpuy, unit);
89+
return true;
9090
}
91-
catch (Exception ex)
92-
{
93-
Debug.WriteLine($"Error while loading page object mark: {ex.Message}");
94-
}
95-
props = default;
96-
return false;
9791
}
92+
catch (Exception ex)
93+
{
94+
Debug.WriteLine($"Error while loading page object mark: {ex.Message}");
95+
}
96+
props = default;
97+
return false;
9898
}
9999
}

PdfFileType/Ensure.cs

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,70 +5,85 @@
55
using System.Collections;
66
using System.ComponentModel;
77

8-
namespace PdfFileTypePlugin
8+
namespace PdfFileTypePlugin;
9+
10+
internal static class Ensure
911
{
10-
internal static class Ensure
12+
public static T IsNotNull<T>(T param, string paramName) where T : class
1113
{
12-
public static T IsNotNull<T>(T param, string paramName) where T : class
13-
=> param ?? throw new ArgumentNullException(paramName);
14+
return param ?? throw new ArgumentNullException(paramName);
15+
}
1416

15-
public static IntPtr IsNotNull(IntPtr param, string paramName)
16-
=> param != IntPtr.Zero ? param : throw new ArgumentNullException(paramName);
17+
public static IntPtr IsNotNull(IntPtr param, string paramName)
18+
{
19+
return param != IntPtr.Zero ? param : throw new ArgumentNullException(paramName);
20+
}
1721

18-
public static T IsNotNullOrEmpty<T>(T param, string paramName) where T : class, ICollection
19-
{
20-
IsNotNull(param, paramName);
21-
return param.Count == 0 ? throw new ArgumentException("Collection is empty.", paramName) : param;
22-
}
22+
public static T IsNotNullOrEmpty<T>(T param, string paramName) where T : class, ICollection
23+
{
24+
IsNotNull(param, paramName);
25+
return param.Count == 0 ? throw new ArgumentException("Collection is empty.", paramName) : param;
26+
}
2327

24-
public static string IsNotNullOrEmpty(string param, string paramName)
25-
{
26-
IsNotNull(param, paramName);
27-
return param.Length == 0 ? throw new ArgumentException("String is empty.", paramName) : param;
28-
}
28+
public static string IsNotNullOrEmpty(string param, string paramName)
29+
{
30+
IsNotNull(param, paramName);
31+
return param.Length == 0 ? throw new ArgumentException("String is empty.", paramName) : param;
32+
}
2933

30-
public static string IsNotNullOrWhiteSpace(string param, string paramName)
31-
{
32-
IsNotNull(param, paramName);
33-
return param.Trim().Length == 0 ? throw new ArgumentException("String is empty.", paramName) : param;
34-
}
34+
public static string IsNotNullOrWhiteSpace(string param, string paramName)
35+
{
36+
IsNotNull(param, paramName);
37+
return param.Trim().Length == 0 ? throw new ArgumentException("String is empty.", paramName) : param;
38+
}
3539

36-
public static T IsInRange<T>(T param, T min, T max, string paramName) where T : IComparable<T>
37-
=> param.CompareTo(min) >= 0 && param.CompareTo(max) <= 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be between {min} and {max}.");
40+
public static T IsInRange<T>(T param, T min, T max, string paramName) where T : IComparable<T>
41+
{
42+
return param.CompareTo(min) >= 0 && param.CompareTo(max) <= 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be between {min} and {max}.");
43+
}
3844

39-
public static T IsGreaterThan<T>(T param, T comparand, string paramName) where T : IComparable<T>
40-
=> param.CompareTo(comparand) > 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be greater than {comparand}.");
45+
public static T IsGreaterThan<T>(T param, T comparand, string paramName) where T : IComparable<T>
46+
{
47+
return param.CompareTo(comparand) > 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be greater than {comparand}.");
48+
}
4149

42-
public static T IsGreaterThanOrEqualTo<T>(T param, T comparand, string paramName) where T : IComparable<T>
43-
=> param.CompareTo(comparand) >= 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be greater than or equal to {comparand}.");
50+
public static T IsGreaterThanOrEqualTo<T>(T param, T comparand, string paramName) where T : IComparable<T>
51+
{
52+
return param.CompareTo(comparand) >= 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be greater than or equal to {comparand}.");
53+
}
4454

45-
public static T IsLessThan<T>(T param, T comparand, string paramName) where T : IComparable<T>
46-
=> param.CompareTo(comparand) < 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be less than {comparand}.");
55+
public static T IsLessThan<T>(T param, T comparand, string paramName) where T : IComparable<T>
56+
{
57+
return param.CompareTo(comparand) < 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be less than {comparand}.");
58+
}
4759

48-
public static T IsLessThanOrEqualTo<T>(T param, T comparand, string paramName) where T : IComparable<T>
49-
=> param.CompareTo(comparand) <= 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be less than or equal to {comparand}.");
60+
public static T IsLessThanOrEqualTo<T>(T param, T comparand, string paramName) where T : IComparable<T>
61+
{
62+
return param.CompareTo(comparand) <= 0 ? param : throw new ArgumentOutOfRangeException(paramName, $"Value must be less than or equal to {comparand}.");
63+
}
5064

51-
public static T IsEqualTo<T>(T param, T comparand, string paramName)
52-
=> param.Equals(comparand) ? param : throw new ArgumentException($"Value must be equal to {comparand}.", paramName);
65+
public static T IsEqualTo<T>(T param, T comparand, string paramName) where T: notnull
66+
{
67+
return param.Equals(comparand) ? param : throw new ArgumentException($"Value must be equal to {comparand}.", paramName);
68+
}
5369

54-
public static void IsTrue(bool condition, Action throwException)
70+
public static void IsTrue(bool condition, Action throwException)
71+
{
72+
if (!condition)
5573
{
56-
if (!condition)
57-
{
58-
throwException();
59-
}
74+
throwException();
6075
}
76+
}
6177

62-
public static T Test<T>(Func<T> action, string message)
78+
public static T Test<T>(Func<T> action, string message)
79+
{
80+
try
81+
{
82+
return action();
83+
}
84+
catch (Exception ex)
6385
{
64-
try
65-
{
66-
return action();
67-
}
68-
catch (Exception ex)
69-
{
70-
throw new WarningException(message, ex);
71-
}
86+
throw new WarningException(message, ex);
7287
}
7388
}
7489
}

PdfFileType/Export/ExportMode.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
// Copyright 2022 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-
namespace PdfFileTypePlugin.Export
4+
namespace PdfFileTypePlugin.Export;
5+
6+
internal enum ExportMode
57
{
6-
internal enum ExportMode
7-
{
8-
Normal,
9-
Cropped,
10-
Cumulative,
11-
Flattened
12-
}
8+
Normal,
9+
Cropped,
10+
Cumulative,
11+
Flattened
1312
}

0 commit comments

Comments
 (0)