PDFDest.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. http://www.cgsoso.com/forum-211-1.html
  3. CG搜搜 Unity3d 每日Unity3d插件免费更新 更有VIP资源!
  4. CGSOSO 主打游戏开发,影视设计等CG资源素材。
  5. 插件如若商用,请务必官网购买!
  6. daily assets update for try.
  7. U should buy the asset from home store if u use it in your project!
  8. */
  9. using System;
  10. using System.Runtime.InteropServices;
  11. namespace Paroxe.PdfRenderer
  12. {
  13. #if !UNITY_WEBGL
  14. /// <summary>
  15. /// Represents a destination into a PDF document.
  16. /// </summary>
  17. public class PDFDest : IDisposable
  18. {
  19. private bool m_Disposed;
  20. private IntPtr m_NativePointer;
  21. private IDisposable m_Source;
  22. private PDFDocument m_Document;
  23. private int m_PageIndex = -1;
  24. public PDFDest(PDFAction action, IntPtr nativePointer)
  25. {
  26. if (action == null)
  27. throw new NullReferenceException();
  28. if (nativePointer == IntPtr.Zero)
  29. throw new NullReferenceException();
  30. PDFLibrary.AddRef("PDFDest");
  31. m_Source = action;
  32. m_Document = action.Document;
  33. m_NativePointer = nativePointer;
  34. }
  35. public PDFDest(PDFLink link, IntPtr nativePointer)
  36. {
  37. if (link == null)
  38. throw new NullReferenceException();
  39. if (nativePointer == IntPtr.Zero)
  40. throw new NullReferenceException();
  41. PDFLibrary.AddRef("PDFDest");
  42. m_Source = link;
  43. m_Document = link.Page.Document;
  44. m_NativePointer = nativePointer;
  45. }
  46. public PDFDest(PDFBookmark bookmark, IntPtr nativePointer)
  47. {
  48. if (bookmark == null)
  49. throw new NullReferenceException();
  50. if (nativePointer == IntPtr.Zero)
  51. throw new NullReferenceException();
  52. PDFLibrary.AddRef("PDFDest");
  53. m_Source = bookmark;
  54. m_Document = bookmark.Document;
  55. m_NativePointer = nativePointer;
  56. }
  57. ~PDFDest()
  58. {
  59. Dispose(false);
  60. }
  61. public void Dispose()
  62. {
  63. Dispose(true);
  64. GC.SuppressFinalize(this);
  65. }
  66. protected virtual void Dispose(bool disposing)
  67. {
  68. if (!m_Disposed)
  69. {
  70. m_NativePointer = IntPtr.Zero;
  71. PDFLibrary.RemoveRef("PDFDest");
  72. m_Disposed = true;
  73. }
  74. }
  75. public PDFDocument Document
  76. {
  77. get { return m_Document; }
  78. }
  79. public IDisposable Source
  80. {
  81. get { return m_Source; }
  82. }
  83. public IntPtr NativePointer
  84. {
  85. get { return m_NativePointer; }
  86. }
  87. public int PageIndex
  88. {
  89. get
  90. {
  91. if (m_PageIndex < 0)
  92. m_PageIndex = (int)FPDFDest_GetPageIndex(m_Document.NativePointer, m_NativePointer);
  93. return m_PageIndex;
  94. }
  95. }
  96. #region NATIVE
  97. [DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  98. private static extern uint FPDFDest_GetPageIndex(IntPtr document, IntPtr dest);
  99. #endregion
  100. }
  101. #endif
  102. }