From d7898d851c47e007e82f0b53166883fd65afa731 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 3 Apr 2022 14:48:50 -0400 Subject: [PATCH 1/5] add net 6 as a target framework and dual target tests --- CONTRIBUTING.md | 2 +- src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj | 2 +- .../UglyToad.PdfPig.DocumentLayoutAnalysis.csproj | 2 +- src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj | 2 +- src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj | 2 +- .../UglyToad.PdfPig.Tokenization.csproj | 2 +- src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj | 2 +- src/UglyToad.PdfPig/UglyToad.PdfPig.csproj | 2 +- tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index abf70298..00d3e912 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -45,7 +45,7 @@ Open `.\src\UglyToad.PdfPig\UglyToad.PdfPig.csproj` in a text editor and change: ``` - netstandard2.0;net45;net451;net452;net46;net461;net462;net47 + netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0 PdfPig ... ``` diff --git a/src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj b/src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj index 998695b0..bb180705 100644 --- a/src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj +++ b/src/UglyToad.PdfPig.Core/UglyToad.PdfPig.Core.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net45;net451;net452;net46;net461;net462;net47 + netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0 latest 0.1.6-alpha001 False diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/UglyToad.PdfPig.DocumentLayoutAnalysis.csproj b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/UglyToad.PdfPig.DocumentLayoutAnalysis.csproj index 3a71ba68..88a83e42 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/UglyToad.PdfPig.DocumentLayoutAnalysis.csproj +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/UglyToad.PdfPig.DocumentLayoutAnalysis.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net45;net451;net452;net46;net461;net462;net47 + netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0 latest 0.1.6-alpha001 False diff --git a/src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj b/src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj index fc0311c6..610c9b28 100644 --- a/src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj +++ b/src/UglyToad.PdfPig.Fonts/UglyToad.PdfPig.Fonts.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net45;net451;net452;net46;net461;net462;net47 + netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0 latest 0.1.6-alpha001 False diff --git a/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj b/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj index 6f7f0f5e..878d9824 100644 --- a/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj +++ b/src/UglyToad.PdfPig.Tests/UglyToad.PdfPig.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + netcoreapp2.0;net6.0 true false full diff --git a/src/UglyToad.PdfPig.Tokenization/UglyToad.PdfPig.Tokenization.csproj b/src/UglyToad.PdfPig.Tokenization/UglyToad.PdfPig.Tokenization.csproj index dd207610..a4789e7e 100644 --- a/src/UglyToad.PdfPig.Tokenization/UglyToad.PdfPig.Tokenization.csproj +++ b/src/UglyToad.PdfPig.Tokenization/UglyToad.PdfPig.Tokenization.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net45;net451;net452;net46;net461;net462;net47 + netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0 latest 0.1.6-alpha001 False diff --git a/src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj b/src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj index 22a90f7d..48dcb4ca 100644 --- a/src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj +++ b/src/UglyToad.PdfPig.Tokens/UglyToad.PdfPig.Tokens.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net45;net451;net452;net46;net461;net462;net47 + netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0 latest 0.1.6-alpha001 False diff --git a/src/UglyToad.PdfPig/UglyToad.PdfPig.csproj b/src/UglyToad.PdfPig/UglyToad.PdfPig.csproj index 89b3d5f4..332decf9 100644 --- a/src/UglyToad.PdfPig/UglyToad.PdfPig.csproj +++ b/src/UglyToad.PdfPig/UglyToad.PdfPig.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net45;net451;net452;net46;net461;net462;net47 + netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0 latest 0.1.6-alpha001 False diff --git a/tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj b/tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj index ec25f460..c2108392 100644 --- a/tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj +++ b/tools/UglyToad.PdfPig.Package/UglyToad.PdfPig.Package.csproj @@ -1,6 +1,6 @@ - netstandard2.0;net45;net451;net452;net46;net461;net462;net47 + netstandard2.0;net45;net451;net452;net46;net461;net462;net47;net6.0 PdfPig full UglyToad From 9be57c6948faf0e66cc7ddd404e3ff643598556c Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 3 Apr 2022 15:00:38 -0400 Subject: [PATCH 2/5] use precision in assert for letter bounding box tests --- .../Fonts/SystemFonts/Linux.cs | 65 +++++++++++++++---- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/src/UglyToad.PdfPig.Tests/Fonts/SystemFonts/Linux.cs b/src/UglyToad.PdfPig.Tests/Fonts/SystemFonts/Linux.cs index 5959b7f7..a61b2575 100644 --- a/src/UglyToad.PdfPig.Tests/Fonts/SystemFonts/Linux.cs +++ b/src/UglyToad.PdfPig.Tests/Fonts/SystemFonts/Linux.cs @@ -5,6 +5,8 @@ using Xunit; namespace UglyToad.PdfPig.Tests.Fonts.SystemFonts { + using PdfPig.Core; + public class Linux { public static IEnumerable DataExtract => new[] @@ -12,19 +14,43 @@ namespace UglyToad.PdfPig.Tests.Fonts.SystemFonts new object[] { "90 180 270 rotated.pdf", - new object[][] - { - new object[] { "[(x:53.88, y:759.48), 2.495859375, 0]", 0.0 }, - new object[] { "[(x:514.925312502883, y:744.099765720344), 6.83203125, 7.94531249999983]", -90.0 }, - new object[] { "[(x:512.505390717836, y:736.603703191305), 5.1796875, 5.68945312499983]", -90.0 }, - new object[] { "[(x:512.505390785898, y:730.931828191305), 3.99609375, 5.52539062499994]", -90.0 }, + new ExpectedLetterData[] + { + new ExpectedLetterData + { + TopLeft = new PdfPoint(53.88, 759.48), + Width = 2.495859375, + Height = 0, + Rotation = 0 + }, + new ExpectedLetterData + { + TopLeft = new PdfPoint(514.925312502883, 744.099765720344), + Width = 6.83203125, + Height = 7.94531249999983, + Rotation = -90 + }, + new ExpectedLetterData + { + TopLeft = new PdfPoint(512.505390717836, 736.603703191305), + Width = 5.1796875, + Height = 5.68945312499983, + Rotation = -90 + }, + new ExpectedLetterData + { + TopLeft = new PdfPoint(512.505390785898, 730.931828191305), + Width = 3.99609375, + Height = 5.52539062499994, + Rotation = -90 + }, } }, }; [SkippableTheory] [MemberData(nameof(DataExtract))] - public void GetCorrectBBoxLinux(string name, object[][] expected) + public void GetCorrectBBoxLinux(string name, ExpectedLetterData[] expected) { // success on Windows but LinuxSystemFontLister cannot find the 'TimesNewRomanPSMT' font var font = SystemFontFinder.Instance.GetTrueTypeFont("TimesNewRomanPSMT"); @@ -36,13 +62,28 @@ namespace UglyToad.PdfPig.Tests.Fonts.SystemFonts var page = document.GetPage(1); for (int i = 0; i < expected.Length; i++) { - string bbox = (string)expected[i][0]; - var rotation = (double)expected[i][1]; - var current = page.Letters[i]; - Assert.Equal(bbox, current.GlyphRectangle.ToString()); - Assert.Equal(rotation, current.GlyphRectangle.Rotation, 3); + var expectedData = expected[i]; + + var current = page.Letters[i]; + + Assert.Equal(expectedData.TopLeft.X, current.GlyphRectangle.TopLeft.X, 7); + Assert.Equal(expectedData.TopLeft.Y, current.GlyphRectangle.TopLeft.Y, 7); + Assert.Equal(expectedData.Width, current.GlyphRectangle.Width, 7); + Assert.Equal(expectedData.Height, current.GlyphRectangle.Height, 7); + Assert.Equal(expectedData.Rotation, current.GlyphRectangle.Rotation, 3); } } + } + + public class ExpectedLetterData + { + public PdfPoint TopLeft { get; set; } + + public double Width { get; set; } + + public double Height { get; set; } + + public double Rotation { get; set; } } } } From 347259eaa54f32dc539fc1cc96f46fd478fe0ea9 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 3 Apr 2022 15:13:45 -0400 Subject: [PATCH 3/5] #433 address breaking change in aes api in net 6 https://github.com/dotnet/runtime/issues/55527 --- .../Encryption/AesEncryptionHelperTests.cs | 4 +++- .../Encryption/AesEncryptionHelper.cs | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/UglyToad.PdfPig.Tests/Encryption/AesEncryptionHelperTests.cs b/src/UglyToad.PdfPig.Tests/Encryption/AesEncryptionHelperTests.cs index 6a07a911..1ae27525 100644 --- a/src/UglyToad.PdfPig.Tests/Encryption/AesEncryptionHelperTests.cs +++ b/src/UglyToad.PdfPig.Tests/Encryption/AesEncryptionHelperTests.cs @@ -23,7 +23,9 @@ namespace UglyToad.PdfPig.Tests.Encryption var output = AesEncryptionHelper.Decrypt(data, key); - Assert.Equal("D:20180808103317-07'00'", OtherEncodings.BytesAsLatin1String(output)); + var actual = OtherEncodings.BytesAsLatin1String(output); + + Assert.Equal("D:20180808103317-07'00'", actual); } } } diff --git a/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs b/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs index 3e4cd7b6..7f4a246d 100644 --- a/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs +++ b/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs @@ -35,16 +35,16 @@ input.Seek(iv.Length, SeekOrigin.Begin); using (var cryptoStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read)) { + var offset = 0; int read; - while ((read = cryptoStream.Read(buffer, 0, buffer.Length)) != -1) + do { - output.Write(buffer, 0, read); + read = cryptoStream.Read(buffer, offset, buffer.Length - offset); - if (read < buffer.Length) - { - break; - } - } + output.Write(buffer, offset, read); + + offset += read; + } while (read > 0); return output.ToArray(); } From 3ab0883cf3b9e73bbc490ff0de28a8f4499fb5b9 Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 3 Apr 2022 15:20:42 -0400 Subject: [PATCH 4/5] fix bug with handling of more than 256 bytes --- .../Encryption/AesEncryptionHelper.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs b/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs index 7f4a246d..f572a25d 100644 --- a/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs +++ b/src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs @@ -1,6 +1,7 @@ namespace UglyToad.PdfPig.Encryption { using System; + using System.Diagnostics; using System.IO; using System.Security.Cryptography; @@ -20,7 +21,7 @@ var iv = new byte[16]; Array.Copy(data, iv, iv.Length); - + using (var rijndael = Rijndael.Create()) { rijndael.Key = finalKey; @@ -28,6 +29,11 @@ var buffer = new byte[256]; + if (data.Length > 256) + { + Debugger.Break(); + } + using (var decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV)) using (var input = new MemoryStream(data)) using (var output = new MemoryStream()) @@ -35,15 +41,15 @@ input.Seek(iv.Length, SeekOrigin.Begin); using (var cryptoStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read)) { - var offset = 0; int read; do { - read = cryptoStream.Read(buffer, offset, buffer.Length - offset); + read = cryptoStream.Read(buffer, 0, buffer.Length); - output.Write(buffer, offset, read); - - offset += read; + if (read > 0) + { + output.Write(buffer, 0, read); + } } while (read > 0); return output.ToArray(); From e402a0710552142941d47f50e1d0cbd101e61b2d Mon Sep 17 00:00:00 2001 From: Eliot Jones Date: Sun, 3 Apr 2022 15:22:39 -0400 Subject: [PATCH 5/5] add net 6 support in actions --- .github/workflows/build_and_test.yml | 6 ++++-- .github/workflows/nightly_release.yml | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 89216c75..70a3bbd2 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -13,9 +13,11 @@ jobs: - uses: actions/checkout@master - name: Set up dotnet core - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: - dotnet-version: "2.1.x" + dotnet-version: | + 2.1.x + 6.0.x - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v1.0.2 diff --git a/.github/workflows/nightly_release.yml b/.github/workflows/nightly_release.yml index 0eca77a0..7ec4938b 100644 --- a/.github/workflows/nightly_release.yml +++ b/.github/workflows/nightly_release.yml @@ -30,9 +30,11 @@ jobs: - uses: actions/checkout@master - name: Set up dotnet core - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: - dotnet-version: "2.1.x" + dotnet-version: | + 2.1.x + 6.0.x - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v1.0.2