CPDFViewerTool.CustomizeTool.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using ComPDFKit.Tool.DrawTool;
  2. using ComPDFKitViewer.Layer;
  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.Input;
  9. using System.Windows;
  10. using ComPDFKit.PDFAnnotation;
  11. using ComPDFKit.PDFPage;
  12. using ComPDFKit.PDFDocument;
  13. using ComPDFKitViewer.BaseObject;
  14. using ComPDFKit.PDFAnnotation.Form;
  15. using System.Windows.Media;
  16. namespace ComPDFKit.Tool
  17. {
  18. public partial class CPDFViewerTool
  19. {
  20. /// <summary>
  21. ///Identity whether to draw the custom tool
  22. /// </summary>
  23. protected bool isDrawAnnot { get; set; }
  24. public event EventHandler<List<AnnotParam>> DeleteChanged;
  25. int customizeToolViewTag = -1;
  26. private bool UnCheckCustomizeToolViewerModel()
  27. {
  28. if (currentModel == ToolType.Customize)
  29. {
  30. return false;
  31. }
  32. return true;
  33. }
  34. private void InsertCustomizeToolView()
  35. {
  36. CreateCustomizeTool createAnnotTool = new CreateCustomizeTool();
  37. createAnnotTool.PDFViewer = PDFViewer;
  38. int customizeToolViewindex = PDFViewer.GetMaxViewIndex();
  39. createAnnotTool.DeleteChanged += CreateAnnotTool_DeleteChanged;
  40. PDFViewer.InsertView(customizeToolViewindex, createAnnotTool);
  41. customizeToolViewTag= createAnnotTool.GetResTag();
  42. }
  43. private void CreateAnnotTool_DeleteChanged(object sender, List<AnnotParam> e)
  44. {
  45. DeleteChanged?.Invoke(this, e);
  46. }
  47. /// <summary>
  48. /// Begin to draw the custom tool
  49. /// </summary>
  50. public void DrawStartCustomizeTool(CustomizeToolType ToolType)
  51. {
  52. if (UnCheckCustomizeToolViewerModel())
  53. {
  54. return;
  55. }
  56. Point point = Mouse.GetPosition(this);
  57. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  58. PDFViewer.GetPointPageInfo(point, out int index, out Rect paintRect, out Rect pageBound);
  59. if (index < 0)
  60. {
  61. return;
  62. }
  63. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  64. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  65. BaseLayer layer = PDFViewer.GetViewForTag(PDFViewer.GetAnnotViewTag());
  66. if (ToolType == CustomizeToolType.kErase)
  67. {
  68. (baseLayer as CreateCustomizeTool).SetAnnotLayer(layer as AnnotLayer);
  69. }
  70. (baseLayer as CreateCustomizeTool).StartDraw(point, cPDFPage, paintRect, pageBound, ToolType);
  71. }
  72. /// <summary>
  73. /// Custom tool move call
  74. /// </summary>
  75. public void DrawMoveCustomizeTool()
  76. {
  77. if (UnCheckCustomizeToolViewerModel())
  78. {
  79. return;
  80. }
  81. Point point = Mouse.GetPosition(this);
  82. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  83. (baseLayer as CreateCustomizeTool).MoveDraw(point, PDFViewer.GetZoom());
  84. }
  85. /// <summary>
  86. /// Custom tool end call
  87. /// </summary>
  88. public void DrawEndCustomizeTool()
  89. {
  90. if (UnCheckCustomizeToolViewerModel())
  91. {
  92. return;
  93. }
  94. Point point = Mouse.GetPosition(this);
  95. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  96. (baseLayer as CreateCustomizeTool).EndDraw();
  97. return;
  98. }
  99. /// <summary>
  100. /// Clear the custom tool
  101. /// </summary>
  102. public void CleanCustomizeTool()
  103. {
  104. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  105. (baseLayer as CreateCustomizeTool).ClearDraw();
  106. }
  107. /// <summary>
  108. /// Set the thickness of the custom tool
  109. /// </summary>
  110. public void SetEraseZoom(double eraseZoom)
  111. {
  112. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  113. (baseLayer as CreateCustomizeTool)?.SetEraseZoom(eraseZoom);
  114. }
  115. /// <summary>
  116. /// Clear the custom tool
  117. /// </summary>
  118. public void SetDefEraseThickness(double defEraseThickness)
  119. {
  120. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  121. (baseLayer as CreateCustomizeTool)?.SetDefEraseThickness(defEraseThickness);
  122. }
  123. /// <summary>
  124. /// Clear the custom tool
  125. /// </summary>
  126. public void SetEraseBrush(SolidColorBrush drawBrush)
  127. {
  128. if(PDFViewer!=null)
  129. {
  130. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  131. (baseLayer as CreateCustomizeTool)?.SetEraseBrush(drawBrush);
  132. }
  133. }
  134. }
  135. }