AnnotTransfer.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Media;
  9. namespace PDF_Office.ViewModels.Tools.AnnotManager
  10. {
  11. /// <summary>
  12. /// 注释面板与外部(如注释工具)关联
  13. /// </summary>
  14. public class AnnotTransfer
  15. {
  16. public bool IsAddLink = false;
  17. public bool IsLocationLink = false;
  18. public AnnotAttribEvent AnnotEvent { get; set; }
  19. public List<AnnotAttribEvent> AnnotEvents = new List<AnnotAttribEvent>();
  20. public AnnotHandlerEventArgs annot;
  21. public List<AnnotHandlerEventArgs> annotlists;
  22. public bool IsTextFill { get; private set; }
  23. public void SetIsTextFill(bool isTextFill)
  24. {
  25. IsTextFill = isTextFill;
  26. }
  27. public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
  28. public event EventHandler<Dictionary<AnnotArgsType, object>> AnnotTypeChanged;
  29. public event EventHandler<object> DefaultStored;
  30. public AnnotTransfer()
  31. {
  32. }
  33. //外部UI控件选中状态
  34. public static bool IsSolidStyle(DashStyle LineDash)
  35. {
  36. bool isSolid = true;
  37. if (LineDash == null || LineDash.Dashes.Count == 0)
  38. {
  39. return isSolid;
  40. }
  41. foreach (var item in LineDash.Dashes)
  42. {
  43. if (item > 0)
  44. {
  45. isSolid = false;
  46. break;
  47. }
  48. }
  49. return isSolid;
  50. }
  51. public static DashStyle GetLineDashStyle(bool isSolid)
  52. {
  53. DashStyle newDash = new DashStyle();
  54. if (isSolid == false)
  55. {
  56. newDash.Dashes.Add(2);
  57. newDash.Dashes.Add(2);
  58. }
  59. else
  60. {
  61. newDash = DashStyles.Solid;
  62. }
  63. return newDash;
  64. }
  65. //单个属性更改
  66. public void UpdateAnnotAAttrib(AnnotAttrib annotAttrib, object obj)
  67. {
  68. if (annotlists != null && annotlists.Count > 1)
  69. {
  70. foreach (var itemevent in AnnotEvents)
  71. {
  72. itemevent?.UpdateAttrib(annotAttrib, obj);
  73. itemevent?.UpdateAnnot();
  74. }
  75. }
  76. else
  77. {
  78. AnnotEvent?.UpdateAttrib(annotAttrib, obj);
  79. AnnotEvent?.UpdateAnnot();
  80. }
  81. }
  82. //多个属性更改
  83. public void UpdateAnnotAllAttribs(Dictionary<AnnotAttrib, object> AnnotAttribDir)
  84. {
  85. if (annotlists != null && annotlists.Count > 1)
  86. {
  87. foreach (var itemevent in AnnotEvents)
  88. {
  89. foreach (var item in AnnotAttribDir)
  90. {
  91. itemevent?.UpdateAttrib(item.Key, item.Value);
  92. }
  93. itemevent?.UpdateAnnot();
  94. }
  95. }
  96. else
  97. {
  98. foreach (var item in AnnotAttribDir)
  99. {
  100. AnnotEvent?.UpdateAttrib(item.Key, item.Value);
  101. }
  102. AnnotEvent?.UpdateAnnot();
  103. }
  104. }
  105. //是否为多选
  106. public bool IsMultiSelected
  107. { get { return (annotlists != null && annotlists.Count > 1); } }
  108. /// <summary>
  109. /// 更新多个属性,触发到工具栏注释工具,改变工具图标下的颜色值
  110. /// </summary>
  111. public void InvokeToMyTools(object sender, Dictionary<AnnotArgsType, object> keyValues)
  112. {
  113. DataChanged?.Invoke(sender, keyValues);
  114. }
  115. /// <summary>
  116. /// 更新单个属性
  117. /// </summary>
  118. public void InvokeToMyTools(AnnotArgsType argsType, object obj)
  119. {
  120. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  121. changeData[argsType] = obj;
  122. DataChanged?.Invoke(null, changeData);
  123. }
  124. //同一属性面板,切换注释工具
  125. public void AnnotTypeChangedInvoke(object sender, Dictionary<AnnotArgsType, object> keyValues)
  126. {
  127. AnnotTypeChanged?.Invoke(sender, keyValues);
  128. }
  129. }
  130. }