CPDFViewerTool.CustomizeTool.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. (baseLayer as CreateCustomizeTool).ErasePageIndex = -1;
  67. if (ToolType == CustomizeToolType.kErase)
  68. {
  69. (baseLayer as CreateCustomizeTool).SetAnnotLayer(layer as AnnotLayer);
  70. (baseLayer as CreateCustomizeTool).ErasePageIndex = index;
  71. }
  72. (baseLayer as CreateCustomizeTool).StartDraw(point, cPDFPage, paintRect, pageBound, ToolType);
  73. }
  74. /// <summary>
  75. /// Custom tool move call
  76. /// </summary>
  77. public void DrawMoveCustomizeTool()
  78. {
  79. if (UnCheckCustomizeToolViewerModel())
  80. {
  81. return;
  82. }
  83. Point point = Mouse.GetPosition(this);
  84. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  85. (baseLayer as CreateCustomizeTool).MoveDraw(point, PDFViewer.GetZoom());
  86. }
  87. /// <summary>
  88. /// Custom tool end call
  89. /// </summary>
  90. public void DrawEndCustomizeTool()
  91. {
  92. if (UnCheckCustomizeToolViewerModel())
  93. {
  94. return;
  95. }
  96. Point point = Mouse.GetPosition(this);
  97. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  98. (baseLayer as CreateCustomizeTool).EndDraw();
  99. return;
  100. }
  101. /// <summary>
  102. /// Clear the custom tool
  103. /// </summary>
  104. public void CleanCustomizeTool()
  105. {
  106. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  107. (baseLayer as CreateCustomizeTool).ClearDraw();
  108. }
  109. /// <summary>
  110. /// Set the thickness of the custom tool
  111. /// </summary>
  112. public void SetEraseZoom(double eraseZoom)
  113. {
  114. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  115. (baseLayer as CreateCustomizeTool)?.SetEraseZoom(eraseZoom);
  116. }
  117. /// <summary>
  118. /// Clear the custom tool
  119. /// </summary>
  120. public void SetDefEraseThickness(double defEraseThickness)
  121. {
  122. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  123. (baseLayer as CreateCustomizeTool)?.SetDefEraseThickness(defEraseThickness);
  124. }
  125. /// <summary>
  126. /// Clear the custom tool
  127. /// </summary>
  128. public void SetEraseBrush(SolidColorBrush drawBrush)
  129. {
  130. if(PDFViewer!=null)
  131. {
  132. BaseLayer baseLayer = PDFViewer.GetViewForTag(customizeToolViewTag);
  133. (baseLayer as CreateCustomizeTool)?.SetEraseBrush(drawBrush);
  134. }
  135. }
  136. }
  137. }