CPDFViewerTool.CreateWidget.cs 4.2 KB

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