CPDFViewerTool.CreateWidget.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFAnnotation.Form;
  4. using ComPDFKit.PDFDocument;
  5. using ComPDFKit.PDFPage;
  6. using ComPDFKit.Tool.DrawTool;
  7. using ComPDFKitViewer.BaseObject;
  8. using ComPDFKitViewer.Helper;
  9. using ComPDFKitViewer.Layer;
  10. using ComPDFKitViewer.Widget;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Input;
  18. namespace ComPDFKit.Tool
  19. {
  20. public partial class CPDFViewerTool
  21. {
  22. BaseWidget cacheMoveWidget;
  23. int createWidgetTag = -1;
  24. public BaseWidget GetCacheHitTestWidget()
  25. {
  26. return cacheMoveWidget;
  27. }
  28. private void InsertWidgetView()
  29. {
  30. CreateWidgetTool createAnnotTool = new CreateWidgetTool();
  31. int annotViewindex = PDFViewer.GetMaxViewIndex();
  32. PDFViewer.InsertView(annotViewindex, createAnnotTool);
  33. createWidgetTag = createAnnotTool.GetResTag();
  34. }
  35. protected bool AnnotWidgetHitTest()
  36. {
  37. BaseAnnot baseAnnot = PDFViewer.AnnotHitTest();
  38. if (baseAnnot != null)
  39. {
  40. if ((baseAnnot as BaseWidget) != null)
  41. {
  42. cacheMoveWidget = baseAnnot as BaseWidget;
  43. return true;
  44. }
  45. }
  46. cacheMoveWidget = null;
  47. return false;
  48. }
  49. public CPDFAnnotation StartDrawWidget(C_WIDGET_TYPE WidgetType)
  50. {
  51. Point point = Mouse.GetPosition(this);
  52. BaseLayer baseLayer = PDFViewer.GetViewForTag(createWidgetTag);
  53. PDFViewer.GetPointPageInfo(point, out int index, out Rect paintRect, out Rect pageBound);
  54. if (index < 0)
  55. {
  56. return null;
  57. }
  58. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  59. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  60. Point cropPoint = new Point();
  61. if (PDFViewer.GetIsCrop())
  62. {
  63. CRect cRect = cPDFPage.GetCropBounds();
  64. cropPoint.X = DpiHelper.PDFNumToStandardNum(cRect.left);
  65. cropPoint.Y = DpiHelper.PDFNumToStandardNum(cRect.top);
  66. }
  67. return (baseLayer as CreateWidgetTool).StartDraw(point, cropPoint, cPDFPage, paintRect, pageBound, WidgetType);
  68. }
  69. public void SetDrawWidgetType(C_WIDGET_TYPE WidgetType)
  70. {
  71. Point point = Mouse.GetPosition(this);
  72. BaseLayer baseLayer = PDFViewer.GetViewForTag(createWidgetTag);
  73. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  74. (baseLayer as CreateWidgetTool).SetDrawType(WidgetType);
  75. }
  76. /// <summary>
  77. /// Widget move in create mode
  78. /// </summary>
  79. /// <param name="Hide">
  80. /// Identify whether the default size style of the widget form is displayed
  81. /// </param>
  82. public void MoveDrawWidget(bool Hide)
  83. {
  84. Point point = Mouse.GetPosition(this);
  85. BaseLayer baseLayer = PDFViewer.GetViewForTag(createWidgetTag);
  86. PDFViewer.GetPointPageInfo(point, out int index, out Rect paintRect, out Rect pageBound);
  87. (baseLayer as CreateWidgetTool).MoveDraw(point, PDFViewer.GetZoom(), PDFViewer.ActualWidth, PDFViewer.ActualHeight, Hide, paintRect);
  88. }
  89. public Rect EndDrawWidget()
  90. {
  91. Point point = Mouse.GetPosition(this);
  92. BaseLayer baseLayer = PDFViewer.GetViewForTag(createWidgetTag);
  93. return (baseLayer as CreateWidgetTool).EndDraw();
  94. }
  95. public void ClearDrawWidget()
  96. {
  97. Point point = Mouse.GetPosition(this);
  98. BaseLayer baseLayer = PDFViewer.GetViewForTag(createWidgetTag);
  99. if (baseLayer is CreateWidgetTool)
  100. {
  101. (baseLayer as CreateWidgetTool).ClearDraw();
  102. (baseLayer as CreateWidgetTool).SetDrawType(C_WIDGET_TYPE.WIDGET_NONE);
  103. }
  104. }
  105. public void ReDrawWidget()
  106. {
  107. Point point = Mouse.GetPosition(this);
  108. BaseLayer baseLayer = PDFViewer.GetViewForTag(createWidgetTag);
  109. if (baseLayer is CreateWidgetTool)
  110. {
  111. (baseLayer as CreateWidgetTool).ReDrawWidget(PDFViewer.GetZoom());
  112. }
  113. }
  114. }
  115. }