From 097f31d648791c79deabc3c7e61808f40a204cc0 Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Sun, 25 Feb 2024 06:37:13 -0600 Subject: [PATCH 1/9] Enable compatibility with old and new image sharp verions. (Only NET60 and above use the new ImageSharp.) Rebase and Cleanup commits. --- .../MigraDocCore.DocumentObjectModel.csproj | 2 +- .../MigraDocCore.Rendering.csproj | 2 +- PdfSharpCore.Test/CreateSimplePDF.cs | 5 ++ PdfSharpCore.Test/PdfSharpCore.Test.csproj | 3 +- PdfSharpCore/PdfSharpCore.csproj | 30 ++++++-- PdfSharpCore/Utils/ImageSharpImageSource.cs | 37 +--------- .../Utils/ImageSharpImageSource_NET6.cs | 68 +++++++++++++++++++ .../ImageSharpImageSource_NETSTANDARD.cs | 61 +++++++++++++++++ SampleApp/SampleApp.csproj | 3 +- 9 files changed, 167 insertions(+), 44 deletions(-) create mode 100644 PdfSharpCore/Utils/ImageSharpImageSource_NET6.cs create mode 100644 PdfSharpCore/Utils/ImageSharpImageSource_NETSTANDARD.cs diff --git a/MigraDocCore.DocumentObjectModel/MigraDocCore.DocumentObjectModel.csproj b/MigraDocCore.DocumentObjectModel/MigraDocCore.DocumentObjectModel.csproj index f3f17cc0..abad81ed 100644 --- a/MigraDocCore.DocumentObjectModel/MigraDocCore.DocumentObjectModel.csproj +++ b/MigraDocCore.DocumentObjectModel/MigraDocCore.DocumentObjectModel.csproj @@ -1,6 +1,6 @@  - netstandard2.0;netcoreapp3.1;net5.0;net6.0 + netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 false True Stefan Steiger and Contributors diff --git a/MigraDocCore.Rendering/MigraDocCore.Rendering.csproj b/MigraDocCore.Rendering/MigraDocCore.Rendering.csproj index 3666b526..a4de0292 100644 --- a/MigraDocCore.Rendering/MigraDocCore.Rendering.csproj +++ b/MigraDocCore.Rendering/MigraDocCore.Rendering.csproj @@ -1,6 +1,6 @@  - netstandard2.0;netcoreapp3.1;net5.0;net6.0 + netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 false True Stefan Steiger and Contributors diff --git a/PdfSharpCore.Test/CreateSimplePDF.cs b/PdfSharpCore.Test/CreateSimplePDF.cs index ce9a4d49..c4090c0b 100644 --- a/PdfSharpCore.Test/CreateSimplePDF.cs +++ b/PdfSharpCore.Test/CreateSimplePDF.cs @@ -88,7 +88,12 @@ public void CreateTestPdfWithImageViaImageSharp() var renderer = XGraphics.FromPdfPage(pageNewRenderer); // Load image for ImageSharp and apply a simple mutation: +#if NET6_0_OR_GREATER + var image = Image.Load(PathHelper.GetInstance().GetAssetPath("lenna.png")); + var format = image.Metadata.DecodedImageFormat; +#else var image = Image.Load(PathHelper.GetInstance().GetAssetPath("lenna.png"), out var format); +#endif image.Mutate(ctx => ctx.Grayscale()); // create XImage from that same ImageSharp image: diff --git a/PdfSharpCore.Test/PdfSharpCore.Test.csproj b/PdfSharpCore.Test/PdfSharpCore.Test.csproj index 844f5748..587f1d3e 100644 --- a/PdfSharpCore.Test/PdfSharpCore.Test.csproj +++ b/PdfSharpCore.Test/PdfSharpCore.Test.csproj @@ -1,7 +1,8 @@ - netcoreapp3.1;net5.0;net6.0 + netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + latest false false diff --git a/PdfSharpCore/PdfSharpCore.csproj b/PdfSharpCore/PdfSharpCore.csproj index 9f8cedfd..16e71269 100644 --- a/PdfSharpCore/PdfSharpCore.csproj +++ b/PdfSharpCore/PdfSharpCore.csproj @@ -1,7 +1,7 @@  - netstandard2.0;netcoreapp3.1;net5.0;net6.0 + netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 false True Stefan Steiger and Contributors @@ -17,6 +17,12 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi PdfSharp for .NET Core true true + + 1.6.0 + 1.6.0 + 1.6.0 + 1.6.0 + @@ -45,11 +51,23 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi - - - - - + + + + + + + + + + + + + + + + + diff --git a/PdfSharpCore/Utils/ImageSharpImageSource.cs b/PdfSharpCore/Utils/ImageSharpImageSource.cs index 383863f4..18700690 100644 --- a/PdfSharpCore/Utils/ImageSharpImageSource.cs +++ b/PdfSharpCore/Utils/ImageSharpImageSource.cs @@ -7,40 +7,14 @@ using SixLabors.ImageSharp.Formats.Bmp; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.Advanced; namespace PdfSharpCore.Utils { - public class ImageSharpImageSource : ImageSource where TPixel : unmanaged, IPixel + public partial class ImageSharpImageSource : ImageSource where TPixel : unmanaged, IPixel { - public static IImageSource FromImageSharpImage(Image image, IImageFormat imgFormat, int? quality = 75) - { - var _path = "*" + Guid.NewGuid().ToString("B"); - return new ImageSharpImageSourceImpl(_path, image, (int)quality, imgFormat is PngFormat); - } - - protected override IImageSource FromBinaryImpl(string name, Func imageSource, int? quality = 75) - { - var image = Image.Load(imageSource.Invoke(), out IImageFormat imgFormat); - return new ImageSharpImageSourceImpl(name, image, (int)quality, imgFormat is PngFormat); - } - - protected override IImageSource FromFileImpl(string path, int? quality = 75) - { - var image = Image.Load(path, out IImageFormat imgFormat); - return new ImageSharpImageSourceImpl(path, image, (int) quality, imgFormat is PngFormat); - } - - protected override IImageSource FromStreamImpl(string name, Func imageStream, int? quality = 75) - { - using (var stream = imageStream.Invoke()) - { - var image = Image.Load(stream, out IImageFormat imgFormat); - return new ImageSharpImageSourceImpl(name, image, (int)quality, imgFormat is PngFormat); - } - } - - private class ImageSharpImageSourceImpl : IImageSource where TPixel2 : unmanaged, IPixel + private partial class ImageSharpImageSourceImpl : IImageSource where TPixel2 : unmanaged, IPixel { private Image Image { get; } private readonly int _quality; @@ -58,11 +32,6 @@ public ImageSharpImageSourceImpl(string name, Image image, int quality, Transparent = isTransparent; } - public void SaveAsJpeg(MemoryStream ms) - { - Image.SaveAsJpeg(ms, new JpegEncoder() { Quality = this._quality }); - } - public void Dispose() { Image.Dispose(); diff --git a/PdfSharpCore/Utils/ImageSharpImageSource_NET6.cs b/PdfSharpCore/Utils/ImageSharpImageSource_NET6.cs new file mode 100644 index 00000000..0cb9ee0e --- /dev/null +++ b/PdfSharpCore/Utils/ImageSharpImageSource_NET6.cs @@ -0,0 +1,68 @@ +#if NET6_0_OR_GREATER + +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; +using MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes; +using System; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Formats.Bmp; +using SixLabors.ImageSharp.Formats.Jpeg; +using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.Advanced; + +namespace PdfSharpCore.Utils +{ + public partial class ImageSharpImageSource : ImageSource where TPixel : unmanaged, IPixel + { + + public static IImageSource FromImageSharpImage(Image image, IImageFormat imgFormat, int? quality = 75) + { + var _path = "*" + Guid.NewGuid().ToString("B"); + return new ImageSharpImageSourceImpl(_path, image, (int)quality, imgFormat is PngFormat); + } + + protected override IImageSource FromBinaryImpl(string name, Func imageSource, int? quality = 75) + { + var image = Image.Load(imageSource.Invoke()); + var imgFormat = image.Metadata.DecodedImageFormat; + + return new ImageSharpImageSourceImpl(name, image, (int)quality, imgFormat is PngFormat); + } + + protected override IImageSource FromFileImpl(string path, int? quality = 75) + { + var image = Image.Load(path); + var imgFormat = image.Metadata.DecodedImageFormat; + + return new ImageSharpImageSourceImpl(path, image, (int) quality, imgFormat is PngFormat); + } + + protected override IImageSource FromStreamImpl(string name, Func imageStream, int? quality = 75) + { + using (var stream = imageStream.Invoke()) { + var image = Image.Load(stream); + var imgFormat = image.Metadata.DecodedImageFormat; + + return new ImageSharpImageSourceImpl(name, image, (int)quality, imgFormat is PngFormat); + } + } + + private partial class ImageSharpImageSourceImpl + { + + public void SaveAsJpeg(MemoryStream ms) + { + Image.SaveAsJpeg(ms, new JpegEncoder() { + Quality = this._quality, + ColorType = JpegEncodingColor.YCbCrRatio420, + Interleaved = true, + }); + } + + } + + } +} + +#endif \ No newline at end of file diff --git a/PdfSharpCore/Utils/ImageSharpImageSource_NETSTANDARD.cs b/PdfSharpCore/Utils/ImageSharpImageSource_NETSTANDARD.cs new file mode 100644 index 00000000..fa5367d6 --- /dev/null +++ b/PdfSharpCore/Utils/ImageSharpImageSource_NETSTANDARD.cs @@ -0,0 +1,61 @@ +#if !NET6_0_OR_GREATER + +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; +using MigraDocCore.DocumentObjectModel.MigraDoc.DocumentObjectModel.Shapes; +using System; +using System.IO; +using SixLabors.ImageSharp.Formats; +using SixLabors.ImageSharp.Formats.Bmp; +using SixLabors.ImageSharp.Formats.Jpeg; +using SixLabors.ImageSharp.Formats.Png; +using SixLabors.ImageSharp.Advanced; + +namespace PdfSharpCore.Utils +{ + public partial class ImageSharpImageSource : ImageSource where TPixel : unmanaged, IPixel + { + + public static IImageSource FromImageSharpImage(Image image, IImageFormat imgFormat, int? quality = 75) + { + var _path = "*" + Guid.NewGuid().ToString("B"); + return new ImageSharpImageSourceImpl(_path, image, (int)quality, imgFormat is PngFormat); + } + + protected override IImageSource FromBinaryImpl(string name, Func imageSource, int? quality = 75) + { + var image = Image.Load(imageSource.Invoke(), out IImageFormat imgFormat); + return new ImageSharpImageSourceImpl(name, image, (int)quality, imgFormat is PngFormat); + } + + protected override IImageSource FromFileImpl(string path, int? quality = 75) + { + var image = Image.Load(path, out IImageFormat imgFormat); + return new ImageSharpImageSourceImpl(path, image, (int) quality, imgFormat is PngFormat); + } + + protected override IImageSource FromStreamImpl(string name, Func imageStream, int? quality = 75) + { + using (var stream = imageStream.Invoke()) + { + var image = Image.Load(stream, out IImageFormat imgFormat); + return new ImageSharpImageSourceImpl(name, image, (int)quality, imgFormat is PngFormat); + } + } + + private partial class ImageSharpImageSourceImpl + { + + public void SaveAsJpeg(MemoryStream ms) + { + Image.SaveAsJpeg(ms, new JpegEncoder() { + Quality = this._quality, + }); + } + + } + + } +} + +#endif diff --git a/SampleApp/SampleApp.csproj b/SampleApp/SampleApp.csproj index 464229b5..b5fdc568 100644 --- a/SampleApp/SampleApp.csproj +++ b/SampleApp/SampleApp.csproj @@ -2,7 +2,8 @@ Exe - netcoreapp3.1;net5.0;net6.0 + netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + latest false enable enable From 619e20ff70532b946ff0d85b82067f714fd96fca Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Sun, 10 Mar 2024 16:36:30 -0500 Subject: [PATCH 2/9] Commit. --- PdfSharpCore/PdfSharpCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PdfSharpCore/PdfSharpCore.csproj b/PdfSharpCore/PdfSharpCore.csproj index 16e71269..d374252c 100644 --- a/PdfSharpCore/PdfSharpCore.csproj +++ b/PdfSharpCore/PdfSharpCore.csproj @@ -57,7 +57,7 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi - + From 66083200ddfcbd7a23f62cfb1c8c4dc0e9b4f955 Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Wed, 13 Mar 2024 13:49:14 -0500 Subject: [PATCH 3/9] Package Upgrade. --- PdfSharpCore.Test/PdfSharpCore.Test.csproj | 16 ++++++++-------- PdfSharpCore/PdfSharpCore.csproj | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/PdfSharpCore.Test/PdfSharpCore.Test.csproj b/PdfSharpCore.Test/PdfSharpCore.Test.csproj index 587f1d3e..9ebc02e8 100644 --- a/PdfSharpCore.Test/PdfSharpCore.Test.csproj +++ b/PdfSharpCore.Test/PdfSharpCore.Test.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 @@ -8,19 +8,19 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/PdfSharpCore/PdfSharpCore.csproj b/PdfSharpCore/PdfSharpCore.csproj index d374252c..7d3c3440 100644 --- a/PdfSharpCore/PdfSharpCore.csproj +++ b/PdfSharpCore/PdfSharpCore.csproj @@ -63,8 +63,8 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi - - + + From 9c77873fefd09f007b2cb27c4f39b383bb7b1d14 Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Sat, 6 Apr 2024 06:13:30 -0500 Subject: [PATCH 4/9] Telerik Upgrade Litify Abacus Fix TimeSlips fix NEOS Fix eBillityFix --- PdfSharpCore/PdfSharpCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PdfSharpCore/PdfSharpCore.csproj b/PdfSharpCore/PdfSharpCore.csproj index 7d3c3440..4065f1e9 100644 --- a/PdfSharpCore/PdfSharpCore.csproj +++ b/PdfSharpCore/PdfSharpCore.csproj @@ -56,7 +56,7 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi - + From 4c0fe08a0d47822e890b5903d459df0c6a6b781c Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Sat, 13 Apr 2024 21:42:49 -0500 Subject: [PATCH 5/9] Lots of Tweaks. Litify, Prevail, TimeSolv, Clio. --- PdfSharpCore/PdfSharpCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PdfSharpCore/PdfSharpCore.csproj b/PdfSharpCore/PdfSharpCore.csproj index 4065f1e9..9e5f62ac 100644 --- a/PdfSharpCore/PdfSharpCore.csproj +++ b/PdfSharpCore/PdfSharpCore.csproj @@ -57,7 +57,7 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi - + From 761e85415ce4f54abd4fb57cfb3bfe1c9d52c92d Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Fri, 3 May 2024 10:48:57 -0500 Subject: [PATCH 6/9] LEAP and lots of tweaks RE custom fields. --- PdfSharpCore/PdfSharpCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PdfSharpCore/PdfSharpCore.csproj b/PdfSharpCore/PdfSharpCore.csproj index 9e5f62ac..282abc4d 100644 --- a/PdfSharpCore/PdfSharpCore.csproj +++ b/PdfSharpCore/PdfSharpCore.csproj @@ -64,7 +64,7 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi - + From 399012b40b087b4c97b3ef1152451a1b5cb3a430 Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Wed, 3 Jul 2024 04:39:33 -0500 Subject: [PATCH 7/9] Package Upgrade. In-app documentation. --- PdfSharpCore/PdfSharpCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PdfSharpCore/PdfSharpCore.csproj b/PdfSharpCore/PdfSharpCore.csproj index 282abc4d..78e99843 100644 --- a/PdfSharpCore/PdfSharpCore.csproj +++ b/PdfSharpCore/PdfSharpCore.csproj @@ -56,7 +56,7 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi - + From 020664c5b0f1c0a5cfc5e01dea33b25eb055fc57 Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Thu, 25 Jul 2024 07:00:27 -0500 Subject: [PATCH 8/9] Commit. --- PdfSharpCore/PdfSharpCore.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PdfSharpCore/PdfSharpCore.csproj b/PdfSharpCore/PdfSharpCore.csproj index d61ce3ac..58bb473b 100644 --- a/PdfSharpCore/PdfSharpCore.csproj +++ b/PdfSharpCore/PdfSharpCore.csproj @@ -57,14 +57,14 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi - + - + From 85c5a94afba0c1c1cd3d9abbdfe9770ae0edc52e Mon Sep 17 00:00:00 2001 From: Tony Valenti Date: Thu, 31 Oct 2024 12:41:23 -0500 Subject: [PATCH 9/9] OAuth --- PdfSharpCore/PdfSharpCore.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PdfSharpCore/PdfSharpCore.csproj b/PdfSharpCore/PdfSharpCore.csproj index 58bb473b..e74f8edb 100644 --- a/PdfSharpCore/PdfSharpCore.csproj +++ b/PdfSharpCore/PdfSharpCore.csproj @@ -56,7 +56,7 @@ PdfSharpCore is a partial port of PdfSharp.Xamarin for .NET Core Additionally Mi - +