NativeMethods.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;
  4. namespace Paroxe.PdfRenderer.Internal
  5. {
  6. public static class NativeMethods
  7. {
  8. #if !UNITY_WEBGL || UNITY_EDITOR
  9. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  10. public static extern IntPtr FPDFAction_GetDest(IntPtr document, IntPtr action);
  11. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  12. public static extern uint FPDFAction_GetFilePath(IntPtr action, [In, Out] byte[] buffer, uint buflen);
  13. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  14. public static extern uint FPDFAction_GetType(IntPtr action);
  15. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  16. public static extern uint FPDFAction_GetURIPath(IntPtr document, IntPtr action, [In, Out] byte[] buffer, uint buflen);
  17. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  18. public static extern uint FPDFDest_GetDestPageIndex(IntPtr document, IntPtr dest);
  19. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  20. public static extern IntPtr FPDFLink_GetAction(IntPtr link);
  21. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  22. public static extern IntPtr FPDFLink_GetDest(IntPtr document, IntPtr link);
  23. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  24. public static extern IntPtr FPDFBookmark_GetAction(IntPtr bookmark);
  25. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  26. public static extern IntPtr FPDFBookmark_GetDest(IntPtr document, IntPtr bookmark);
  27. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  28. public static extern IntPtr FPDFBookmark_GetFirstChild(IntPtr document, IntPtr bookmark);
  29. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  30. public static extern IntPtr FPDFBookmark_GetNextSibling(IntPtr document, IntPtr bookmark);
  31. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  32. public static extern uint FPDFBookmark_GetTitle(IntPtr bookmark, [In, Out] byte[] buffer, uint buflen);
  33. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  34. public static extern void FPDF_CloseDocument(IntPtr document);
  35. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  36. public static extern uint FPDF_GetDocPermissions(IntPtr document);
  37. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  38. public static extern int FPDF_GetPageCount(IntPtr document);
  39. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY, CharSet = CharSet.Ansi)]
  40. public static extern IntPtr FPDF_LoadMemDocument(IntPtr data_buf, int size, string password);
  41. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  42. public static extern int FPDF_GetPageSizeByIndex(IntPtr document, int page_index, out double width, out double height);
  43. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  44. public static extern uint FPDF_GetLastError();
  45. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  46. public static extern void FPDF_DestroyLibrary();
  47. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  48. public static extern void FPDF_InitLibrary();
  49. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  50. public static extern IntPtr FPDF_LoadPage(IntPtr document, int page_index);
  51. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  52. public static extern void FPDF_ClosePage(IntPtr page);
  53. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  54. public static extern IntPtr FPDFLink_GetLinkAtPoint(IntPtr page, double x, double y);
  55. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  56. public static extern void FPDF_DeviceToPage(IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, int device_x, int device_y, out double page_x, out double page_y);
  57. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  58. public static extern void FPDF_PageToDevice(IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, double page_x, double page_y, out int device_x, out int device_y);
  59. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  60. public static extern void FPDF_RenderPageBitmap(IntPtr bitmap, IntPtr page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags);
  61. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  62. public static extern void FPDF_RenderPageBitmapWithMatrix(IntPtr bitmap, IntPtr page, ref PDFRenderer.PDFMatrix matrix, ref PDFRenderer.PDFRect clipping, int flags);
  63. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  64. public static extern IntPtr FPDFText_FindStart(IntPtr text_page, IntPtr buffer, uint flags, int start_index);
  65. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  66. public static extern void FPDFText_FindClose(IntPtr handle);
  67. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  68. public static extern bool FPDFText_FindNext(IntPtr handle);
  69. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  70. public static extern bool FPDFText_FindPrev(IntPtr handle);
  71. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  72. public static extern int FPDFText_GetSchCount(IntPtr handle);
  73. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  74. public static extern int FPDFText_GetSchResultIndex(IntPtr handle);
  75. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  76. public static extern IntPtr FPDFText_LoadPage(IntPtr page);
  77. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  78. public static extern void FPDFText_ClosePage(IntPtr text_page);
  79. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  80. public static extern int FPDFText_CountChars(IntPtr text_page);
  81. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  82. public static extern int FPDFText_CountRects(IntPtr text_page, int start_index, int count);
  83. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  84. public static extern int FPDFText_GetBoundedText(IntPtr text_page, double left, double top, double right, double bottom, [In, Out] byte[] buffer, int buflen);
  85. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  86. public static extern void FPDFText_GetCharBox(IntPtr text_page, int index, out double left, out double right, out double bottom, out double top);
  87. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  88. public static extern int FPDFText_GetCharIndexAtPos(IntPtr text_page, double x, double y, double xTolerance, double yTolerance);
  89. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  90. public static extern double FPDFText_GetFontSize(IntPtr text_page, int index);
  91. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  92. public static extern void FPDFText_GetRect(IntPtr text_page, int rect_index, out double left, out double top, out double right, out double bottom);
  93. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  94. public static extern int FPDFText_GetText(IntPtr text_page, int start_index, int count, [In, Out] byte[] buffer);
  95. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  96. public static extern uint FPDFText_GetUnicode(IntPtr text_page, int index);
  97. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  98. public static extern IntPtr FPDFBitmap_Create(int width, int height, bool alpha);
  99. //[MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  100. //private static extern IntPtr FPDFBitmap_CreateEx(int width, int height, int format, IntPtr firstScan, int stride);
  101. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  102. public static extern void FPDFBitmap_Destroy(IntPtr bitmap);
  103. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  104. public static extern void FPDFBitmap_FillRect(IntPtr bitmap, int left, int top, int width, int height, int color);
  105. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  106. public static extern IntPtr FPDFBitmap_GetBuffer(IntPtr bitmap);
  107. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  108. public static extern int FPDFBitmap_GetStride(IntPtr bitmap);
  109. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  110. public static extern PDFBitmap.BitmapFormat FPDFBitmap_GetFormat(IntPtr bitmap);
  111. #else
  112. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  113. public static extern void PDFJS_LoadDocumentFromURL(string promiseHandle, string documentUrl);
  114. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  115. public static extern void PDFJS_LoadDocumentFromBytes(string promiseHandle, string base64);
  116. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  117. public static extern void PDFJS_CloseDocument(int document);
  118. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  119. public static extern int PDFJS_GetPageCount(int documentHandle);
  120. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  121. public static extern void PDFJS_InitLibrary();
  122. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  123. public static extern void PDFJS_LoadPage(string promiseHandle, int documentHandle, int pageIndex);
  124. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  125. public static extern void PDFJS_ClosePage(int pageHandle);
  126. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  127. public static extern int PDFJS_GetPageWidth(int pageHandle, float scale);
  128. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  129. public static extern int PDFJS_GetPageHeight(int pageHandle, float scale);
  130. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  131. public static extern void PDFJS_RenderPageIntoCanvas(string promiseHandle, int pageHandle, float scale, float width, float height);
  132. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  133. public static extern void PDFJS_RenderCanvasIntoTexture(int canvasHandle, int textureHandle);
  134. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  135. public static extern void PDFJS_TryTerminateRenderWorker(string promiseHandle);
  136. [MethodImpl(MethodImplOptions.Synchronized), DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  137. public static extern void PDFJS_DestroyCanvas(int canvasHandle);
  138. #endif
  139. }
  140. }