PDFDest.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using Paroxe.PdfRenderer.Internal;
  3. namespace Paroxe.PdfRenderer
  4. {
  5. #if !UNITY_WEBGL
  6. /// <summary>
  7. /// Represents a destination into a PDF document.
  8. /// </summary>
  9. public class PDFDest : IDisposable
  10. {
  11. private bool m_Disposed;
  12. private IntPtr m_NativePointer;
  13. private IDisposable m_Source;
  14. private PDFDocument m_Document;
  15. private int m_PageIndex = -1;
  16. public PDFDest(PDFAction action, IntPtr nativePointer)
  17. {
  18. if (action == null)
  19. throw new NullReferenceException();
  20. if (nativePointer == IntPtr.Zero)
  21. throw new NullReferenceException();
  22. PDFLibrary.AddRef("PDFDest");
  23. m_Source = action;
  24. m_Document = action.Document;
  25. m_NativePointer = nativePointer;
  26. }
  27. public PDFDest(PDFLink link, IntPtr nativePointer)
  28. {
  29. if (link == null)
  30. throw new NullReferenceException();
  31. if (nativePointer == IntPtr.Zero)
  32. throw new NullReferenceException();
  33. PDFLibrary.AddRef("PDFDest");
  34. m_Source = link;
  35. m_Document = link.Page.Document;
  36. m_NativePointer = nativePointer;
  37. }
  38. public PDFDest(PDFBookmark bookmark, IntPtr nativePointer)
  39. {
  40. if (bookmark == null)
  41. throw new NullReferenceException();
  42. if (nativePointer == IntPtr.Zero)
  43. throw new NullReferenceException();
  44. PDFLibrary.AddRef("PDFDest");
  45. m_Source = bookmark;
  46. m_Document = bookmark.Document;
  47. m_NativePointer = nativePointer;
  48. }
  49. ~PDFDest()
  50. {
  51. Dispose(false);
  52. }
  53. public void Dispose()
  54. {
  55. Dispose(true);
  56. GC.SuppressFinalize(this);
  57. }
  58. protected virtual void Dispose(bool disposing)
  59. {
  60. if (!m_Disposed)
  61. {
  62. m_NativePointer = IntPtr.Zero;
  63. PDFLibrary.RemoveRef("PDFDest");
  64. m_Disposed = true;
  65. }
  66. }
  67. public PDFDocument Document
  68. {
  69. get { return m_Document; }
  70. }
  71. public IDisposable Source
  72. {
  73. get { return m_Source; }
  74. }
  75. public IntPtr NativePointer
  76. {
  77. get { return m_NativePointer; }
  78. }
  79. public int PageIndex
  80. {
  81. get
  82. {
  83. if (m_PageIndex < 0)
  84. m_PageIndex = (int)NativeMethods.FPDFDest_GetDestPageIndex(m_Document.NativePointer, m_NativePointer);
  85. return m_PageIndex;
  86. }
  87. }
  88. }
  89. #endif
  90. }