PDFLink.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using Paroxe.PdfRenderer.Internal;
  3. namespace Paroxe.PdfRenderer
  4. {
  5. #if !UNITY_WEBGL
  6. /// <summary>
  7. /// Represents the annotation link in a PDF page.
  8. /// </summary>
  9. public class PDFLink : IDisposable
  10. {
  11. private bool m_Disposed;
  12. private IntPtr m_NativePointer;
  13. private PDFPage m_Page;
  14. public PDFLink(PDFPage page, IntPtr nativePointer)
  15. {
  16. if (page == null)
  17. throw new NullReferenceException();
  18. if (nativePointer == IntPtr.Zero)
  19. throw new NullReferenceException();
  20. PDFLibrary.AddRef("PDFLink");
  21. m_Page = page;
  22. m_NativePointer = nativePointer;
  23. }
  24. ~PDFLink()
  25. {
  26. Dispose(false);
  27. }
  28. public void Dispose()
  29. {
  30. Dispose(true);
  31. GC.SuppressFinalize(this);
  32. }
  33. protected virtual void Dispose(bool disposing)
  34. {
  35. if (!m_Disposed)
  36. {
  37. m_NativePointer = IntPtr.Zero;
  38. PDFLibrary.RemoveRef("PDFLink");
  39. m_Disposed = true;
  40. }
  41. }
  42. public PDFPage Page
  43. {
  44. get { return m_Page; }
  45. }
  46. public IntPtr NativePointer
  47. {
  48. get { return m_NativePointer; }
  49. }
  50. /// <summary>
  51. /// Gets the named destination assigned to a link. Return null if there is no destination associated with the link,
  52. /// in this case the application should try GetAction() instead.
  53. /// </summary>
  54. /// <returns></returns>
  55. public PDFDest GetDest()
  56. {
  57. IntPtr destPtr = NativeMethods.FPDFLink_GetDest(m_Page.Document.NativePointer, m_NativePointer);
  58. if (destPtr != IntPtr.Zero)
  59. return new PDFDest(this, destPtr);
  60. return null;
  61. }
  62. /// <summary>
  63. /// Gets the PDF action assigned to a link.
  64. /// </summary>
  65. /// <returns></returns>
  66. public PDFAction GetAction()
  67. {
  68. IntPtr actionPtr = NativeMethods.FPDFLink_GetAction(m_NativePointer);
  69. if (actionPtr != IntPtr.Zero)
  70. return new PDFAction(this, actionPtr);
  71. return null;
  72. }
  73. }
  74. #endif
  75. }