SelectedRect.protected.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Windows.Media;
  5. namespace ComPDFKit.Tool.DrawTool
  6. {
  7. public partial class SelectedRect
  8. {
  9. #region Properties
  10. /// <summary>
  11. /// Current control point drawing style.
  12. /// </summary>
  13. protected DrawPointType currentDrawPointType { get; set; }
  14. /// <summary>
  15. /// Current drag drawing style.
  16. /// </summary>
  17. protected DrawMoveType currentDrawMoveType { get; set; }
  18. /// <summary>
  19. /// Current click hit control point.
  20. /// </summary>
  21. protected PointControlType hitControlType { get; set; }
  22. /// <summary>
  23. /// Mouse down position information.
  24. /// </summary>
  25. protected Point mouseDownPoint { get; set; }
  26. /// <summary>
  27. /// Whether the mouse is pressed.
  28. /// </summary>
  29. protected bool isMouseDown { get; set; }
  30. /// <summary>
  31. /// Whether proportional scaling is required.
  32. /// </summary>
  33. protected bool isProportionalScaling { get; set; } = false;
  34. /// <summary>
  35. /// Current control point size.
  36. /// </summary>
  37. protected int pointSize { get; set; } = 4;
  38. /// <summary>
  39. /// Rectangular minimum width.
  40. /// </summary>
  41. protected int rectMinWidth { get; set; } = 10;
  42. /// <summary>
  43. /// Rectangular minimum height.
  44. /// </summary>
  45. protected int RectMinHeight { get; set; } = 10;
  46. /// <summary>
  47. /// Current set of ignore points.
  48. /// </summary>
  49. protected List<PointControlType> ignorePoints { get; set; } = new List<PointControlType>();
  50. /// <summary>
  51. /// Current set of drawing rectangles (original data).
  52. /// </summary>
  53. protected Rect SetDrawRect { get; set; } = new Rect(0, 0, 0, 0);
  54. /// <summary>
  55. /// Current drawing rectangle (calculated during operation).
  56. /// </summary>
  57. protected Rect drawRect { get; set; } = new Rect(0, 0, 0, 0);
  58. /// <summary>
  59. /// Maximum range that can be drawn.
  60. /// </summary>
  61. protected Rect maxRect { get; set; } = new Rect(0, 0, 0, 0);
  62. /// <summary>
  63. /// Current center point of the drawing rectangle.
  64. /// </summary>
  65. protected Point drawCenterPoint { get; private set; } = new Point(0, 0);
  66. /// <summary>
  67. /// When the mouse is pressed, the cached rectangle.
  68. /// </summary>
  69. protected Rect cacheRect { get; set; } = new Rect(0, 0, 0, 0);
  70. /// <summary>
  71. /// Current control point coordinates.
  72. /// </summary>
  73. protected List<Point> controlPoints { get; set; } = new List<Point>();
  74. /// <summary>
  75. /// Move offset during movement.
  76. /// </summary>
  77. protected Point moveOffset { get; set; } = new Point(0, 0);
  78. /// <summary>
  79. /// Current actual display width and height of PDFVIewer.
  80. /// </summary>
  81. protected double PDFViewerActualWidth { get; set; } = 0;
  82. protected double PDFViewerActualHeight { get; set; } = 0;
  83. protected double rectPadding = 6;
  84. protected double currentZoom = 1;
  85. protected SelectedAnnotData selectedRectData = new SelectedAnnotData();
  86. protected bool disable = false;
  87. #endregion
  88. #region Functions
  89. /// <summary>
  90. /// Calcuate the control points
  91. /// </summary>
  92. /// <param name="currentRect">
  93. /// Control points in the target rectangle
  94. /// </param>
  95. protected void CalcControlPoint(Rect currentRect)
  96. {
  97. controlPoints.Clear();
  98. int centerX = (int)(currentRect.Left + currentRect.Right) / 2;
  99. int centerY = (int)(currentRect.Top + currentRect.Bottom) / 2;
  100. controlPoints.Add(new Point(currentRect.Left, currentRect.Top));
  101. controlPoints.Add(new Point(currentRect.Left, centerY));
  102. controlPoints.Add(new Point(currentRect.Left, currentRect.Bottom));
  103. controlPoints.Add(new Point(centerX, currentRect.Bottom));
  104. controlPoints.Add(new Point(currentRect.Right, currentRect.Bottom));
  105. controlPoints.Add(new Point(currentRect.Right, centerY));
  106. controlPoints.Add(new Point(currentRect.Right, currentRect.Top));
  107. controlPoints.Add(new Point(centerX, currentRect.Top));
  108. }
  109. /// <summary>
  110. /// Calcuate the offset of the current rectangle in the maximum rectangle range
  111. /// </summary>
  112. /// <param name="currentRect">
  113. /// The rectangle cached when pressed
  114. /// </param>
  115. /// <param name="offsetPoint">
  116. /// Equivalent to the offset value when pressed
  117. /// </param>
  118. /// <param name="maxRect">
  119. /// The maximum rectangle range.
  120. /// </param>
  121. /// <returns></returns>
  122. protected Point CalcMoveBound(Rect currentRect, Point offsetPoint, Rect maxRect)
  123. {
  124. double cLeft = currentRect.Left;
  125. double cRight = currentRect.Right;
  126. double cUp = currentRect.Top;
  127. double cDown = currentRect.Bottom;
  128. double TmpLeft = cLeft + offsetPoint.X;
  129. double TmpRight = cRight + offsetPoint.X;
  130. double TmpUp = cUp + offsetPoint.Y;
  131. double TmpDown = cDown + offsetPoint.Y;
  132. if (TmpLeft < maxRect.Left)
  133. {
  134. TmpRight = (cRight - cLeft) + maxRect.Left;
  135. TmpLeft = maxRect.Left;
  136. }
  137. if (TmpUp < maxRect.Top)
  138. {
  139. TmpDown = (cDown - cUp) + maxRect.Top;
  140. TmpUp = maxRect.Top;
  141. }
  142. if (TmpRight > maxRect.Right)
  143. {
  144. TmpLeft = maxRect.Right - (cRight - cLeft);
  145. TmpRight = maxRect.Right;
  146. }
  147. if (TmpDown > maxRect.Bottom)
  148. {
  149. TmpUp = maxRect.Bottom - (cDown - cUp);
  150. TmpDown = maxRect.Bottom;
  151. }
  152. offsetPoint = new Point(TmpLeft - cLeft, TmpUp - cUp);
  153. return offsetPoint;
  154. }
  155. /// <summary>
  156. /// Calculate the movement of the hit point
  157. /// </summary>
  158. /// <param name="mousePoint">
  159. /// Current mouse position
  160. /// </param>
  161. /// <returns>
  162. /// Whether the movement is successful
  163. /// </returns>
  164. protected bool CalcHitPointMove(Point mousePoint)
  165. {
  166. if (isMouseDown == false || hitControlType == PointControlType.None)
  167. {
  168. return false;
  169. }
  170. return NormalScaling(mousePoint);
  171. }
  172. private Size GetProportionalScalingSize(double width, double height)
  173. {
  174. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  175. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  176. if (minWidth > width || minHeight > height)
  177. {
  178. if (cacheRect.Width >= cacheRect.Height)
  179. {
  180. width = cacheRect.Width * minHeight / cacheRect.Height;
  181. height = minHeight;
  182. }
  183. else
  184. {
  185. height = cacheRect.Height * minWidth / cacheRect.Width;
  186. width = minWidth;
  187. }
  188. }
  189. return new Size(width, height);
  190. }
  191. /// <summary>
  192. /// Draw the algorithm in the form of normal scaling (drag a point, only scale in one direction).
  193. /// </summary>
  194. /// <param name="mousePoint">Current mouse position.</param>
  195. /// <returns></returns>
  196. protected bool NormalScaling(Point mousePoint)
  197. {
  198. double left = 0, right = 0, top = 0, bottom = 0;
  199. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  200. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  201. Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
  202. Point moveVector = (Point)(mousePoint - centerPoint);
  203. moveVector = ProportionalScalingOffsetPos(moveVector);
  204. switch (hitControlType)
  205. {
  206. case PointControlType.LeftTop:
  207. {
  208. left = centerPoint.X + moveVector.X;
  209. right = cacheRect.Right;
  210. top = centerPoint.Y + moveVector.Y;
  211. bottom = cacheRect.Bottom;
  212. if (isProportionalScaling)
  213. {
  214. Size size = GetProportionalScalingSize(right - left, bottom - top);
  215. left = right - size.Width;
  216. top = bottom - size.Height;
  217. if(left < maxRect.Left)
  218. {
  219. double tmpWidth = right - left;
  220. left = maxRect.Left;
  221. double width = right - left;
  222. double height = (bottom - top) * width / tmpWidth;
  223. top = bottom - height;
  224. }
  225. if (top < maxRect.Top)
  226. {
  227. double tmpHeight = bottom - top;
  228. top = maxRect.Top;
  229. double height = bottom - top;
  230. double width = (right - left) * height / tmpHeight;
  231. left = right - width;
  232. }
  233. }
  234. else
  235. {
  236. if (left + minWidth > right)
  237. {
  238. left = right - minWidth;
  239. }
  240. if (top + minHeight > bottom)
  241. {
  242. top = bottom - minHeight;
  243. }
  244. }
  245. }
  246. break;
  247. case PointControlType.LeftMiddle:
  248. {
  249. left = centerPoint.X + moveVector.X;
  250. right = cacheRect.Right;
  251. top = cacheRect.Top;
  252. bottom = cacheRect.Bottom;
  253. if (left + minWidth > right)
  254. {
  255. left = right - minWidth;
  256. }
  257. }
  258. break;
  259. case PointControlType.LeftBottom:
  260. {
  261. left = centerPoint.X + moveVector.X;
  262. right = cacheRect.Right;
  263. top = cacheRect.Top;
  264. bottom = centerPoint.Y + moveVector.Y;
  265. if (isProportionalScaling)
  266. {
  267. Size size = GetProportionalScalingSize(right - left, bottom - top);
  268. left = right - size.Width;
  269. bottom = top + size.Height;
  270. if (left < maxRect.Left)
  271. {
  272. double tmpWidth = right - left;
  273. left = maxRect.Left;
  274. double width = right - left;
  275. double height = (bottom - top) * width / tmpWidth;
  276. bottom = top + height;
  277. }
  278. if (bottom > maxRect.Bottom)
  279. {
  280. double tmpHeight = bottom - top;
  281. bottom = maxRect.Bottom;
  282. double height = bottom - top;
  283. double width = (right - left) * height / tmpHeight;
  284. left = right - width;
  285. }
  286. }
  287. else
  288. {
  289. if (left + minWidth > right)
  290. {
  291. left = right - minWidth;
  292. }
  293. if (top + minHeight > bottom)
  294. {
  295. bottom = top + minHeight;
  296. }
  297. }
  298. }
  299. break;
  300. case PointControlType.MiddlBottom:
  301. {
  302. left = cacheRect.Left;
  303. right = cacheRect.Right;
  304. top = cacheRect.Top;
  305. bottom = centerPoint.Y + moveVector.Y;
  306. if (top + minHeight > bottom)
  307. {
  308. bottom = top + minHeight;
  309. }
  310. }
  311. break;
  312. case PointControlType.RightBottom:
  313. {
  314. left = cacheRect.Left;
  315. right = centerPoint.X + moveVector.X;
  316. top = cacheRect.Top;
  317. bottom = centerPoint.Y + moveVector.Y;
  318. if (isProportionalScaling)
  319. {
  320. Size size = GetProportionalScalingSize(right - left, bottom - top);
  321. right = left + size.Width;
  322. bottom = top + size.Height;
  323. if (right > maxRect.Right)
  324. {
  325. double tmpWidth = right - left;
  326. right = maxRect.Right;
  327. double width = right - left;
  328. double height = (bottom - top) * width / tmpWidth;
  329. bottom = top + height;
  330. }
  331. if (bottom > maxRect.Bottom)
  332. {
  333. double tmpHeight = bottom - top;
  334. bottom = maxRect.Bottom;
  335. double height = bottom - top;
  336. double width = (right - left) * height / tmpHeight;
  337. right = left + width;
  338. }
  339. }
  340. else
  341. {
  342. if (left + minWidth > right)
  343. {
  344. right = left + minWidth;
  345. }
  346. if (top + minHeight > bottom)
  347. {
  348. bottom = top + minHeight;
  349. }
  350. }
  351. }
  352. break;
  353. case PointControlType.RightMiddle:
  354. {
  355. left = cacheRect.Left;
  356. right = centerPoint.X + moveVector.X;
  357. top = cacheRect.Top;
  358. bottom = cacheRect.Bottom;
  359. if (left + minWidth > right)
  360. {
  361. right = left + minWidth;
  362. }
  363. }
  364. break;
  365. case PointControlType.RightTop:
  366. {
  367. left = cacheRect.Left;
  368. right = centerPoint.X + moveVector.X;
  369. top = centerPoint.Y + moveVector.Y;
  370. bottom = cacheRect.Bottom;
  371. if (isProportionalScaling)
  372. {
  373. Size size = GetProportionalScalingSize(right - left, bottom - top);
  374. right = left + size.Width;
  375. top = bottom - size.Height;
  376. if (right > maxRect.Right)
  377. {
  378. double tmpWidth = right - left;
  379. right = maxRect.Right;
  380. double width = right - left;
  381. double height = (bottom - top) * width / tmpWidth;
  382. top = bottom - height;
  383. }
  384. if (top < maxRect.Top)
  385. {
  386. double tmpHeight = bottom - top;
  387. top = maxRect.Top;
  388. double height = bottom - top;
  389. double width = (right - left) * height / tmpHeight;
  390. right = left + width;
  391. }
  392. }
  393. else
  394. {
  395. if (left + minWidth > right)
  396. {
  397. right = left + minWidth;
  398. }
  399. if (top + minHeight > bottom)
  400. {
  401. top = bottom - minHeight;
  402. }
  403. }
  404. }
  405. break;
  406. case PointControlType.MiddleTop:
  407. {
  408. left = cacheRect.Left;
  409. right = cacheRect.Right;
  410. top = centerPoint.Y + moveVector.Y;
  411. bottom = cacheRect.Bottom;
  412. if (top + minHeight > bottom)
  413. {
  414. top = bottom - minHeight;
  415. }
  416. }
  417. break;
  418. case PointControlType.Body:
  419. case PointControlType.Line:
  420. {
  421. Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), maxRect);
  422. left = cacheRect.Left + OffsetPos.X;
  423. right = cacheRect.Right + OffsetPos.X;
  424. top = cacheRect.Top + OffsetPos.Y;
  425. bottom = cacheRect.Bottom + OffsetPos.Y;
  426. }
  427. break;
  428. default:
  429. break;
  430. }
  431. if (left < maxRect.Left)
  432. {
  433. left = maxRect.Left;
  434. }
  435. if (top < maxRect.Top)
  436. {
  437. top = maxRect.Top;
  438. }
  439. if (right > maxRect.Right)
  440. {
  441. right = maxRect.Right;
  442. }
  443. if (bottom > maxRect.Bottom)
  444. {
  445. bottom = maxRect.Bottom;
  446. }
  447. drawRect = new Rect(left, top, right - left, bottom - top);
  448. moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
  449. return true;
  450. }
  451. /// <summary>
  452. /// Proportional scaling offset calibration
  453. /// </summary>
  454. /// <param name="movePoint">
  455. /// The current movement point
  456. /// </param>
  457. /// <returns>
  458. /// The offset point after the proportional scaling
  459. /// </returns>
  460. protected Point ProportionalScalingOffsetPos(Point movePoint)
  461. {
  462. if (isProportionalScaling)
  463. {
  464. Point offsetPos = movePoint;
  465. double ratioX = cacheRect.Width > 0 ? cacheRect.Height / cacheRect.Width : 1;
  466. double ratioY = cacheRect.Height > 0 ? cacheRect.Width / cacheRect.Height : 1;
  467. switch (hitControlType)
  468. {
  469. case PointControlType.LeftTop:
  470. case PointControlType.RightBottom:
  471. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
  472. break;
  473. case PointControlType.LeftBottom:
  474. case PointControlType.RightTop:
  475. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
  476. break;
  477. case PointControlType.LeftMiddle:
  478. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
  479. break;
  480. case PointControlType.RightMiddle:
  481. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
  482. break;
  483. case PointControlType.MiddlBottom:
  484. offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? 1 : -1), movePoint.Y);
  485. break;
  486. case PointControlType.MiddleTop:
  487. offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? -1 : 1), movePoint.Y);
  488. break;
  489. default:
  490. break;
  491. }
  492. return offsetPos;
  493. }
  494. else
  495. {
  496. return movePoint;
  497. }
  498. }
  499. /// <summary>
  500. /// Inner drawing circle point
  501. /// </summary>
  502. /// <param name="drawingContext">
  503. /// Drawing context
  504. /// </param>
  505. /// <param name="ignoreList">
  506. /// Collection of positions that need to be drawn
  507. /// </param>
  508. /// <param name="PointSize">
  509. /// Size of the point
  510. /// </param>
  511. /// <param name="PointPen">
  512. /// Brush for drawing points
  513. /// </param>
  514. /// <param name="BorderBrush">
  515. /// Border brush for drawing points
  516. /// </param>
  517. protected void DrawCirclePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  518. {
  519. GeometryGroup controlGroup = new GeometryGroup();
  520. controlGroup.FillRule = FillRule.Nonzero;
  521. List<Point> ignorePointsList = new List<Point>();
  522. // Get specific points
  523. foreach (PointControlType type in ignoreList)
  524. {
  525. if ((int)type < controlPoints.Count)
  526. {
  527. ignorePointsList.Add(controlPoints[(int)type]);
  528. }
  529. }
  530. for (int i = 0; i < controlPoints.Count; i++)
  531. {
  532. Point controlPoint = controlPoints[i];
  533. if (ignorePointsList.Contains(controlPoint))
  534. {
  535. continue;
  536. }
  537. EllipseGeometry circlPoint = new EllipseGeometry(controlPoint, PointSize, PointSize);
  538. controlGroup.Children.Add(circlPoint);
  539. }
  540. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  541. }
  542. /// <summary>
  543. /// Inner drawing square
  544. /// </summary>
  545. /// <param name="drawingContext">
  546. /// Drawing context
  547. /// </param>
  548. /// <param name="ControlPoints">
  549. /// Collection of positions that need to be drawn
  550. /// </param>
  551. /// <param name="PointSize">
  552. /// Size of the point
  553. /// </param>
  554. /// <param name="PointPen">
  555. /// Brush for drawing points
  556. /// </param>
  557. /// <param name="BorderBrush">
  558. /// Border brush for drawing points
  559. /// </param>
  560. protected void DrawSquarePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  561. {
  562. GeometryGroup controlGroup = new GeometryGroup();
  563. controlGroup.FillRule = FillRule.Nonzero;
  564. List<Point> ignorePointsList = new List<Point>();
  565. // Get specific points
  566. foreach (PointControlType type in ignoreList)
  567. {
  568. if ((int)type < controlPoints.Count)
  569. {
  570. ignorePointsList.Add(controlPoints[(int)type]);
  571. }
  572. }
  573. for (int i = 0; i < controlPoints.Count; i++)
  574. {
  575. Point controlPoint = controlPoints[i];
  576. if (ignorePointsList.Contains(controlPoint))
  577. {
  578. continue;
  579. }
  580. RectangleGeometry rectPoint = new RectangleGeometry(new Rect(controlPoint.X - PointSize, controlPoint.Y - PointSize,
  581. PointSize * 2, PointSize * 2), 1, 1);
  582. controlGroup.Children.Add(rectPoint);
  583. }
  584. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  585. }
  586. protected void DrawCropPoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  587. {
  588. GeometryGroup controlGroup = new GeometryGroup();
  589. controlGroup.FillRule = FillRule.Nonzero;
  590. //Left Top Corner
  591. if (!ignoreList.Contains(PointControlType.LeftTop))
  592. {
  593. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[0].X - PointSize, controlPoints[0].Y - PointSize, PointSize, PointSize * 4));
  594. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[0].X - PointSize, controlPoints[0].Y - PointSize, PointSize * 4, PointSize));
  595. }
  596. //Left Center
  597. if (!ignoreList.Contains(PointControlType.LeftMiddle))
  598. {
  599. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[1].X - PointSize, (controlPoints[1].Y + controlPoints[1].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
  600. }
  601. //Left Bottom Corner
  602. if (!ignoreList.Contains(PointControlType.LeftBottom))
  603. {
  604. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[2].X - PointSize, controlPoints[2].Y - PointSize * 3, PointSize, PointSize * 4));
  605. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[2].X - PointSize, controlPoints[2].Y, PointSize * 4, PointSize));
  606. }
  607. //Bottom Center
  608. if (!ignoreList.Contains(PointControlType.MiddlBottom))
  609. {
  610. drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlPoints[3].X + controlPoints[3].X - PointSize * 5) / 2, controlPoints[3].Y, PointSize * 5, PointSize));
  611. }
  612. //Bottom Right Corner
  613. if (!ignoreList.Contains(PointControlType.RightBottom))
  614. {
  615. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[4].X , controlPoints[4].Y - PointSize * 3, PointSize, PointSize * 4));
  616. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[4].X - PointSize * 3, controlPoints[4].Y, PointSize * 4, PointSize));
  617. }
  618. //Right Center
  619. if (!ignoreList.Contains(PointControlType.RightMiddle))
  620. {
  621. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[5].X, (controlPoints[5].Y + controlPoints[5].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
  622. }
  623. //Right Top Corner
  624. if (!ignoreList.Contains(PointControlType.RightTop))
  625. {
  626. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[6].X, controlPoints[6].Y - PointSize, PointSize, PointSize * 4));
  627. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlPoints[6].X - PointSize * 4, controlPoints[6].Y - PointSize, PointSize * 4, PointSize));
  628. }
  629. //Top Center
  630. if (!ignoreList.Contains(PointControlType.MiddleTop))
  631. {
  632. drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlPoints[7].X + controlPoints[7].X - PointSize * 5) / 2, controlPoints[7].Y-PointSize, PointSize * 5, PointSize));
  633. }
  634. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  635. }
  636. /// <summary>
  637. /// Draw the reference line in the moving state
  638. /// </summary>
  639. /// <param name="drawDc">
  640. /// Draw context handle
  641. /// </param>
  642. /// <param name="controltype">
  643. /// Current selected control point type
  644. /// </param>
  645. /// <param name="activePen">
  646. /// Brush for drawing lines
  647. /// </param>
  648. /// <param name="moveBrush">
  649. /// Brush for drawing rectangles
  650. /// </param>
  651. /// <param name="moveRect">
  652. /// Current rectangle to draw
  653. /// </param>
  654. protected void DrawMoveBounds(DrawingContext drawDc, PointControlType controltype, Pen activePen, Brush moveBrush, Rect moveRect)
  655. {
  656. switch (controltype)
  657. {
  658. case PointControlType.LeftTop:
  659. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  660. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  661. break;
  662. case PointControlType.LeftMiddle:
  663. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  664. break;
  665. case PointControlType.LeftBottom:
  666. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  667. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  668. break;
  669. case PointControlType.MiddlBottom:
  670. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  671. break;
  672. case PointControlType.RightBottom:
  673. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  674. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  675. break;
  676. case PointControlType.RightMiddle:
  677. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  678. break;
  679. case PointControlType.RightTop:
  680. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  681. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  682. break;
  683. case PointControlType.MiddleTop:
  684. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  685. break;
  686. case PointControlType.Rotate:
  687. break;
  688. case PointControlType.Body:
  689. case PointControlType.Line:
  690. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  691. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  692. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  693. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  694. break;
  695. default:
  696. break;
  697. }
  698. drawDc?.DrawRectangle(moveBrush, null, moveRect);
  699. }
  700. /// <summary>
  701. /// Notify the event during/after the drawing data
  702. /// </summary>
  703. /// <param name="isFinish">
  704. /// Identifies whether the data change is complete
  705. /// </param>
  706. protected void InvokeDataChangEvent(bool isFinish)
  707. {
  708. selectedRectData.Square = GetRect();
  709. if (isFinish)
  710. {
  711. DataChanged?.Invoke(this, selectedRectData);
  712. }
  713. else
  714. {
  715. DataChanging?.Invoke(this, selectedRectData);
  716. }
  717. }
  718. /// <summary>
  719. /// Align the rectangle drawing
  720. /// </summary>
  721. /// <param name="RectMovePoint">
  722. /// Move distance required for the aligned algorithm to obtain the rectangle
  723. /// </param>
  724. private void DrawAlignRect(Point RectMovePoint)
  725. {
  726. double TmpLeft, TmpRight, TmpUp, TmpDown;
  727. Point OffsetPos = CalcMoveBound(drawRect, RectMovePoint, maxRect);
  728. TmpLeft = drawRect.Left + OffsetPos.X;
  729. TmpRight = drawRect.Right + OffsetPos.X;
  730. TmpUp = drawRect.Top + OffsetPos.Y;
  731. TmpDown = drawRect.Bottom + OffsetPos.Y;
  732. SetDrawRect = drawRect = new Rect(TmpLeft, TmpUp, TmpRight - TmpLeft, TmpDown - TmpUp);
  733. Draw();
  734. }
  735. /// <summary>
  736. /// Get the current set of ignore points
  737. /// </summary>
  738. /// <returns>
  739. /// Data set of ignored points
  740. /// </returns>
  741. private List<PointControlType> GetIgnorePoints()
  742. {
  743. List<PointControlType> IgnorePointsList = new List<PointControlType>();
  744. foreach (PointControlType type in ignorePoints)
  745. {
  746. IgnorePointsList.Add(type);
  747. }
  748. return IgnorePointsList;
  749. }
  750. #endregion
  751. }
  752. }