SelectedRect.protected.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Windows;
  5. using System.Windows.Input;
  6. using System.Windows.Media;
  7. namespace ComPDFKit.Tool.DrawTool
  8. {
  9. public partial class SelectedRect
  10. {
  11. #region Properties
  12. /// <summary>
  13. /// Current control point drawing style.
  14. /// </summary>
  15. protected DrawPointType currentDrawPointType
  16. {
  17. get;
  18. set;
  19. }
  20. /// <summary>
  21. /// Current drag drawing style.
  22. /// </summary>
  23. protected DrawMoveType currentDrawMoveType { get; set; }
  24. /// <summary>
  25. /// Current click hit control point.
  26. /// </summary>
  27. protected PointControlType hitControlType
  28. {
  29. get;
  30. set;
  31. }
  32. /// <summary>
  33. /// Mouse down position information.
  34. /// </summary>
  35. protected Point mouseDownPoint { get; set; }
  36. /// <summary>
  37. /// Whether the mouse is pressed.
  38. /// </summary>
  39. protected bool isMouseDown { get; set; }
  40. protected bool isInRotate { get; set; } = false;
  41. protected bool isInScaling { get; set; } = false;
  42. /// <summary>
  43. /// Whether proportional scaling is required.
  44. /// </summary>
  45. protected bool isProportionalScaling { get; set; } = false;
  46. /// <summary>
  47. /// Current control point size.
  48. /// </summary>
  49. protected int pointSize { get; set; } = 4;
  50. /// <summary>
  51. /// Rectangular minimum width.
  52. /// </summary>
  53. protected int rectMinWidth { get; set; } = 10;
  54. /// <summary>
  55. /// Rectangular minimum height.
  56. /// </summary>
  57. protected int RectMinHeight { get; set; } = 10;
  58. /// <summary>
  59. /// Current set of ignore points.
  60. /// </summary>
  61. protected List<PointControlType> ignorePoints { get; set; } = new List<PointControlType>();
  62. /// <summary>
  63. /// Current set of drawing rectangles (original data).
  64. /// </summary>
  65. protected Rect SetDrawRect
  66. {
  67. get;
  68. set;
  69. } = new Rect(0, 0, 0, 0);
  70. /// <summary>
  71. /// Current drawing rectangle (calculated during operation).
  72. /// </summary>
  73. protected Rect drawRect
  74. {
  75. get;
  76. set;
  77. } = new Rect(0, 0, 0, 0);
  78. /// <summary>
  79. /// Maximum range that can be drawn.
  80. /// </summary>
  81. protected Rect maxRect { get; set; } = new Rect(0, 0, 0, 0);
  82. /// <summary>
  83. /// Current center point of the drawing rectangle.
  84. /// </summary>
  85. protected Point drawCenterPoint { get; private set; } = new Point(0, 0);
  86. /// <summary>
  87. /// When the mouse is pressed, the cached rectangle.
  88. /// </summary>
  89. protected Rect cacheRect { get; set; } = new Rect(0, 0, 0, 0);
  90. /// <summary>
  91. /// Current control point coordinates.
  92. /// </summary>
  93. protected List<Point> controlPoints { get; set; } = new List<Point>();
  94. protected Point centerPoint = new Point();
  95. protected Point rotationPoint = new Point();
  96. protected Point dragRotationPoint = new Point();
  97. /// <summary>
  98. /// Move offset during movement.
  99. /// </summary>
  100. protected Point moveOffset { get; set; } = new Point(0, 0);
  101. /// <summary>
  102. /// Current drawing rectangle (calculated during operation).
  103. /// </summary>
  104. protected Thickness clipThickness = new Thickness(0, 0, 0, 0);
  105. private Pen editPen { get; set; } = new Pen(new SolidColorBrush(Color.FromRgb(71, 126, 222)), 2) { DashStyle = DashStyles.Dash };
  106. private Pen editHoverPen { get; set; } = new Pen(new SolidColorBrush(Color.FromRgb(71, 126, 222)), 2) { DashStyle = DashStyles.Dash };
  107. private bool showCreatTextRect = false;
  108. protected bool isOutSideScaling = false;
  109. /// <summary>
  110. /// Current actual display width and height of PDFVIewer.
  111. /// </summary>
  112. protected double PDFViewerActualWidth { get; set; } = 0;
  113. protected double PDFViewerActualHeight { get; set; } = 0;
  114. protected int rotateAngle { get; set; } = 0;
  115. protected double rectPadding = 6;
  116. protected double currentZoom = 1;
  117. protected SelectedAnnotData selectedRectData = new SelectedAnnotData();
  118. protected bool disable = false;
  119. #endregion
  120. #region Functions
  121. /// <summary>
  122. /// Calcuate the control points
  123. /// </summary>
  124. /// <param name="currentRect">
  125. /// Control points in the target rectangle
  126. /// </param>
  127. protected void CalcControlPoint(Rect currentRect)
  128. {
  129. controlPoints.Clear();
  130. centerPoint.X = (int)(currentRect.Left + currentRect.Right) / 2;
  131. centerPoint.Y = (int)(currentRect.Top + currentRect.Bottom) / 2;
  132. controlPoints.Add(new Point(currentRect.Left, currentRect.Top));
  133. controlPoints.Add(new Point(currentRect.Left, centerPoint.Y));
  134. controlPoints.Add(new Point(currentRect.Left, currentRect.Bottom));
  135. controlPoints.Add(new Point(centerPoint.X, currentRect.Bottom));
  136. controlPoints.Add(new Point(currentRect.Right, currentRect.Bottom));
  137. controlPoints.Add(new Point(currentRect.Right, centerPoint.Y));
  138. controlPoints.Add(new Point(currentRect.Right, currentRect.Top));
  139. controlPoints.Add(new Point(centerPoint.X, currentRect.Top));
  140. if (canRotation)
  141. {
  142. rotationPoint = new Point(centerPoint.X, currentRect.Top - 30);
  143. }
  144. }
  145. protected List<Point> GetControlPoint(Rect currentRect)
  146. {
  147. List<Point> controlCurrentPoints = new List<Point>();
  148. controlCurrentPoints.Clear();
  149. int centerX = (int)(currentRect.Left + currentRect.Right) / 2;
  150. int centerY = (int)(currentRect.Top + currentRect.Bottom) / 2;
  151. controlCurrentPoints.Add(new Point(currentRect.Left, currentRect.Top));
  152. controlCurrentPoints.Add(new Point(currentRect.Left, centerY));
  153. controlCurrentPoints.Add(new Point(currentRect.Left, currentRect.Bottom));
  154. controlCurrentPoints.Add(new Point(centerX, currentRect.Bottom));
  155. controlCurrentPoints.Add(new Point(currentRect.Right, currentRect.Bottom));
  156. controlCurrentPoints.Add(new Point(currentRect.Right, centerY));
  157. controlCurrentPoints.Add(new Point(currentRect.Right, currentRect.Top));
  158. controlCurrentPoints.Add(new Point(centerX, currentRect.Top));
  159. return controlCurrentPoints;
  160. }
  161. /// <summary>
  162. /// Calcuate the offset of the current rectangle in the maximum rectangle range
  163. /// </summary>
  164. /// <param name="currentRect">
  165. /// The rectangle cached when pressed
  166. /// </param>
  167. /// <param name="offsetPoint">
  168. /// Equivalent to the offset value when pressed
  169. /// </param>
  170. /// <param name="maxRect">
  171. /// The maximum rectangle range.
  172. /// </param>
  173. /// <returns></returns>
  174. protected Point CalcMoveBound(Rect currentRect, Point offsetPoint, Rect maxRect)
  175. {
  176. double cLeft = currentRect.Left;
  177. double cRight = currentRect.Right;
  178. double cUp = currentRect.Top;
  179. double cDown = currentRect.Bottom;
  180. double TmpLeft = cLeft + offsetPoint.X;
  181. double TmpRight = cRight + offsetPoint.X;
  182. double TmpUp = cUp + offsetPoint.Y;
  183. double TmpDown = cDown + offsetPoint.Y;
  184. if (TmpLeft < maxRect.Left)
  185. {
  186. TmpRight = (cRight - cLeft) + maxRect.Left;
  187. TmpLeft = maxRect.Left;
  188. }
  189. if (TmpUp < maxRect.Top)
  190. {
  191. TmpDown = (cDown - cUp) + maxRect.Top;
  192. TmpUp = maxRect.Top;
  193. }
  194. if (TmpRight > maxRect.Right)
  195. {
  196. TmpLeft = maxRect.Right - (cRight - cLeft);
  197. TmpRight = maxRect.Right;
  198. }
  199. if (TmpDown > maxRect.Bottom)
  200. {
  201. TmpUp = maxRect.Bottom - (cDown - cUp);
  202. TmpDown = maxRect.Bottom;
  203. }
  204. offsetPoint = new Point(TmpLeft - cLeft, TmpUp - cUp);
  205. return offsetPoint;
  206. }
  207. /// <summary>
  208. /// Calculate the movement of the hit point
  209. /// </summary>
  210. /// <param name="mousePoint">
  211. /// Current mouse position
  212. /// </param>
  213. /// <returns>
  214. /// Whether the movement is successful
  215. /// </returns>
  216. protected bool CalcHitPointMove(Point mousePoint)
  217. {
  218. if (isMouseDown == false || hitControlType == PointControlType.None)
  219. {
  220. return false;
  221. }
  222. if (hitControlType == PointControlType.Rotate)
  223. {
  224. return SetRotateByMousePoint(mousePoint);
  225. }
  226. if (!isOutSideScaling)
  227. {
  228. return NormalScaling(mousePoint);
  229. }
  230. else
  231. {
  232. return OutSideScaling(mousePoint);
  233. }
  234. }
  235. public void SetOutSideScaling(bool IsOutSideScaling)
  236. {
  237. isOutSideScaling = IsOutSideScaling;
  238. }
  239. private Size GetProportionalScalingSize(double width, double height)
  240. {
  241. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  242. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  243. if (minWidth > width || minHeight > height)
  244. {
  245. if (cacheRect.Width >= cacheRect.Height)
  246. {
  247. width = cacheRect.Width * minHeight / cacheRect.Height;
  248. height = minHeight;
  249. }
  250. else
  251. {
  252. height = cacheRect.Height * minWidth / cacheRect.Width;
  253. width = minWidth;
  254. }
  255. }
  256. return new Size(width, height);
  257. }
  258. private bool SetRotateByMousePoint(Point mousePoint)
  259. {
  260. dragRotationPoint = mousePoint;
  261. Vector moveVector = (mousePoint - centerPoint);
  262. rotateAngle = (int)(Math.Atan2(moveVector.X, -moveVector.Y) * 180 / Math.PI);
  263. return false;
  264. }
  265. /// <summary>
  266. /// Draw the algorithm in the form of normal scaling (drag a point, only scale in one direction).
  267. /// </summary>
  268. /// <param name="mousePoint">Current mouse position.</param>
  269. /// <returns></returns>
  270. protected bool NormalScaling(Point mousePoint)
  271. {
  272. try
  273. {
  274. double left = 0, right = 0, top = 0, bottom = 0;
  275. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  276. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  277. Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
  278. Point moveVector = (Point)(mousePoint - centerPoint);
  279. moveVector = ProportionalScalingOffsetPos(moveVector);
  280. switch (hitControlType)
  281. {
  282. case PointControlType.LeftTop:
  283. {
  284. left = centerPoint.X + moveVector.X;
  285. right = cacheRect.Right;
  286. top = centerPoint.Y + moveVector.Y;
  287. bottom = cacheRect.Bottom;
  288. if (isProportionalScaling)
  289. {
  290. Size size = GetProportionalScalingSize(right - left, bottom - top);
  291. left = right - size.Width;
  292. top = bottom - size.Height;
  293. if (left < maxRect.Left)
  294. {
  295. double tmpWidth = right - left;
  296. left = maxRect.Left;
  297. double width = right - left;
  298. double height = (bottom - top) * width / tmpWidth;
  299. top = bottom - height;
  300. }
  301. if (top < maxRect.Top)
  302. {
  303. double tmpHeight = bottom - top;
  304. top = maxRect.Top;
  305. double height = bottom - top;
  306. double width = (right - left) * height / tmpHeight;
  307. left = right - width;
  308. }
  309. }
  310. else
  311. {
  312. if (left + minWidth > right)
  313. {
  314. left = right - minWidth;
  315. }
  316. if (top + minHeight > bottom)
  317. {
  318. top = bottom - minHeight;
  319. }
  320. }
  321. }
  322. break;
  323. case PointControlType.LeftMiddle:
  324. {
  325. left = centerPoint.X + moveVector.X;
  326. right = cacheRect.Right;
  327. top = cacheRect.Top;
  328. bottom = cacheRect.Bottom;
  329. if (left + minWidth > right)
  330. {
  331. left = right - minWidth;
  332. }
  333. }
  334. break;
  335. case PointControlType.LeftBottom:
  336. {
  337. left = centerPoint.X + moveVector.X;
  338. right = cacheRect.Right;
  339. top = cacheRect.Top;
  340. bottom = centerPoint.Y + moveVector.Y;
  341. if (isProportionalScaling)
  342. {
  343. Size size = GetProportionalScalingSize(right - left, bottom - top);
  344. left = right - size.Width;
  345. bottom = top + size.Height;
  346. if (left < maxRect.Left)
  347. {
  348. double tmpWidth = right - left;
  349. left = maxRect.Left;
  350. double width = right - left;
  351. double height = (bottom - top) * width / tmpWidth;
  352. bottom = top + height;
  353. }
  354. if (bottom > maxRect.Bottom)
  355. {
  356. double tmpHeight = bottom - top;
  357. bottom = maxRect.Bottom;
  358. double height = bottom - top;
  359. double width = (right - left) * height / tmpHeight;
  360. left = right - width;
  361. }
  362. }
  363. else
  364. {
  365. if (left + minWidth > right)
  366. {
  367. left = right - minWidth;
  368. }
  369. if (top + minHeight > bottom)
  370. {
  371. bottom = top + minHeight;
  372. }
  373. }
  374. }
  375. break;
  376. case PointControlType.MiddleBottom:
  377. {
  378. left = cacheRect.Left;
  379. right = cacheRect.Right;
  380. top = cacheRect.Top;
  381. bottom = centerPoint.Y + moveVector.Y;
  382. if (top + minHeight > bottom)
  383. {
  384. bottom = top + minHeight;
  385. }
  386. }
  387. break;
  388. case PointControlType.RightBottom:
  389. {
  390. left = cacheRect.Left;
  391. right = centerPoint.X + moveVector.X;
  392. top = cacheRect.Top;
  393. bottom = centerPoint.Y + moveVector.Y;
  394. if (isProportionalScaling)
  395. {
  396. Size size = GetProportionalScalingSize(right - left, bottom - top);
  397. right = left + size.Width;
  398. bottom = top + size.Height;
  399. if (right > maxRect.Right)
  400. {
  401. double tmpWidth = right - left;
  402. right = maxRect.Right;
  403. double width = right - left;
  404. double height = (bottom - top) * width / tmpWidth;
  405. bottom = top + height;
  406. }
  407. if (bottom > maxRect.Bottom)
  408. {
  409. double tmpHeight = bottom - top;
  410. bottom = maxRect.Bottom;
  411. double height = bottom - top;
  412. double width = (right - left) * height / tmpHeight;
  413. right = left + width;
  414. }
  415. }
  416. else
  417. {
  418. if (left + minWidth > right)
  419. {
  420. right = left + minWidth;
  421. }
  422. if (top + minHeight > bottom)
  423. {
  424. bottom = top + minHeight;
  425. }
  426. }
  427. }
  428. break;
  429. case PointControlType.RightMiddle:
  430. {
  431. left = cacheRect.Left;
  432. right = centerPoint.X + moveVector.X;
  433. top = cacheRect.Top;
  434. bottom = cacheRect.Bottom;
  435. if (left + minWidth > right)
  436. {
  437. right = left + minWidth;
  438. }
  439. }
  440. break;
  441. case PointControlType.RightTop:
  442. {
  443. left = cacheRect.Left;
  444. right = centerPoint.X + moveVector.X;
  445. top = centerPoint.Y + moveVector.Y;
  446. bottom = cacheRect.Bottom;
  447. if (isProportionalScaling)
  448. {
  449. Size size = GetProportionalScalingSize(right - left, bottom - top);
  450. right = left + size.Width;
  451. top = bottom - size.Height;
  452. if (right > maxRect.Right)
  453. {
  454. double tmpWidth = right - left;
  455. right = maxRect.Right;
  456. double width = right - left;
  457. double height = (bottom - top) * width / tmpWidth;
  458. top = bottom - height;
  459. }
  460. if (top < maxRect.Top)
  461. {
  462. double tmpHeight = bottom - top;
  463. top = maxRect.Top;
  464. double height = bottom - top;
  465. double width = (right - left) * height / tmpHeight;
  466. right = left + width;
  467. }
  468. }
  469. else
  470. {
  471. if (left + minWidth > right)
  472. {
  473. right = left + minWidth;
  474. }
  475. if (top + minHeight > bottom)
  476. {
  477. top = bottom - minHeight;
  478. }
  479. }
  480. }
  481. break;
  482. case PointControlType.MiddleTop:
  483. {
  484. left = cacheRect.Left;
  485. right = cacheRect.Right;
  486. top = centerPoint.Y + moveVector.Y;
  487. bottom = cacheRect.Bottom;
  488. if (top + minHeight > bottom)
  489. {
  490. top = bottom - minHeight;
  491. }
  492. }
  493. break;
  494. case PointControlType.Body:
  495. case PointControlType.Line:
  496. {
  497. Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), maxRect);
  498. left = cacheRect.Left + OffsetPos.X;
  499. right = cacheRect.Right + OffsetPos.X;
  500. top = cacheRect.Top + OffsetPos.Y;
  501. bottom = cacheRect.Bottom + OffsetPos.Y;
  502. }
  503. break;
  504. default:
  505. break;
  506. }
  507. if (left < maxRect.Left)
  508. {
  509. left = maxRect.Left;
  510. }
  511. if (top < maxRect.Top)
  512. {
  513. top = maxRect.Top;
  514. }
  515. if (right > maxRect.Right)
  516. {
  517. right = maxRect.Right;
  518. }
  519. if (bottom > maxRect.Bottom)
  520. {
  521. bottom = maxRect.Bottom;
  522. }
  523. drawRect = new Rect(left, top, right - left, bottom - top);
  524. moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
  525. return true;
  526. }
  527. catch (Exception ex)
  528. {
  529. }
  530. return false;
  531. }
  532. /// <summary>
  533. /// Provisional logic, to be further improved, not yet used: Draw the algorithm in the form of normal scaling (drag a point, only scale in one direction).
  534. /// </summary>
  535. /// <param name="mousePoint">Current mouse position.</param>
  536. /// <returns></returns>
  537. protected bool OutSideScaling(Point mousePoint)
  538. {
  539. try
  540. {
  541. double left = 0, right = 0, top = 0, bottom = 0;
  542. double minHeight = RectMinHeight + 2 * rectPadding * currentZoom;
  543. double minWidth = rectMinWidth + 2 * rectPadding * currentZoom;
  544. Point centerPoint = new Point((cacheRect.Right + cacheRect.Left) / 2, (cacheRect.Bottom + cacheRect.Top) / 2);
  545. Point moveVector = (Point)(mousePoint - centerPoint);
  546. moveVector = ProportionalScalingOffsetPos(moveVector);
  547. switch (hitControlType)
  548. {
  549. case PointControlType.LeftTop:
  550. {
  551. left = centerPoint.X + moveVector.X;
  552. right = cacheRect.Right;
  553. top = centerPoint.Y + moveVector.Y;
  554. bottom = cacheRect.Bottom;
  555. if (isProportionalScaling)
  556. {
  557. Size size = GetProportionalScalingSize(right - left, bottom - top);
  558. left = right - size.Width;
  559. top = bottom - size.Height;
  560. if (left < maxRect.Left)
  561. {
  562. double tmpWidth = right - left;
  563. left = maxRect.Left;
  564. double width = right - left;
  565. double height = (bottom - top) * width / tmpWidth;
  566. top = bottom - height;
  567. }
  568. if (top < maxRect.Top)
  569. {
  570. double tmpHeight = bottom - top;
  571. top = maxRect.Top;
  572. double height = bottom - top;
  573. double width = (right - left) * height / tmpHeight;
  574. left = right - width;
  575. }
  576. }
  577. else
  578. {
  579. if (left + minWidth > right)
  580. {
  581. left = right - minWidth;
  582. }
  583. if (top + minHeight > bottom)
  584. {
  585. top = bottom - minHeight;
  586. }
  587. }
  588. }
  589. break;
  590. case PointControlType.LeftMiddle:
  591. {
  592. left = centerPoint.X + moveVector.X;
  593. right = cacheRect.Right;
  594. top = cacheRect.Top;
  595. bottom = cacheRect.Bottom;
  596. if (left + minWidth > right)
  597. {
  598. left = right - minWidth;
  599. }
  600. }
  601. break;
  602. case PointControlType.LeftBottom:
  603. {
  604. left = centerPoint.X + moveVector.X;
  605. right = cacheRect.Right;
  606. top = cacheRect.Top;
  607. bottom = centerPoint.Y + moveVector.Y;
  608. if (isProportionalScaling)
  609. {
  610. Size size = GetProportionalScalingSize(right - left, bottom - top);
  611. left = right - size.Width;
  612. bottom = top + size.Height;
  613. if (left < maxRect.Left)
  614. {
  615. double tmpWidth = right - left;
  616. left = maxRect.Left;
  617. double width = right - left;
  618. double height = (bottom - top) * width / tmpWidth;
  619. bottom = top + height;
  620. }
  621. if (bottom > maxRect.Bottom)
  622. {
  623. double tmpHeight = bottom - top;
  624. bottom = maxRect.Bottom;
  625. double height = bottom - top;
  626. double width = (right - left) * height / tmpHeight;
  627. left = right - width;
  628. }
  629. }
  630. else
  631. {
  632. if (left + minWidth > right)
  633. {
  634. left = right - minWidth;
  635. }
  636. if (top + minHeight > bottom)
  637. {
  638. bottom = top + minHeight;
  639. }
  640. }
  641. }
  642. break;
  643. case PointControlType.MiddleBottom:
  644. {
  645. left = cacheRect.Left;
  646. right = cacheRect.Right;
  647. top = cacheRect.Top;
  648. bottom = centerPoint.Y + moveVector.Y;
  649. if (top + minHeight > bottom)
  650. {
  651. bottom = top + minHeight;
  652. }
  653. }
  654. break;
  655. case PointControlType.RightBottom:
  656. {
  657. left = cacheRect.Left;
  658. right = centerPoint.X + moveVector.X;
  659. top = cacheRect.Top;
  660. bottom = centerPoint.Y + moveVector.Y;
  661. if (isProportionalScaling)
  662. {
  663. Size size = GetProportionalScalingSize(right - left, bottom - top);
  664. right = left + size.Width;
  665. bottom = top + size.Height;
  666. if (right > maxRect.Right)
  667. {
  668. double tmpWidth = right - left;
  669. right = maxRect.Right;
  670. double width = right - left;
  671. double height = (bottom - top) * width / tmpWidth;
  672. bottom = top + height;
  673. }
  674. if (bottom > maxRect.Bottom)
  675. {
  676. double tmpHeight = bottom - top;
  677. bottom = maxRect.Bottom;
  678. double height = bottom - top;
  679. double width = (right - left) * height / tmpHeight;
  680. right = left + width;
  681. }
  682. }
  683. else
  684. {
  685. if (left + minWidth > right)
  686. {
  687. right = left + minWidth;
  688. }
  689. if (top + minHeight > bottom)
  690. {
  691. bottom = top + minHeight;
  692. }
  693. }
  694. }
  695. break;
  696. case PointControlType.RightMiddle:
  697. {
  698. left = cacheRect.Left;
  699. right = centerPoint.X + moveVector.X;
  700. top = cacheRect.Top;
  701. bottom = cacheRect.Bottom;
  702. if (left + minWidth > right)
  703. {
  704. right = left + minWidth;
  705. }
  706. }
  707. break;
  708. case PointControlType.RightTop:
  709. {
  710. left = cacheRect.Left;
  711. right = centerPoint.X + moveVector.X;
  712. top = centerPoint.Y + moveVector.Y;
  713. bottom = cacheRect.Bottom;
  714. if (isProportionalScaling)
  715. {
  716. Size size = GetProportionalScalingSize(right - left, bottom - top);
  717. right = left + size.Width;
  718. top = bottom - size.Height;
  719. if (right > maxRect.Right)
  720. {
  721. double tmpWidth = right - left;
  722. right = maxRect.Right;
  723. double width = right - left;
  724. double height = (bottom - top) * width / tmpWidth;
  725. top = bottom - height;
  726. }
  727. if (top < maxRect.Top)
  728. {
  729. double tmpHeight = bottom - top;
  730. top = maxRect.Top;
  731. double height = bottom - top;
  732. double width = (right - left) * height / tmpHeight;
  733. right = left + width;
  734. }
  735. }
  736. else
  737. {
  738. if (left + minWidth > right)
  739. {
  740. right = left + minWidth;
  741. }
  742. if (top + minHeight > bottom)
  743. {
  744. top = bottom - minHeight;
  745. }
  746. }
  747. }
  748. break;
  749. case PointControlType.MiddleTop:
  750. {
  751. left = cacheRect.Left;
  752. right = cacheRect.Right;
  753. top = centerPoint.Y + moveVector.Y;
  754. bottom = cacheRect.Bottom;
  755. if (top + minHeight > bottom)
  756. {
  757. top = bottom - minHeight;
  758. }
  759. }
  760. break;
  761. case PointControlType.Body:
  762. case PointControlType.Line:
  763. {
  764. double newleft = maxRect.Left - SetDrawRect.Width + 10;
  765. double newright = maxRect.Right + SetDrawRect.Width - 10;
  766. double newtop = maxRect.Top - SetDrawRect.Height + 10;
  767. double newbottom = maxRect.Bottom + SetDrawRect.Height - 10;
  768. if (newleft < 0)
  769. {
  770. newleft = 0;
  771. }
  772. Rect newMaxRect = new Rect(newleft, newtop, newright - newleft, newbottom - newtop);
  773. Point OffsetPos = CalcMoveBound(cacheRect, ((Point)(mousePoint - mouseDownPoint)), newMaxRect);
  774. left = cacheRect.Left + OffsetPos.X;
  775. right = cacheRect.Right + OffsetPos.X;
  776. top = cacheRect.Top + OffsetPos.Y;
  777. bottom = cacheRect.Bottom + OffsetPos.Y;
  778. }
  779. break;
  780. default:
  781. break;
  782. }
  783. //if (left < maxRect.Left)
  784. //{
  785. // left = maxRect.Left;
  786. //}
  787. //if (top < maxRect.Top)
  788. //{
  789. // top = maxRect.Top;
  790. //}
  791. if (right > maxRect.Right + SetDrawRect.Width - 10)
  792. {
  793. if (left > maxRect.Right - 10)
  794. {
  795. left = maxRect.Right - 10;
  796. }
  797. right = maxRect.Right + SetDrawRect.Width - 10;
  798. }
  799. if (bottom > maxRect.Bottom + SetDrawRect.Height - 10)
  800. {
  801. if (top > maxRect.Bottom - 10)
  802. {
  803. top = maxRect.Bottom - 10;
  804. }
  805. bottom = maxRect.Bottom + SetDrawRect.Height - 10;
  806. }
  807. drawRect = new Rect(left, top, right - left, bottom - top);
  808. moveOffset = new Point(drawRect.X - cacheRect.X, drawRect.Y - cacheRect.Y);
  809. return true;
  810. }
  811. catch (Exception ex)
  812. {
  813. }
  814. return false;
  815. }
  816. /// <summary>
  817. /// Proportional scaling offset calibration
  818. /// </summary>
  819. /// <param name="movePoint">
  820. /// The current movement point
  821. /// </param>
  822. /// <returns>
  823. /// The offset point after the proportional scaling
  824. /// </returns>
  825. protected Point ProportionalScalingOffsetPos(Point movePoint)
  826. {
  827. if (isProportionalScaling)
  828. {
  829. Point offsetPos = movePoint;
  830. double ratioX = cacheRect.Width > 0 ? cacheRect.Height / cacheRect.Width : 1;
  831. double ratioY = cacheRect.Height > 0 ? cacheRect.Width / cacheRect.Height : 1;
  832. switch (hitControlType)
  833. {
  834. case PointControlType.LeftTop:
  835. case PointControlType.RightBottom:
  836. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
  837. break;
  838. case PointControlType.LeftBottom:
  839. case PointControlType.RightTop:
  840. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
  841. break;
  842. case PointControlType.LeftMiddle:
  843. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? 1 : -1));
  844. break;
  845. case PointControlType.RightMiddle:
  846. offsetPos = new Point(movePoint.X, Math.Abs(movePoint.X) * ratioX * (movePoint.X < 0 ? -1 : 1));
  847. break;
  848. case PointControlType.MiddleBottom:
  849. offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? 1 : -1), movePoint.Y);
  850. break;
  851. case PointControlType.MiddleTop:
  852. offsetPos = new Point(Math.Abs(movePoint.Y) * ratioY * (movePoint.Y < 0 ? -1 : 1), movePoint.Y);
  853. break;
  854. default:
  855. break;
  856. }
  857. return offsetPos;
  858. }
  859. else
  860. {
  861. return movePoint;
  862. }
  863. }
  864. /// <summary>
  865. /// Inner drawing circle point
  866. /// </summary>
  867. /// <param name="drawingContext">
  868. /// Drawing context
  869. /// </param>
  870. /// <param name="ignoreList">
  871. /// Collection of positions that need to be drawn
  872. /// </param>
  873. /// <param name="PointSize">
  874. /// Size of the point
  875. /// </param>
  876. /// <param name="PointPen">
  877. /// Brush for drawing points
  878. /// </param>
  879. /// <param name="BorderBrush">
  880. /// Border brush for drawing points
  881. /// </param>
  882. protected void DrawCirclePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  883. {
  884. GeometryGroup controlGroup = new GeometryGroup();
  885. controlGroup.FillRule = FillRule.Nonzero;
  886. List<Point> ignorePointsList = new List<Point>();
  887. // Get specific points
  888. foreach (PointControlType type in ignoreList)
  889. {
  890. if ((int)type < controlPoints.Count)
  891. {
  892. ignorePointsList.Add(controlPoints[(int)type]);
  893. }
  894. }
  895. for (int i = 0; i < controlPoints.Count; i++)
  896. {
  897. Point controlPoint = controlPoints[i];
  898. if (ignorePointsList.Contains(controlPoint))
  899. {
  900. continue;
  901. }
  902. EllipseGeometry circlPoint = new EllipseGeometry(controlPoint, PointSize, PointSize);
  903. controlGroup.Children.Add(circlPoint);
  904. }
  905. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  906. }
  907. /// <summary>
  908. /// Inner drawing square
  909. /// </summary>
  910. /// <param name="drawingContext">
  911. /// Drawing context
  912. /// </param>
  913. /// <param name="ControlPoints">
  914. /// Collection of positions that need to be drawn
  915. /// </param>
  916. /// <param name="PointSize">
  917. /// Size of the point
  918. /// </param>
  919. /// <param name="PointPen">
  920. /// Brush for drawing points
  921. /// </param>
  922. /// <param name="BorderBrush">
  923. /// Border brush for drawing points
  924. /// </param>
  925. protected void DrawSquarePoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  926. {
  927. RotateTransform rotateTransform = new RotateTransform(rotateAngle, centerPoint.X, centerPoint.Y);
  928. if (canRotation && !isInScaling)
  929. {
  930. Point currentRotationPoint = isInRotate ? dragRotationPoint : rotationPoint;
  931. GeometryGroup rotateGroup = new GeometryGroup();
  932. double angleInRadians = rotateAngle * (Math.PI / 180);
  933. double sinValue = Math.Sin(angleInRadians);
  934. double cosValue = Math.Cos(angleInRadians);
  935. double rotatedX = currentRotationPoint.X - pointSize * sinValue;
  936. double rotatedY = currentRotationPoint.Y + pointSize * cosValue;
  937. LineGeometry moveLineGeometry = new LineGeometry(centerPoint, new Point(rotatedX, rotatedY));
  938. EllipseGeometry ellipseGeometry = new EllipseGeometry(currentRotationPoint, PointSize, pointSize);
  939. rotateGroup.Children.Add(moveLineGeometry);
  940. rotateGroup.Children.Add(ellipseGeometry);
  941. if (!isInRotate)
  942. {
  943. rotateGroup.Children.Remove(moveLineGeometry);
  944. LineGeometry stopLineGeometry = new LineGeometry(centerPoint, new Point(currentRotationPoint.X, currentRotationPoint.Y + pointSize));
  945. rotateGroup.Children.Add(stopLineGeometry);
  946. drawingContext.PushTransform(rotateTransform);
  947. }
  948. drawingContext?.DrawGeometry(BorderBrush, PointPen, rotateGroup);
  949. if (!isInRotate)
  950. {
  951. drawingContext.Pop();
  952. }
  953. }
  954. if (!isInRotate)
  955. {
  956. GeometryGroup controlGroup = new GeometryGroup();
  957. controlGroup.FillRule = FillRule.Nonzero;
  958. List<Point> ignorePointsList = new List<Point>();
  959. // Get specific points
  960. foreach (PointControlType type in ignoreList)
  961. {
  962. if ((int)type < controlPoints.Count)
  963. {
  964. ignorePointsList.Add(controlPoints[(int)type]);
  965. }
  966. }
  967. for (int i = 0; i < controlPoints.Count; i++)
  968. {
  969. Point controlPoint = controlPoints[i];
  970. if (ignorePointsList.Contains(controlPoint))
  971. {
  972. continue;
  973. }
  974. RectangleGeometry rectPoint = new RectangleGeometry(new Rect(controlPoint.X - PointSize, controlPoint.Y - PointSize,
  975. PointSize * 2, PointSize * 2), 1, 1);
  976. controlGroup.Children.Add(rectPoint);
  977. }
  978. drawingContext.PushTransform(rotateTransform);
  979. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  980. drawingContext.Pop();
  981. }
  982. }
  983. protected void DrawCropPoint(DrawingContext drawingContext, List<PointControlType> ignoreList, int PointSize, Pen PointPen, SolidColorBrush BorderBrush)
  984. {
  985. //GeometryGroup controlGroup = new GeometryGroup();
  986. //controlGroup.FillRule = FillRule.Nonzero;
  987. clipThickness.Left = (SetDrawRect.Left - drawRect.Left) / currentZoom;
  988. clipThickness.Top = (SetDrawRect.Top - drawRect.Top) / currentZoom;
  989. clipThickness.Right = (SetDrawRect.Right - drawRect.Right) / currentZoom;
  990. clipThickness.Bottom = (SetDrawRect.Bottom - drawRect.Bottom) / currentZoom;
  991. List<Point> controlCurrentPoints = GetControlPoint(drawRect);
  992. CombinedGeometry controlGroup = new CombinedGeometry();
  993. RectangleGeometry paintGeometry = new RectangleGeometry();
  994. paintGeometry.Rect = SetDrawRect;
  995. controlGroup.Geometry1 = paintGeometry;
  996. RectangleGeometry moveGeometry = new RectangleGeometry();
  997. Rect clippedBorder = drawRect;
  998. if (clippedBorder.IsEmpty == false)
  999. {
  1000. moveGeometry.Rect = drawRect;
  1001. }
  1002. controlGroup.Geometry2 = moveGeometry;
  1003. controlGroup.GeometryCombineMode = GeometryCombineMode.Exclude;
  1004. //Left Top Corner
  1005. if (!ignoreList.Contains(PointControlType.LeftTop))
  1006. {
  1007. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[0].X - PointSize, controlCurrentPoints[0].Y - PointSize, PointSize, PointSize * 4));
  1008. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[0].X - PointSize, controlCurrentPoints[0].Y - PointSize, PointSize * 4, PointSize));
  1009. }
  1010. //Left Center
  1011. if (!ignoreList.Contains(PointControlType.LeftMiddle))
  1012. {
  1013. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[1].X - PointSize, (controlCurrentPoints[1].Y + controlCurrentPoints[1].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
  1014. }
  1015. //Left Bottom Corner
  1016. if (!ignoreList.Contains(PointControlType.LeftBottom))
  1017. {
  1018. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[2].X - PointSize, controlCurrentPoints[2].Y - PointSize * 3, PointSize, PointSize * 4));
  1019. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[2].X - PointSize, controlCurrentPoints[2].Y, PointSize * 4, PointSize));
  1020. }
  1021. //Bottom Center
  1022. if (!ignoreList.Contains(PointControlType.MiddleBottom))
  1023. {
  1024. drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlCurrentPoints[3].X + controlCurrentPoints[3].X - PointSize * 5) / 2, controlCurrentPoints[3].Y, PointSize * 5, PointSize));
  1025. }
  1026. //Bottom Right Corner
  1027. if (!ignoreList.Contains(PointControlType.RightBottom))
  1028. {
  1029. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[4].X, controlCurrentPoints[4].Y - PointSize * 3, PointSize, PointSize * 4));
  1030. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[4].X - PointSize * 3, controlCurrentPoints[4].Y, PointSize * 4, PointSize));
  1031. }
  1032. //Right Center
  1033. if (!ignoreList.Contains(PointControlType.RightMiddle))
  1034. {
  1035. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[5].X, (controlCurrentPoints[5].Y + controlCurrentPoints[5].Y - PointSize * 5) / 2, PointSize, PointSize * 5));
  1036. }
  1037. //Right Top Corner
  1038. if (!ignoreList.Contains(PointControlType.RightTop))
  1039. {
  1040. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[6].X, controlCurrentPoints[6].Y - PointSize, PointSize, PointSize * 4));
  1041. drawingContext?.DrawRectangle(BorderBrush, null, new Rect(controlCurrentPoints[6].X - PointSize * 4, controlCurrentPoints[6].Y - PointSize, PointSize * 4, PointSize));
  1042. }
  1043. //Top Center
  1044. if (!ignoreList.Contains(PointControlType.MiddleTop))
  1045. {
  1046. drawingContext?.DrawRectangle(BorderBrush, null, new Rect((controlCurrentPoints[7].X + controlCurrentPoints[7].X - PointSize * 5) / 2, controlCurrentPoints[7].Y - PointSize, PointSize * 5, PointSize));
  1047. }
  1048. BorderBrush = new SolidColorBrush(Color.FromArgb(0x3F, 0x00, 0x00, 0x00));
  1049. drawingContext?.DrawGeometry(BorderBrush, PointPen, controlGroup);
  1050. }
  1051. /// <summary>
  1052. /// Draw the reference line in the moving state
  1053. /// </summary>
  1054. /// <param name="drawDc">
  1055. /// Draw context handle
  1056. /// </param>
  1057. /// <param name="controltype">
  1058. /// Current selected control point type
  1059. /// </param>
  1060. /// <param name="activePen">
  1061. /// Brush for drawing lines
  1062. /// </param>
  1063. /// <param name="moveBrush">
  1064. /// Brush for drawing rectangles
  1065. /// </param>
  1066. /// <param name="moveRect">
  1067. /// Current rectangle to draw
  1068. /// </param>
  1069. protected void DrawMoveBounds(DrawingContext drawDc, PointControlType controltype, Pen activePen, Brush moveBrush, Rect moveRect, Pen RectPen = null)
  1070. {
  1071. switch (controltype)
  1072. {
  1073. case PointControlType.LeftTop:
  1074. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  1075. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  1076. break;
  1077. case PointControlType.LeftMiddle:
  1078. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  1079. break;
  1080. case PointControlType.LeftBottom:
  1081. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  1082. drawDc?.DrawLine(activePen, new Point(moveRect.Left, 0), new Point(moveRect.Left, PDFViewerActualHeight));
  1083. break;
  1084. case PointControlType.MiddleBottom:
  1085. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  1086. break;
  1087. case PointControlType.RightBottom:
  1088. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  1089. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  1090. break;
  1091. case PointControlType.RightMiddle:
  1092. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  1093. break;
  1094. case PointControlType.RightTop:
  1095. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  1096. drawDc?.DrawLine(activePen, new Point(moveRect.Right, 0), new Point(moveRect.Right, PDFViewerActualHeight));
  1097. break;
  1098. case PointControlType.MiddleTop:
  1099. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  1100. break;
  1101. case PointControlType.Rotate:
  1102. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(moveRect.Left, moveRect.Top));
  1103. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  1104. drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Top), new Point(moveRect.Left, 0));
  1105. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(moveRect.Right, 0));
  1106. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(moveRect.Left, moveRect.Bottom));
  1107. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  1108. drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Bottom), new Point(moveRect.Left, PDFViewerActualHeight));
  1109. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(moveRect.Right, PDFViewerActualHeight));
  1110. break;
  1111. case PointControlType.Body:
  1112. case PointControlType.Line:
  1113. drawDc?.DrawLine(activePen, new Point(0, moveRect.Top), new Point(moveRect.Left, moveRect.Top));
  1114. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(PDFViewerActualWidth, moveRect.Top));
  1115. drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Top), new Point(moveRect.Left, 0));
  1116. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Top), new Point(moveRect.Right, 0));
  1117. drawDc?.DrawLine(activePen, new Point(0, moveRect.Bottom), new Point(moveRect.Left, moveRect.Bottom));
  1118. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(PDFViewerActualWidth, moveRect.Bottom));
  1119. drawDc?.DrawLine(activePen, new Point(moveRect.Left, moveRect.Bottom), new Point(moveRect.Left, PDFViewerActualHeight));
  1120. drawDc?.DrawLine(activePen, new Point(moveRect.Right, moveRect.Bottom), new Point(moveRect.Right, PDFViewerActualHeight));
  1121. break;
  1122. default:
  1123. break;
  1124. }
  1125. drawDc?.DrawRectangle(moveBrush, RectPen, moveRect);
  1126. }
  1127. /// <summary>
  1128. /// Notify the event during/after the drawing data
  1129. /// </summary>
  1130. /// <param name="isFinish">
  1131. /// Identifies whether the data change is complete
  1132. /// </param>
  1133. protected void InvokeDataChangEvent(bool isFinish)
  1134. {
  1135. selectedRectData.Square = GetRect();
  1136. selectedRectData.rotationAngle = rotateAngle;
  1137. if (isFinish)
  1138. {
  1139. DataChanged?.Invoke(this, selectedRectData);
  1140. }
  1141. else
  1142. {
  1143. DataChanging?.Invoke(this, selectedRectData);
  1144. }
  1145. }
  1146. /// <summary>
  1147. /// Align the rectangle drawing
  1148. /// </summary>
  1149. /// <param name="RectMovePoint">
  1150. /// Move distance required for the aligned algorithm to obtain the rectangle
  1151. /// </param>
  1152. private void DrawAlignRect(Point RectMovePoint)
  1153. {
  1154. double TmpLeft, TmpRight, TmpUp, TmpDown;
  1155. Point OffsetPos = CalcMoveBound(drawRect, RectMovePoint, maxRect);
  1156. TmpLeft = drawRect.Left + OffsetPos.X;
  1157. TmpRight = drawRect.Right + OffsetPos.X;
  1158. TmpUp = drawRect.Top + OffsetPos.Y;
  1159. TmpDown = drawRect.Bottom + OffsetPos.Y;
  1160. SetDrawRect = drawRect = new Rect(TmpLeft, TmpUp, TmpRight - TmpLeft, TmpDown - TmpUp);
  1161. Draw();
  1162. }
  1163. /// <summary>
  1164. /// Get the current set of ignore points
  1165. /// </summary>
  1166. /// <returns>
  1167. /// Data set of ignored points
  1168. /// </returns>
  1169. private List<PointControlType> GetIgnorePoints()
  1170. {
  1171. List<PointControlType> IgnorePointsList = new List<PointControlType>();
  1172. foreach (PointControlType type in ignorePoints)
  1173. {
  1174. IgnorePointsList.Add(type);
  1175. }
  1176. return IgnorePointsList;
  1177. }
  1178. #endregion
  1179. }
  1180. }