PDFLink.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 the annotation link in a PDF page.
  16. /// </summary>
  17. public class PDFLink : IDisposable
  18. {
  19. private bool m_Disposed;
  20. private IntPtr m_NativePointer;
  21. private PDFPage m_Page;
  22. public PDFLink(PDFPage page, IntPtr nativePointer)
  23. {
  24. if (page == null)
  25. throw new NullReferenceException();
  26. if (nativePointer == IntPtr.Zero)
  27. throw new NullReferenceException();
  28. PDFLibrary.AddRef("PDFLink");
  29. m_Page = page;
  30. m_NativePointer = nativePointer;
  31. }
  32. ~PDFLink()
  33. {
  34. Dispose(false);
  35. }
  36. public void Dispose()
  37. {
  38. Dispose(true);
  39. GC.SuppressFinalize(this);
  40. }
  41. protected virtual void Dispose(bool disposing)
  42. {
  43. if (!m_Disposed)
  44. {
  45. m_NativePointer = IntPtr.Zero;
  46. PDFLibrary.RemoveRef("PDFLink");
  47. m_Disposed = true;
  48. }
  49. }
  50. public PDFPage Page
  51. {
  52. get { return m_Page; }
  53. }
  54. public IntPtr NativePointer
  55. {
  56. get { return m_NativePointer; }
  57. }
  58. /// <summary>
  59. /// Gets the named destination assigned to a link. Return null if there is no destination associated with the link,
  60. /// in this case the application should try GetAction() instead.
  61. /// </summary>
  62. /// <returns></returns>
  63. public PDFDest GetDest()
  64. {
  65. IntPtr destPtr = FPDFLink_GetDest(m_Page.Document.NativePointer, m_NativePointer);
  66. if (destPtr != IntPtr.Zero)
  67. return new PDFDest(this, destPtr);
  68. return null;
  69. }
  70. /// <summary>
  71. /// Gets the PDF action assigned to a link.
  72. /// </summary>
  73. /// <returns></returns>
  74. public PDFAction GetAction()
  75. {
  76. IntPtr actionPtr = FPDFLink_GetAction(m_NativePointer);
  77. if (actionPtr != IntPtr.Zero)
  78. return new PDFAction(this, actionPtr);
  79. return null;
  80. }
  81. #region NATIVE
  82. [DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  83. private static extern IntPtr FPDFLink_GetAction(IntPtr link);
  84. [DllImport(PDFLibrary.PLUGIN_ASSEMBLY)]
  85. private static extern IntPtr FPDFLink_GetDest(IntPtr document, IntPtr link);
  86. #endregion
  87. }
  88. #endif
  89. }