AnnotTransfer.cs 7.8 KB

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