AnnotTransfer.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
  17. public event EventHandler<Dictionary<AnnotArgsType, object>> AnnotTypeChanged;
  18. public bool IsAddLink = false;
  19. public bool IsLocationLink = false;
  20. public AnnotAttribEvent AnnotEvent { get; set; }
  21. public List<AnnotAttribEvent> AnnotEvents = new List<AnnotAttribEvent>();
  22. public AnnotHandlerEventArgs annot;
  23. public List<AnnotHandlerEventArgs> annotlists;
  24. //是否为填写与签名的日期文本
  25. public bool IsTextFill { get; private set; }
  26. public void SetIsTextFill(bool isTextFill)
  27. {
  28. IsTextFill = isTextFill;
  29. }
  30. public bool IsMultiSelected
  31. { get { return (annotlists != null && annotlists.Count > 1); } }
  32. public AnnotTransfer()
  33. {
  34. }
  35. #region 静态
  36. //是否为形状注释
  37. public static bool IsShapAnnot(AnnotHandlerEventArgs annot)
  38. {
  39. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  40. annot.EventType == AnnotArgsType.AnnotSquare ||
  41. annot.EventType == AnnotArgsType.AnnotLine
  42. )
  43. {
  44. return true;
  45. }
  46. else
  47. {
  48. return false;
  49. }
  50. }
  51. //是否为高亮注释
  52. public static bool IsHightAnnot(AnnotHandlerEventArgs annot)
  53. {
  54. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  55. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  56. annot.EventType == AnnotArgsType.AnnotHighlight ||
  57. annot.EventType == AnnotArgsType.AnnotStrikeout
  58. )
  59. {
  60. return true;
  61. }
  62. else
  63. {
  64. return false;
  65. }
  66. }
  67. //判断注释列表是否有不同种类的注释
  68. public static bool IsDifferentTypeAnnots(List<AnnotHandlerEventArgs> annotlists)
  69. {
  70. //如高亮、下划线、删除线,是属于同一种类的注释
  71. bool isDifferentAnnotTyle = false;
  72. var annot = annotlists[0];
  73. var lastAnnot = annot;
  74. foreach (var item in annotlists)
  75. {
  76. if (lastAnnot.EventType != item.EventType)
  77. {
  78. if ((AnnotTransfer.IsShapAnnot(annot) == true && AnnotTransfer.IsShapAnnot(item) == true) || (AnnotTransfer.IsHightAnnot(annot) == true && AnnotTransfer.IsHightAnnot(item) == true))
  79. {
  80. lastAnnot = item;
  81. continue;
  82. }
  83. lastAnnot = item;
  84. isDifferentAnnotTyle = true;
  85. break;
  86. }
  87. }
  88. return isDifferentAnnotTyle;
  89. }
  90. //外部UI控件选中状态
  91. public static bool IsSolidStyle(DashStyle LineDash)
  92. {
  93. bool isSolid = true;
  94. if (LineDash == null || LineDash.Dashes.Count == 0)
  95. {
  96. return isSolid;
  97. }
  98. foreach (var item in LineDash.Dashes)
  99. {
  100. if (item > 0)
  101. {
  102. isSolid = false;
  103. break;
  104. }
  105. }
  106. return isSolid;
  107. }
  108. public static DashStyle GetLineDashStyle(bool isSolid)
  109. {
  110. DashStyle newDash = new DashStyle();
  111. if (isSolid == false)
  112. {
  113. newDash.Dashes.Add(2);
  114. newDash.Dashes.Add(2);
  115. }
  116. else
  117. {
  118. newDash = DashStyles.Solid;
  119. }
  120. return newDash;
  121. }
  122. #endregion 静态
  123. //单个属性更改
  124. public void UpdateAnnotAAttrib(AnnotAttrib annotAttrib, object obj)
  125. {
  126. if (annotlists != null && annotlists.Count > 1)
  127. {
  128. foreach (var itemevent in AnnotEvents)
  129. {
  130. itemevent?.UpdateAttrib(annotAttrib, obj);
  131. itemevent?.UpdateAnnot();
  132. }
  133. }
  134. else
  135. {
  136. AnnotEvent?.UpdateAttrib(annotAttrib, obj);
  137. AnnotEvent?.UpdateAnnot();
  138. }
  139. }
  140. //多个属性更改
  141. public void UpdateAnnotAllAttribs(Dictionary<AnnotAttrib, object> AnnotAttribDir)
  142. {
  143. if (annotlists != null && annotlists.Count > 1)
  144. {
  145. foreach (var itemevent in AnnotEvents)
  146. {
  147. foreach (var item in AnnotAttribDir)
  148. {
  149. itemevent?.UpdateAttrib(item.Key, item.Value);
  150. }
  151. itemevent?.UpdateAnnot();
  152. }
  153. }
  154. else
  155. {
  156. foreach (var item in AnnotAttribDir)
  157. {
  158. AnnotEvent?.UpdateAttrib(item.Key, item.Value);
  159. }
  160. AnnotEvent?.UpdateAnnot();
  161. }
  162. }
  163. //是否为多选
  164. #region Invoke
  165. /// <summary>
  166. /// 更新多个属性,触发到工具栏注释工具,改变工具图标下的颜色值
  167. /// </summary>
  168. public void InvokeToMyTools(object sender, Dictionary<AnnotArgsType, object> keyValues)
  169. {
  170. DataChanged?.Invoke(sender, keyValues);
  171. }
  172. /// <summary>
  173. /// 更新单个属性
  174. /// </summary>
  175. public void InvokeToMyTools(AnnotArgsType argsType, object obj)
  176. {
  177. Dictionary<AnnotArgsType, object> changeData = new Dictionary<AnnotArgsType, object>();
  178. changeData[argsType] = obj;
  179. DataChanged?.Invoke(null, changeData);
  180. }
  181. //同一属性面板,切换注释工具
  182. public void AnnotTypeChangedInvoke(object sender, Dictionary<AnnotArgsType, object> keyValues)
  183. {
  184. AnnotTypeChanged?.Invoke(sender, keyValues);
  185. }
  186. #endregion Invoke
  187. }
  188. }