-
-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SourceGenerator for native code of PdfInfo.
- Loading branch information
Showing
4 changed files
with
13 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,17 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. | ||
// Licensed under the Apache License, Version 2.0. | ||
// <auto-generated/> | ||
#nullable enable | ||
|
||
using System; | ||
using System.Security; | ||
using System.Runtime.InteropServices; | ||
using ImageMagick.SourceGenerator; | ||
|
||
namespace ImageMagick.Formats; | ||
|
||
/// <content /> | ||
public partial class PdfInfo | ||
{ | ||
[SuppressUnmanagedCodeSecurity] | ||
private static unsafe class NativeMethods | ||
[NativeInterop] | ||
private partial class NativePdfInfo | ||
{ | ||
#if PLATFORM_x64 || PLATFORM_AnyCPU | ||
public static class X64 | ||
{ | ||
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)] | ||
public static extern UIntPtr PdfInfo_PageCount(IntPtr fileName, IntPtr password, out IntPtr exception); | ||
} | ||
#endif | ||
#if PLATFORM_arm64 || PLATFORM_AnyCPU | ||
public static class ARM64 | ||
{ | ||
[DllImport(NativeLibrary.ARM64Name, CallingConvention = CallingConvention.Cdecl)] | ||
public static extern UIntPtr PdfInfo_PageCount(IntPtr fileName, IntPtr password, out IntPtr exception); | ||
} | ||
#endif | ||
#if PLATFORM_x86 || PLATFORM_AnyCPU | ||
public static class X86 | ||
{ | ||
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)] | ||
public static extern UIntPtr PdfInfo_PageCount(IntPtr fileName, IntPtr password, out IntPtr exception); | ||
} | ||
#endif | ||
} | ||
private unsafe sealed partial class NativePdfInfo : NativeHelper | ||
{ | ||
static NativePdfInfo() { Environment.Initialize(); } | ||
public int PageCount(string fileName, string password) | ||
{ | ||
using var fileNameNative = UTF8Marshaler.CreateInstance(fileName); | ||
using var passwordNative = UTF8Marshaler.CreateInstance(password); | ||
IntPtr exception = IntPtr.Zero; | ||
UIntPtr result; | ||
#if PLATFORM_AnyCPU | ||
if (Runtime.IsArm64) | ||
#endif | ||
#if PLATFORM_arm64 || PLATFORM_AnyCPU | ||
result = NativeMethods.ARM64.PdfInfo_PageCount(fileNameNative.Instance, passwordNative.Instance, out exception); | ||
#endif | ||
#if PLATFORM_AnyCPU | ||
else if (Runtime.Is64Bit) | ||
#endif | ||
#if PLATFORM_x64 || PLATFORM_AnyCPU | ||
result = NativeMethods.X64.PdfInfo_PageCount(fileNameNative.Instance, passwordNative.Instance, out exception); | ||
#endif | ||
#if PLATFORM_AnyCPU | ||
else | ||
#endif | ||
#if PLATFORM_x86 || PLATFORM_AnyCPU | ||
result = NativeMethods.X86.PdfInfo_PageCount(fileNameNative.Instance, passwordNative.Instance, out exception); | ||
#endif | ||
CheckException(exception); | ||
return (int)result; | ||
} | ||
[Throws] | ||
public static partial int PageCount(string fileName, string password); | ||
} | ||
} |