mirror of
https://github.com/cyanfish/naps2.git
synced 2024-10-26 17:11:21 +03:00
Pdfium renderer working aside from colors
This commit is contained in:
parent
2f4cb33cca
commit
ce033a5b8e
@ -116,6 +116,16 @@
|
|||||||
<Link>lib\win32\NAPS2.WIA.dll</Link>
|
<Link>lib\win32\NAPS2.WIA.dll</Link>
|
||||||
<TargetPath>_win32\NAPS2.WIA.dll</TargetPath>
|
<TargetPath>_win32\NAPS2.WIA.dll</TargetPath>
|
||||||
</ContentWithTargetPath>
|
</ContentWithTargetPath>
|
||||||
|
<ContentWithTargetPath Include="..\NAPS2.Setup\lib\win64\pdfium.dll">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
<Link>lib\win64\pdfium.dll</Link>
|
||||||
|
<TargetPath>_win64\pdfium.dll</TargetPath>
|
||||||
|
</ContentWithTargetPath>
|
||||||
|
<ContentWithTargetPath Include="..\NAPS2.Setup\lib\win32\pdfium.dll">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
<Link>lib\win32\pdfium.dll</Link>
|
||||||
|
<TargetPath>_win32\pdfium.dll</TargetPath>
|
||||||
|
</ContentWithTargetPath>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||||
|
@ -171,6 +171,16 @@
|
|||||||
<Link>lib\win32\NAPS2.WIA.dll</Link>
|
<Link>lib\win32\NAPS2.WIA.dll</Link>
|
||||||
<TargetPath>_win32\NAPS2.WIA.dll</TargetPath>
|
<TargetPath>_win32\NAPS2.WIA.dll</TargetPath>
|
||||||
</ContentWithTargetPath>
|
</ContentWithTargetPath>
|
||||||
|
<ContentWithTargetPath Include="..\NAPS2.Setup\lib\win64\pdfium.dll">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
<Link>lib\win64\pdfium.dll</Link>
|
||||||
|
<TargetPath>_win64\pdfium.dll</TargetPath>
|
||||||
|
</ContentWithTargetPath>
|
||||||
|
<ContentWithTargetPath Include="..\NAPS2.Setup\lib\win32\pdfium.dll">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
<Link>lib\win32\pdfium.dll</Link>
|
||||||
|
<TargetPath>_win32\pdfium.dll</TargetPath>
|
||||||
|
</ContentWithTargetPath>
|
||||||
<Content Include="scanner-app.ico" />
|
<Content Include="scanner-app.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -30,6 +30,9 @@ namespace NAPS2.ImportExport.Pdf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("pdfium.dll")]
|
||||||
|
public static extern IntPtr FPDF_InitLibrary();
|
||||||
|
|
||||||
[DllImport("pdfium.dll")]
|
[DllImport("pdfium.dll")]
|
||||||
public static extern IntPtr FPDFBitmap_Create(int width, int height, int alpha);
|
public static extern IntPtr FPDFBitmap_Create(int width, int height, int alpha);
|
||||||
|
|
||||||
@ -40,10 +43,10 @@ namespace NAPS2.ImportExport.Pdf
|
|||||||
public static extern void FPDFBitmap_Destroy(IntPtr bitmap);
|
public static extern void FPDFBitmap_Destroy(IntPtr bitmap);
|
||||||
|
|
||||||
[DllImport("pdfium.dll")]
|
[DllImport("pdfium.dll")]
|
||||||
public static extern IntPtr FPDF_LoadDocument(string filePath, string password);
|
public static extern IntPtr FPDF_LoadDocument([MarshalAs(UnmanagedType.LPStr)] string filePath, [MarshalAs(UnmanagedType.LPStr)] string password);
|
||||||
|
|
||||||
[DllImport("pdfium.dll")]
|
[DllImport("pdfium.dll")]
|
||||||
public static extern IntPtr FPDF_LoadMemDocument(IntPtr buffer, int size, string password);
|
public static extern IntPtr FPDF_LoadMemDocument(IntPtr buffer, int size, [MarshalAs(UnmanagedType.LPStr)] string password);
|
||||||
|
|
||||||
[DllImport("pdfium.dll")]
|
[DllImport("pdfium.dll")]
|
||||||
public static extern int FPDF_GetPageCount(IntPtr document);
|
public static extern int FPDF_GetPageCount(IntPtr document);
|
||||||
|
@ -11,10 +11,15 @@ namespace NAPS2.ImportExport.Pdf
|
|||||||
{
|
{
|
||||||
private const int RENDER_FLAGS = PdfiumNativeMethods.FPDF_PRINTING | PdfiumNativeMethods.FPDF_REVERSE_BYTE_ORDER;
|
private const int RENDER_FLAGS = PdfiumNativeMethods.FPDF_PRINTING | PdfiumNativeMethods.FPDF_REVERSE_BYTE_ORDER;
|
||||||
|
|
||||||
|
static PdfiumPdfRenderer()
|
||||||
|
{
|
||||||
|
PdfiumNativeMethods.FPDF_InitLibrary();
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<IImage> Render(string path)
|
public IEnumerable<IImage> Render(string path)
|
||||||
{
|
{
|
||||||
// TODO: Maybe allow this to be configured
|
// TODO: Maybe allow this to be configured
|
||||||
int dpi = ScanDpi.Dpi300.ToIntDpi();
|
float dpi = ScanDpi.Dpi300.ToIntDpi();
|
||||||
|
|
||||||
var doc = PdfiumNativeMethods.FPDF_LoadDocument(path, null);
|
var doc = PdfiumNativeMethods.FPDF_LoadDocument(path, null);
|
||||||
var pageCount = PdfiumNativeMethods.FPDF_GetPageCount(doc);
|
var pageCount = PdfiumNativeMethods.FPDF_GetPageCount(doc);
|
||||||
@ -23,13 +28,14 @@ namespace NAPS2.ImportExport.Pdf
|
|||||||
{
|
{
|
||||||
var page = PdfiumNativeMethods.FPDF_LoadPage(doc, pageIndex);
|
var page = PdfiumNativeMethods.FPDF_LoadPage(doc, pageIndex);
|
||||||
var widthInInches = PdfiumNativeMethods.FPDF_GetPageWidth(page) * 72;
|
var widthInInches = PdfiumNativeMethods.FPDF_GetPageWidth(page) * 72;
|
||||||
var heightInInches = PdfiumNativeMethods.FPDF_GetPageWidth(page) * 72;
|
var heightInInches = PdfiumNativeMethods.FPDF_GetPageHeight(page) * 72;
|
||||||
int widthInPx = (int)Math.Round(widthInInches * dpi);
|
|
||||||
int heightInPx = (int)Math.Round(heightInInches * dpi);
|
|
||||||
|
|
||||||
// Cap the resolution to 10k pixels in each dimension
|
// Cap the resolution to 10k pixels in each dimension
|
||||||
dpi = Math.Min(dpi, (int)(10000 / heightInInches));
|
dpi = Math.Min(dpi, (float)(10000 / heightInInches));
|
||||||
dpi = Math.Min(dpi, (int)(10000 / widthInInches));
|
dpi = Math.Min(dpi, (float)(10000 / widthInInches));
|
||||||
|
|
||||||
|
int widthInPx = (int)Math.Round(widthInInches * dpi);
|
||||||
|
int heightInPx = (int)Math.Round(heightInInches * dpi);
|
||||||
|
|
||||||
var bitmap = StorageManager.ImageFactory.FromDimensions(widthInPx, heightInPx, StoragePixelFormat.RGB24);
|
var bitmap = StorageManager.ImageFactory.FromDimensions(widthInPx, heightInPx, StoragePixelFormat.RGB24);
|
||||||
bitmap.SetResolution(dpi, dpi);
|
bitmap.SetResolution(dpi, dpi);
|
||||||
|
@ -13,5 +13,6 @@
|
|||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lineart/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lineart/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lossless/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lossless/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=mapi/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=mapi/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pdfium/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pdfs/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pdfs/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=rmse/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=rmse/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
Loading…
Reference in New Issue
Block a user