Skip to content

Commit

Permalink
Add UglyToad.PdfPig.Rendering.Skia.Graphics and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BobLd committed Jul 30, 2023
1 parent 65301a6 commit ecb6c75
Show file tree
Hide file tree
Showing 20 changed files with 2,814 additions and 133 deletions.
17 changes: 17 additions & 0 deletions src/UglyToad.PdfPig.Rendering.Skia.Tests/Helpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace UglyToad.PdfPig.Rendering.Skia.Tests
{
internal static class Helpers
{
private static readonly string _basePath = Path.GetFullPath("..\\..\\..\\..\\UglyToad.PdfPig.Tests\\Integration\\Documents");

public static string GetDocumentPath(string fileName)
{
if (!fileName.EndsWith(".pdf"))
{
fileName += ".pdf";
}

return Path.Combine(_basePath, fileName);
}
}
}
51 changes: 51 additions & 0 deletions src/UglyToad.PdfPig.Rendering.Skia.Tests/RenderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using SkiaSharp;
using UglyToad.PdfPig.Rendering.Skia.Parser;

namespace UglyToad.PdfPig.Rendering.Skia.Tests
{
public class RenderTests
{
[Fact]
public void PigProductionHandbook()
{
RenderDocument("Pig Production Handbook");
}

[Fact]
public void d_68_1990_01_A()
{
RenderDocument("68-1990-01_A");
}

[Fact]
public void d_22060_A1_01_Plans_1()
{
RenderDocument("22060_A1_01_Plans-1");
}

private static void RenderDocument(string path)
{
using (var document = PdfDocument.Open(Helpers.GetDocumentPath(path)))
{
document.AddPageFactory<SKPicture>(typeof(SkiaPageFactory));

for (int p = 1; p <= document.NumberOfPages; p++)
{
var page = document.GetPage(p);

using (var picture = document.GetPage<SKPicture>(p))
{
Assert.NotNull(picture);

using (var fs = new FileStream($"{path}_{p}.png", FileMode.Create))
using (var image = SKImage.FromPicture(picture, new SKSizeI((int)page.Width, (int)page.Height)))
using (SKData d = image.Encode(SKEncodedImageFormat.Png, 100))
{
d.SaveTo(fs);
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\UglyToad.PdfPig.Rendering.Skia\UglyToad.PdfPig.Rendering.Skia.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/UglyToad.PdfPig.Rendering.Skia.Tests/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Loading

0 comments on commit ecb6c75

Please sign in to comment.