Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build_and_test_macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build and test [MacOS]

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@master

- name: Set up dotnet core
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
2.1.x
6.0.x
8.0.x

# Build the release build
- name: Build the solution
run: dotnet build -c Release src/UglyToad.PdfPig.sln

- name: Run the tests
run: dotnet test -c Release src/UglyToad.PdfPig.sln
10 changes: 9 additions & 1 deletion src/UglyToad.PdfPig.Tests/Integration/LetterFilterTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
namespace UglyToad.PdfPig.Tests.Integration
{
using PdfPig.Fonts.SystemFonts;
using System.Linq;

public class LetterFilterTests
{
[Fact]
[SkippableFact]
public void CanFilterClippedLetters()
{
var one = IntegrationHelpers.GetDocumentPath("ClipPathLetterFilter-Test1.pdf");

// The 'TimesNewRomanPSMT' font is used by this particular document. Thus, results cannot be trusted on
// platforms where this font isn't generally available (e.g. OSX, Linux, etc.), so we skip it!
var font = SystemFontFinder.Instance.GetTrueTypeFont("TimesNewRomanPSMT");
var font1 = SystemFontFinder.Instance.GetTrueTypeFont("TimesNewRomanPS-BoldMT");
var font2 = SystemFontFinder.Instance.GetTrueTypeFont("TimesNewRomanPS-ItalicMT");
Skip.If(font is null || font1 is null || font2 is null, "Skipped because the font TimesNewRomanPSMT or a font from TimesNewRoman family could not be found in the execution environment.");

using (var doc1 = PdfDocument.Open(one, new ParsingOptions { ClipPaths = true }))
using (var doc2 = PdfDocument.Open(one, new ParsingOptions { ClipPaths = false }))
{
Expand Down
20 changes: 10 additions & 10 deletions src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,18 +1252,18 @@ public void CanCreateDocumentWithOutline()
bookmarks.GetNodes().OfType<UriBookmarkNode>().Select(node => node.Uri));

Assert.Equal(
new[]
new byte[]
{
ExplicitDestinationType.XyzCoordinates,
ExplicitDestinationType.FitPage,
ExplicitDestinationType.FitRectangle,
ExplicitDestinationType.FitBoundingBox,
ExplicitDestinationType.FitBoundingBoxHorizontally,
ExplicitDestinationType.FitBoundingBoxVertically,
ExplicitDestinationType.FitHorizontally,
ExplicitDestinationType.FitVertically,
(byte)ExplicitDestinationType.XyzCoordinates,
(byte)ExplicitDestinationType.FitPage,
(byte)ExplicitDestinationType.FitRectangle,
(byte)ExplicitDestinationType.FitBoundingBox,
(byte)ExplicitDestinationType.FitBoundingBoxHorizontally,
(byte)ExplicitDestinationType.FitBoundingBoxVertically,
(byte)ExplicitDestinationType.FitHorizontally,
(byte)ExplicitDestinationType.FitVertically,
},
bookmarks.GetNodes().OfType<DocumentBookmarkNode>().Select(node => node.Destination.Type));
bookmarks.GetNodes().OfType<DocumentBookmarkNode>().Select(node => (byte)node.Destination.Type));
}
}

Expand Down
39 changes: 16 additions & 23 deletions src/UglyToad.PdfPig/Encryption/AesEncryptionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace UglyToad.PdfPig.Encryption
{
using System;
using System.IO;
using System.Security.Cryptography;

internal static class AesEncryptionHelper
{
public static byte[] Encrypt256()
{
// See https://stackoverflow.com/questions/73779169/cryptographicexception-bad-pkcs7-padding-invalid-length-0-cannot-decrypt-sa
throw new NotImplementedException();
}

Expand All @@ -27,35 +27,28 @@ public static byte[] Decrypt(byte[] data, byte[] finalKey)
aes.IV = iv;

#if NET8_0_OR_GREATER
var encryptedData = data.AsSpan(iv.Length);
if (encryptedData.IsEmpty)
if (data.Length <= iv.Length)
{
aes.Clear();
return [];
}
return aes.DecryptCbc(encryptedData, iv, PaddingMode.PKCS7);

var encryptedData = data.AsSpan(iv.Length);
var output = aes.DecryptCbc(encryptedData, iv, PaddingMode.PKCS7);
aes.Clear();
return output;
#else
var buffer = new byte[256];
if (data.Length <= iv.Length)
{
aes.Clear();
return [];
}

using (var decryptor = aes.CreateDecryptor(aes.Key, aes.IV))
using (var input = new MemoryStream(data))
using (var output = new MemoryStream())
{
input.Seek(iv.Length, SeekOrigin.Begin);
using (var cryptoStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read))
{
int read;
do
{
read = cryptoStream.Read(buffer, 0, buffer.Length);

if (read > 0)
{
output.Write(buffer, 0, read);
}
} while (read > 0);

return output.ToArray();
}
var output = decryptor.TransformFinalBlock(data, iv.Length, data.Length - iv.Length);
aes.Clear();
return output;
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// The display type for opening an <see cref="ExplicitDestination"/>.
/// </summary>
public enum ExplicitDestinationType
public enum ExplicitDestinationType : byte
{
/// <summary>
/// Display the page with the given top left coordinates and
Expand Down
Loading