CPDFViewerTool.SelectImage.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using ComPDFKit.Tool.DrawTool;
  2. using ComPDFKitViewer.Helper;
  3. using ComPDFKitViewer.Layer;
  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;
  10. namespace ComPDFKit.Tool
  11. {
  12. public partial class CPDFViewerTool
  13. {
  14. int selectImageTag = -1;
  15. private bool enableImageSelect = true;
  16. private void InsertSelectImageView()
  17. {
  18. SelectImage createAnnotTool = new SelectImage();
  19. int SelectTextindex = PDFViewer.GetMaxViewIndex();
  20. PDFViewer.InsertView(SelectTextindex, createAnnotTool);
  21. selectImageTag = createAnnotTool.GetResTag();
  22. }
  23. public void SetImageSelectEnable(bool enable)
  24. {
  25. enableImageSelect=enable;
  26. if (enableImageSelect==false && PDFViewer!=null)
  27. {
  28. SelectImage imageLayer = PDFViewer.GetViewForTag(selectImageTag) as SelectImage;
  29. if (imageLayer != null)
  30. {
  31. imageLayer.CleanDraw(PDFViewer);
  32. }
  33. }
  34. }
  35. public bool DrawMoveSelectImage()
  36. {
  37. bool isSelect = false;
  38. if (PDFViewer.CurrentRenderFrame == null || enableImageSelect == false)
  39. {
  40. return isSelect;
  41. }
  42. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectImageTag);
  43. PDFViewer.GetMousePointToPage(out int pageindex, out Point pagepoint);
  44. isSelect=(baseLayer as SelectImage).ProcessMouseMoveForSelectImage(
  45. new Point(DpiHelper.StandardNumToPDFNum(pagepoint.X / PDFViewer.CurrentRenderFrame.ZoomFactor),
  46. DpiHelper.StandardNumToPDFNum(pagepoint.Y / PDFViewer.CurrentRenderFrame.ZoomFactor)),
  47. pageindex, PDFViewer);
  48. (baseLayer as SelectImage).Draw(PDFViewer);
  49. return isSelect;
  50. }
  51. public bool DrawDownSelectImage(bool isNeedClear)
  52. {
  53. bool isSelect = false;
  54. if (PDFViewer.CurrentRenderFrame == null || enableImageSelect == false)
  55. {
  56. return isSelect;
  57. }
  58. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectImageTag);
  59. PDFViewer.GetMousePointToPage(out int pageindex, out Point pagepoint);
  60. isSelect=(baseLayer as SelectImage).ProcessMouseDownForSelectImage(
  61. new Point(DpiHelper.StandardNumToPDFNum(pagepoint.X / PDFViewer.CurrentRenderFrame.ZoomFactor),
  62. DpiHelper.StandardNumToPDFNum(pagepoint.Y / PDFViewer.CurrentRenderFrame.ZoomFactor)),
  63. pageindex, PDFViewer, isNeedClear);
  64. (baseLayer as SelectImage).Draw(PDFViewer);
  65. return isSelect;
  66. }
  67. public void ReDrawSelectImage()
  68. {
  69. if(enableImageSelect == false)
  70. {
  71. return;
  72. }
  73. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectImageTag);
  74. (baseLayer as SelectImage).Draw(PDFViewer);
  75. }
  76. public void CleanDrawSelectImage()
  77. {
  78. if (enableImageSelect == false)
  79. {
  80. return;
  81. }
  82. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectImageTag);
  83. (baseLayer as SelectImage).CleanDraw(PDFViewer);
  84. }
  85. //public PageImageItem GetSelectImage()
  86. //{
  87. // BaseLayer baseLayer = PDFViewer.GetViewForTag(selectImageTag);
  88. // return (baseLayer as SelectImage).GetHoverImageItem();
  89. //}
  90. public Dictionary<int, List<PageImageItem>> GetSelectImageItems()
  91. {
  92. if (enableImageSelect == false)
  93. {
  94. return new Dictionary<int, List<PageImageItem>>();
  95. }
  96. BaseLayer baseLayer = PDFViewer.GetViewForTag(selectImageTag);
  97. return (baseLayer as SelectImage).GetSelectImageItems();
  98. }
  99. }
  100. }