PDFActionHandlerHelper.cs 3.9 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.IO;
  10. namespace Paroxe.PdfRenderer
  11. {
  12. #if !UNITY_WEBGL
  13. /// <summary>
  14. /// Provides default action handling implementation.
  15. /// </summary>
  16. public static class PDFActionHandlerHelper
  17. {
  18. public static void ExecuteAction(IPDFDeviceActionHandler actionHandler, IPDFDevice device, PDFAction action)
  19. {
  20. if (action != null)
  21. {
  22. PDFAction.ActionType type = action.GetActionType();
  23. switch (type)
  24. {
  25. case PDFAction.ActionType.Unsupported:
  26. break;
  27. case PDFAction.ActionType.GoTo:
  28. PDFDest dest = action.GetDest();
  29. actionHandler.HandleGotoAction(device, dest.PageIndex);
  30. break;
  31. case PDFAction.ActionType.RemoteGoTo:
  32. string resolvedFilePath = actionHandler.HandleRemoteGotoActionPathResolving(device,
  33. action.GetFilePath());
  34. #if !((UNITY_4_6 || UNITY_4_7) && UNITY_WINRT)
  35. if (File.Exists(resolvedFilePath))
  36. {
  37. string password = actionHandler.HandleRemoteGotoActionPasswordResolving(device,
  38. resolvedFilePath);
  39. PDFDocument newDocument = new PDFDocument(resolvedFilePath, password);
  40. if (newDocument.IsValid)
  41. actionHandler.HandleRemoteGotoActionResolved(device, newDocument,
  42. action.GetDest().PageIndex);
  43. else
  44. actionHandler.HandleRemoteGotoActionUnresolved(device, resolvedFilePath);
  45. }
  46. else
  47. #endif
  48. actionHandler.HandleRemoteGotoActionUnresolved(device, resolvedFilePath);
  49. break;
  50. case PDFAction.ActionType.Uri:
  51. actionHandler.HandleUriAction(device, action.GetURIPath());
  52. break;
  53. case PDFAction.ActionType.Launch:
  54. actionHandler.HandleLaunchAction(device, action.GetFilePath());
  55. break;
  56. }
  57. }
  58. }
  59. public static void ExecuteBookmarkAction(IPDFDevice device, PDFBookmark bookmark)
  60. {
  61. if (device.BookmarksActionHandler != null)
  62. {
  63. PDFDest dest = bookmark.GetDest();
  64. if (dest != null)
  65. {
  66. device.BookmarksActionHandler.HandleGotoAction(device, dest.PageIndex);
  67. }
  68. else
  69. {
  70. PDFAction action = bookmark.GetAction();
  71. if (action != null)
  72. ExecuteAction(device.BookmarksActionHandler, device, action);
  73. }
  74. }
  75. }
  76. public static void ExecuteLinkAction(IPDFDevice device, PDFLink link)
  77. {
  78. if (device.LinksActionHandler != null)
  79. {
  80. PDFDest dest = link.GetDest();
  81. if (dest != null)
  82. {
  83. device.LinksActionHandler.HandleGotoAction(device, dest.PageIndex);
  84. }
  85. else
  86. {
  87. PDFAction action = link.GetAction();
  88. if (action != null)
  89. ExecuteAction(device.LinksActionHandler, device, action);
  90. }
  91. }
  92. }
  93. }
  94. #endif
  95. }