зеркало из https://github.com/Dtronix/DtronixPdf.git
Updated .NET version to 8.
Removed DtronixCommon tooling and used Vector128<float> instead of BoundaryF.
This commit is contained in:
Родитель
7ddf6b1519
Коммит
6e071eeda3
|
@ -1,6 +1,6 @@
|
|||
# DtronixPdf [![NuGet](https://img.shields.io/nuget/v/DtronixPdf.svg?maxAge=60)](https://www.nuget.org/packages/DtronixPdf) [![Action Workflow](https://github.com/Dtronix/DtronixPdf/actions/workflows/dotnet.yml/badge.svg)](https://github.com/Dtronix/DtronixPdf/actions)
|
||||
|
||||
DtronixPdf is a .NET 5.0 library to handle interactions with PDFs via the PDFium library which is inherently not thread safe. This library will serialize all calls which are made to the PDFium backend and execute them all on a single thread via a dispatcher. Results are then returned through Tasks to the calling site.
|
||||
DtronixPdf is a .NET 8.0 library to handle interactions with PDFs via the PDFium library which is inherently not thread safe. This library will serialize all calls which are made to the PDFium backend and execute them all on a single thread via a dispatcher. Results are then returned through Tasks to the calling site.
|
||||
|
||||
Supports Linux-x64, OSX-x64, Win-x64, Win-x86.
|
||||
|
||||
|
@ -12,7 +12,7 @@ Supports Linux-x64, OSX-x64, Win-x64, Win-x86.
|
|||
- Manual building. `dotnet build -c Release`
|
||||
|
||||
### Build Requirements
|
||||
- .NET 5.0
|
||||
- .NET 8.0
|
||||
|
||||
### References
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
<Import Project="..\DtronixPdf.props" />
|
||||
<PropertyGroup>
|
||||
<Description>ImageSharp bindings for DtronixPdf</Description>
|
||||
<Version>1.1.3.0</Version>
|
||||
<Version>1.2.0.0</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
|
|
@ -9,9 +9,9 @@ namespace DtronixPdf.ImageSharp
|
|||
{
|
||||
return Image.WrapMemory<Bgra32>(
|
||||
bitmap.Pointer.ToPointer(),
|
||||
(int)bitmap.Viewport.Width,
|
||||
(int)bitmap.Viewport.Height);
|
||||
(int)(bitmap.Viewport[2] - bitmap.Viewport[0]),
|
||||
(int)(bitmap.Viewport[3] - bitmap.Viewport[1]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ using System.IO;
|
|||
using System.Net.Mime;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DtronixCommon;
|
||||
using DtronixPdf.ImageSharp;
|
||||
using NUnit.Framework;
|
||||
using PDFiumCore;
|
||||
|
@ -20,7 +19,6 @@ namespace DtronixPdf.Tests
|
|||
using var document = PdfDocument.Load("TestPdf.pdf", null);
|
||||
using var page = document.GetPage(0);
|
||||
var renderPage = page.Render(1);
|
||||
|
||||
var image = renderPage.GetImage();
|
||||
|
||||
Assert.AreEqual(page.Width, image.Width);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Company>Dtronix</Company>
|
||||
<Product>Dtronix PDF</Product>
|
||||
<Copyright>Copyright © Dtronix 2022</Copyright>
|
||||
<Copyright>Copyright © Dtronix 2024</Copyright>
|
||||
<Authors>DJGosnell</Authors>
|
||||
<PackageProjectUrl>https://github.com/Dtronix/DtronixPdf</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/Dtronix/DtronixPdf</RepositoryUrl>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<Import Project="..\DtronixPdf.props" />
|
||||
<PropertyGroup>
|
||||
<Description>Tool to view and perform common modifications to PDFs. Based on PDFium.</Description>
|
||||
<Version>1.1.3.0</Version>
|
||||
<Version>1.2.0.0</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
|
||||
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
|
||||
|
@ -16,7 +16,6 @@
|
|||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DtronixCommon" Version="0.7.0" />
|
||||
<PackageReference Include="PDFiumCore" Version="119.0.6043" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using DtronixCommon;
|
||||
using System.Runtime.Intrinsics;
|
||||
using PDFiumCore;
|
||||
|
||||
namespace DtronixPdf
|
||||
|
@ -12,7 +12,10 @@ namespace DtronixPdf
|
|||
|
||||
public float Scale { get; }
|
||||
|
||||
public BoundaryF Viewport { get; }
|
||||
/// <summary>
|
||||
/// MinX, MinY, MaxX, MaxY
|
||||
/// </summary>
|
||||
public Vector128<float> Viewport { get; }
|
||||
|
||||
public IntPtr Pointer { get; }
|
||||
|
||||
|
@ -30,17 +33,17 @@ namespace DtronixPdf
|
|||
/// <param name="pdfBitmap"></param>
|
||||
/// <param name="synchronizer"></param>
|
||||
/// <param name="scale"></param>
|
||||
/// <param name="viewport"></param>
|
||||
/// <param name="viewport">MinX, MinY, MaxX, MaxY</param>
|
||||
internal PdfBitmap(
|
||||
FpdfBitmapT pdfBitmap,
|
||||
PdfActionSynchronizer synchronizer,
|
||||
float scale,
|
||||
BoundaryF viewport)
|
||||
float scale,
|
||||
Vector128<float> viewport)
|
||||
{
|
||||
_pdfBitmap = pdfBitmap;
|
||||
Stride = fpdfview.FPDFBitmapGetStride(_pdfBitmap);
|
||||
Width = (int)viewport.Width;
|
||||
Height = (int)viewport.Height;
|
||||
Width = (int)viewport.GetWidth();
|
||||
Height = (int)viewport.GetHeight();
|
||||
Pointer = fpdfview.FPDFBitmapGetBuffer(_pdfBitmap);
|
||||
_synchronizer = synchronizer;
|
||||
Scale = scale;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Threading;
|
||||
using DtronixCommon;
|
||||
using PDFiumCore;
|
||||
|
||||
namespace DtronixPdf
|
||||
|
@ -63,7 +62,7 @@ namespace DtronixPdf
|
|||
var config = new PdfPageRenderConfig()
|
||||
{
|
||||
Scale = scale,
|
||||
Viewport = new BoundaryF(0, 0, Width * scale, Height * scale),
|
||||
Viewport = Vector128.Create(0, 0, Width * scale, Height * scale),
|
||||
CancellationToken = cancellationToken,
|
||||
};
|
||||
|
||||
|
@ -77,13 +76,20 @@ namespace DtronixPdf
|
|||
|
||||
FpdfBitmapT bitmap = null;
|
||||
|
||||
var viewportHeight = config.Viewport.GetHeight();
|
||||
var viewportHeightInt = (int)viewportHeight;
|
||||
var viewportWidth = config.Viewport.GetWidth();
|
||||
var viewportWidthInt = (int)viewportWidth;
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
config.CancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
bitmap = Document.Synchronizer.SyncExec(() => fpdfview.FPDFBitmapCreateEx(
|
||||
(int)config.Viewport.Width,
|
||||
(int)config.Viewport.Height,
|
||||
viewportWidthInt,
|
||||
viewportHeightInt,
|
||||
(int)FPDFBitmapFormat.BGRA,
|
||||
IntPtr.Zero,
|
||||
0));
|
||||
|
@ -99,8 +105,8 @@ namespace DtronixPdf
|
|||
bitmap,
|
||||
0,
|
||||
0,
|
||||
(int)config.Viewport.Width,
|
||||
(int)config.Viewport.Height,
|
||||
viewportWidthInt,
|
||||
viewportHeightInt,
|
||||
config.BackgroundColor.Value));
|
||||
|
||||
config.CancellationToken.ThrowIfCancellationRequested();
|
||||
|
@ -109,9 +115,9 @@ namespace DtronixPdf
|
|||
using var clipping = new FS_RECTF_
|
||||
{
|
||||
Left = 0,
|
||||
Right = config.Viewport.Width,
|
||||
Right = viewportWidth,
|
||||
Bottom = 0,
|
||||
Top = config.Viewport.Height
|
||||
Top = viewportHeight
|
||||
};
|
||||
|
||||
// | | a b 0 |
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Threading;
|
||||
using DtronixCommon;
|
||||
using PDFiumCore;
|
||||
|
||||
namespace DtronixPdf
|
||||
|
@ -8,7 +7,11 @@ namespace DtronixPdf
|
|||
public record class PdfPageRenderConfig
|
||||
{
|
||||
public float Scale { get; init; }
|
||||
public BoundaryF Viewport { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Viewport must be setup with MinX, MinY, MaxX, MaxY formatting.
|
||||
/// </summary>
|
||||
public Vector128<float> Viewport { get; init; }
|
||||
|
||||
public uint? BackgroundColor { get; init; }
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Intrinsics;
|
||||
|
||||
namespace DtronixPdf;
|
||||
|
||||
internal static class VectorHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the width of the vector.
|
||||
/// </summary>
|
||||
/// <param name="vector">Order needs to be MinX, MinY, MaxX, MaxY</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float GetWidth(this in Vector128<float> vector)
|
||||
{
|
||||
return vector[2] - vector[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the height of the vector.
|
||||
/// </summary>
|
||||
/// <param name="vector">Order needs to be MinX, MinY, MaxX, MaxY</param>
|
||||
/// <returns></returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float GetHeight(this in Vector128<float> vector)
|
||||
{
|
||||
return vector[3] - vector[1];
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Runtime.Intrinsics;
|
||||
using System.Threading.Tasks;
|
||||
using DtronixCommon;
|
||||
using DtronixPdf;
|
||||
using DtronixPdf.ImageSharp;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace DtronixPdfBenchmark
|
||||
{
|
||||
|
@ -43,11 +41,11 @@ namespace DtronixPdfBenchmark
|
|||
Point center = new Point(0, 0);
|
||||
Size size = new Size(1920, 1080);
|
||||
|
||||
var viewport = new BoundaryF(
|
||||
0,
|
||||
0,
|
||||
1920,
|
||||
1080);
|
||||
var viewport = Vector128.Create(
|
||||
0f,
|
||||
0f,
|
||||
1920f,
|
||||
1080f);
|
||||
|
||||
using var result = page.Render(new PdfPageRenderConfig()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче