CommonHelper.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using Microsoft.Win32;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Reflection;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Media;
  11. namespace Compdfkit_Tools.Helper
  12. {
  13. public static class CommonHelper
  14. {
  15. /// <summary>
  16. /// Returns the file size based on the specified file path, with the smallest unit being bytes (B).
  17. /// </summary>
  18. /// <param name="filePath">The path to the file.</param>
  19. /// <returns>
  20. /// The calculated file size, with units in bytes (B), kilobytes (KB), megabytes (MB), or gigabytes (GB).
  21. /// </returns>
  22. public static string GetFileSize(string filePath)
  23. {
  24. FileInfo fileInfo = null;
  25. try
  26. {
  27. fileInfo = new FileInfo(filePath);
  28. }
  29. catch
  30. {
  31. return "0B";
  32. }
  33. if (fileInfo != null && fileInfo.Exists)
  34. {
  35. double fileSize = fileInfo.Length;
  36. if (fileSize > 1024)
  37. {
  38. fileSize = Math.Round(fileSize / 1024, 2);
  39. if (fileSize > 1024)
  40. {
  41. fileSize = Math.Round(fileSize / 1024, 2);
  42. if (fileSize > 1024)
  43. {
  44. fileSize = Math.Round(fileSize / 1024, 2);
  45. return fileSize + " GB";
  46. }
  47. else
  48. {
  49. return fileSize + " MB";
  50. }
  51. }
  52. else
  53. {
  54. return fileSize + " KB";
  55. }
  56. }
  57. else
  58. {
  59. return fileSize + " B";
  60. }
  61. }
  62. return "0B";
  63. }
  64. public static string GetFilePathOrEmpty()
  65. {
  66. string selectedFilePath = string.Empty;
  67. OpenFileDialog openFileDialog = new OpenFileDialog();
  68. openFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
  69. if (openFileDialog.ShowDialog() == true)
  70. {
  71. selectedFilePath = openFileDialog.FileName;
  72. }
  73. return selectedFilePath;
  74. }
  75. public static bool GetPagesInRange(ref List<int> pageList, string pageRange, int count, char[] enumerationSeparator, char[] rangeSeparator, bool inittag = false)
  76. {
  77. string[] rangeSplit = pageRange.Split(enumerationSeparator);
  78. pageList.Clear();
  79. foreach (string range in rangeSplit)
  80. {
  81. int starttag = 1;
  82. if (inittag)
  83. {
  84. starttag = 0;
  85. }
  86. if (range.Contains("-"))
  87. {
  88. try
  89. {
  90. string[] limits = range.Split(rangeSeparator);
  91. if (limits.Length >= 2 && !string.IsNullOrWhiteSpace(limits[0]) && !string.IsNullOrWhiteSpace(limits[1]))
  92. {
  93. int start = int.Parse(limits[0]);
  94. int end = int.Parse(limits[1]);
  95. if ((start < starttag) || (end > count) || (start > end))
  96. {
  97. return false;
  98. }
  99. for (int i = start; i <= end; ++i)
  100. {
  101. if (pageList.Contains(i))
  102. {
  103. return false;
  104. }
  105. pageList.Add(i - 1);
  106. }
  107. continue;
  108. }
  109. }
  110. catch (Exception ex)
  111. {
  112. return false;
  113. }
  114. }
  115. int pageNr;
  116. try
  117. {
  118. pageNr = int.Parse(range);
  119. }
  120. catch (Exception)
  121. {
  122. return false;
  123. }
  124. if (pageNr < starttag || pageNr > count)
  125. {
  126. return false;
  127. }
  128. if (pageList.Contains(pageNr))
  129. {
  130. return false;
  131. }
  132. pageList.Add(pageNr - 1);
  133. }
  134. return true;
  135. }
  136. internal static class PageEditHelper
  137. {
  138. public static T FindVisualParent<T>(DependencyObject obj) where T : class
  139. {
  140. while (obj != null)
  141. {
  142. if (obj is T)
  143. return obj as T;
  144. obj = VisualTreeHelper.GetParent(obj);
  145. }
  146. return null;
  147. }
  148. public static childItem FindVisualChild<childItem>(DependencyObject obj)
  149. where childItem : DependencyObject
  150. {
  151. for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
  152. {
  153. DependencyObject child = VisualTreeHelper.GetChild(obj, i);
  154. if (child != null && child is childItem)
  155. return (childItem)child;
  156. else
  157. {
  158. childItem childOfChild = FindVisualChild<childItem>(child);
  159. if (childOfChild != null)
  160. return childOfChild;
  161. }
  162. }
  163. return null;
  164. }
  165. }
  166. public static class ViewportHelper
  167. {
  168. public static CPDFDocument CopyDoc;
  169. public static bool IsInViewport(ScrollViewer sv, Control item)
  170. {
  171. if (item == null) return false;
  172. ItemsControl itemsControl = null;
  173. if (item is ListBoxItem)
  174. itemsControl = ItemsControl.ItemsControlFromItemContainer(item) as ListBox;
  175. else
  176. throw new NotSupportedException(item.GetType().Name);
  177. ScrollContentPresenter scrollContentPresenter = (ScrollContentPresenter)sv.Template.FindName("PART_ScrollContentPresenter", sv);
  178. MethodInfo isInViewportMethod = sv.GetType().GetMethod("IsInViewport", BindingFlags.NonPublic | BindingFlags.Instance);
  179. return (bool)isInViewportMethod.Invoke(sv, new object[] { scrollContentPresenter, item });
  180. }
  181. public static T FindVisualParent<T>(DependencyObject obj) where T : class
  182. {
  183. while (obj != null)
  184. {
  185. if (obj is T)
  186. return obj as T;
  187. obj = VisualTreeHelper.GetParent(obj);
  188. }
  189. return null;
  190. }
  191. public static childItem FindVisualChild<childItem>(DependencyObject obj)
  192. where childItem : DependencyObject
  193. {
  194. for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
  195. {
  196. DependencyObject child = VisualTreeHelper.GetChild(obj, i);
  197. if (child != null && child is childItem)
  198. return (childItem)child;
  199. else
  200. {
  201. childItem childOfChild = FindVisualChild<childItem>(child);
  202. if (childOfChild != null)
  203. return childOfChild;
  204. }
  205. }
  206. return null;
  207. }
  208. }
  209. public class ArrowHelper
  210. {
  211. public bool HasStartArrow
  212. {
  213. get
  214. {
  215. if (StartSharp != C_LINE_TYPE.LINETYPE_UNKNOWN && StartSharp != C_LINE_TYPE.LINETYPE_NONE)
  216. {
  217. return true;
  218. }
  219. return false;
  220. }
  221. }
  222. public bool IsStartClosed
  223. {
  224. get
  225. {
  226. if (StartSharp == C_LINE_TYPE.LINETYPE_CLOSEDARROW || StartSharp == C_LINE_TYPE.LINETYPE_RCLOSEDARROW || StartSharp == C_LINE_TYPE.LINETYPE_DIAMOND)
  227. {
  228. return true;
  229. }
  230. return false;
  231. }
  232. }
  233. public bool HasEndArrow
  234. {
  235. get
  236. {
  237. if (EndSharp != C_LINE_TYPE.LINETYPE_UNKNOWN && EndSharp != C_LINE_TYPE.LINETYPE_NONE)
  238. {
  239. return true;
  240. }
  241. return false;
  242. }
  243. }
  244. public bool IsEndClosed
  245. {
  246. get
  247. {
  248. if (EndSharp == C_LINE_TYPE.LINETYPE_CLOSEDARROW || EndSharp == C_LINE_TYPE.LINETYPE_RCLOSEDARROW || EndSharp == C_LINE_TYPE.LINETYPE_DIAMOND)
  249. {
  250. return true;
  251. }
  252. return false;
  253. }
  254. }
  255. public uint ArrowAngle { get; set; }
  256. public uint ArrowLength { get; set; }
  257. public Point? LineStart { get; set; }
  258. public Point? LineEnd { get; set; }
  259. public PathGeometry Body { get; set; }
  260. public C_LINE_TYPE StartSharp { get; set; }
  261. public C_LINE_TYPE EndSharp { get; set; }
  262. public ArrowHelper()
  263. {
  264. Body = new PathGeometry();
  265. ArrowLength = 12;
  266. ArrowAngle = 60;
  267. }
  268. protected PathFigure CreateLineBody()
  269. {
  270. if (LineStart != null && LineEnd != null)
  271. {
  272. PathFigure lineFigure = new PathFigure();
  273. lineFigure.StartPoint = (Point)LineStart;
  274. LineSegment linePath = new LineSegment();
  275. linePath.Point = (Point)LineEnd;
  276. lineFigure.Segments.Add(linePath);
  277. return lineFigure;
  278. }
  279. return null;
  280. }
  281. protected PathFigure CreateStartArrow()
  282. {
  283. switch (StartSharp)
  284. {
  285. case C_LINE_TYPE.LINETYPE_NONE:
  286. case C_LINE_TYPE.LINETYPE_UNKNOWN:
  287. break;
  288. case C_LINE_TYPE.LINETYPE_ARROW:
  289. case C_LINE_TYPE.LINETYPE_CLOSEDARROW:
  290. return CreateStartOpenArrow();
  291. case C_LINE_TYPE.LINETYPE_ROPENARROW:
  292. case C_LINE_TYPE.LINETYPE_RCLOSEDARROW:
  293. return CreateStartReverseArrow();
  294. case C_LINE_TYPE.LINETYPE_BUTT:
  295. return CreateStartButtArrow();
  296. case C_LINE_TYPE.LINETYPE_DIAMOND:
  297. return CreateStartDiamondArrow();
  298. case C_LINE_TYPE.LINETYPE_CIRCLE:
  299. return CreateStartRoundArrow();
  300. case C_LINE_TYPE.LINETYPE_SQUARE:
  301. return CreateStartSquareArrow();
  302. case C_LINE_TYPE.LINETYPE_SLASH:
  303. return CreateStartSlashArrow();
  304. default:
  305. break;
  306. }
  307. return null;
  308. }
  309. protected virtual PathFigure CreateEndArrow()
  310. {
  311. switch (EndSharp)
  312. {
  313. case C_LINE_TYPE.LINETYPE_NONE:
  314. case C_LINE_TYPE.LINETYPE_UNKNOWN:
  315. break;
  316. case C_LINE_TYPE.LINETYPE_ARROW:
  317. case C_LINE_TYPE.LINETYPE_CLOSEDARROW:
  318. return CreateEndOpenArrow();
  319. case C_LINE_TYPE.LINETYPE_ROPENARROW:
  320. case C_LINE_TYPE.LINETYPE_RCLOSEDARROW:
  321. return CreateEndReverseArrow();
  322. case C_LINE_TYPE.LINETYPE_BUTT:
  323. return CreateEndButtArrow();
  324. case C_LINE_TYPE.LINETYPE_DIAMOND:
  325. return CreateEndDiamondArrow();
  326. case C_LINE_TYPE.LINETYPE_CIRCLE:
  327. return CreateEndRoundArrow();
  328. case C_LINE_TYPE.LINETYPE_SQUARE:
  329. return CreateEndSquareArrow();
  330. case C_LINE_TYPE.LINETYPE_SLASH:
  331. return CreateEndSlashArrow();
  332. default:
  333. break;
  334. }
  335. return null;
  336. }
  337. public PathGeometry BuildArrowBody()
  338. {
  339. Body.Figures.Clear();
  340. PathFigure lineBody = CreateLineBody();
  341. if (lineBody != null)
  342. {
  343. Body.Figures.Add(lineBody);
  344. PathFigure arrowFigure = CreateStartArrow();
  345. if (arrowFigure != null)
  346. {
  347. Body.Figures.Add(arrowFigure);
  348. }
  349. arrowFigure = CreateEndArrow();
  350. if (arrowFigure != null)
  351. {
  352. Body.Figures.Add(arrowFigure);
  353. }
  354. }
  355. return Body;
  356. }
  357. private PathFigure CreateStartOpenArrow()
  358. {
  359. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
  360. {
  361. return null;
  362. }
  363. PathFigure arrowFigure = new PathFigure();
  364. PolyLineSegment arrowSegment = new PolyLineSegment();
  365. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  366. lineVector.Normalize();
  367. lineVector *= ArrowLength;
  368. Matrix rotateMatrix = new Matrix();
  369. rotateMatrix.Rotate(ArrowAngle / 2);
  370. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  371. arrowSegment.Points.Add((Point)LineStart);
  372. rotateMatrix.Rotate(-ArrowAngle);
  373. arrowSegment.Points.Add((Point)LineStart + (lineVector * rotateMatrix));
  374. arrowFigure.Segments.Add(arrowSegment);
  375. arrowFigure.IsClosed = IsStartClosed;
  376. arrowFigure.IsFilled = IsStartClosed;
  377. return arrowFigure;
  378. }
  379. private PathFigure CreateEndOpenArrow()
  380. {
  381. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
  382. {
  383. return null;
  384. }
  385. PathFigure arrowFigure = new PathFigure();
  386. PolyLineSegment arrowSegment = new PolyLineSegment();
  387. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  388. lineVector.Normalize();
  389. lineVector *= ArrowLength;
  390. Matrix rotateMatrix = new Matrix();
  391. rotateMatrix.Rotate(ArrowAngle / 2);
  392. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  393. arrowSegment.Points.Add((Point)LineEnd);
  394. rotateMatrix.Rotate(-ArrowAngle);
  395. arrowSegment.Points.Add((Point)LineEnd + (lineVector * rotateMatrix));
  396. arrowFigure.Segments.Add(arrowSegment);
  397. arrowFigure.IsClosed = IsEndClosed;
  398. arrowFigure.IsFilled = IsEndClosed;
  399. return arrowFigure;
  400. }
  401. private PathFigure CreateStartReverseArrow()
  402. {
  403. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
  404. {
  405. return null;
  406. }
  407. PathFigure arrowFigure = new PathFigure();
  408. PolyLineSegment arrowSegment = new PolyLineSegment();
  409. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  410. lineVector.Normalize();
  411. lineVector *= ArrowLength;
  412. Matrix rotateMatrix = new Matrix();
  413. rotateMatrix.Rotate(ArrowAngle / 2);
  414. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  415. arrowSegment.Points.Add((Point)LineStart);
  416. rotateMatrix.Rotate(-ArrowAngle);
  417. arrowSegment.Points.Add((Point)LineStart + (lineVector * rotateMatrix));
  418. arrowFigure.Segments.Add(arrowSegment);
  419. arrowFigure.IsClosed = IsStartClosed;
  420. arrowFigure.IsFilled = IsStartClosed;
  421. return arrowFigure;
  422. }
  423. private PathFigure CreateEndReverseArrow()
  424. {
  425. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
  426. {
  427. return null;
  428. }
  429. PathFigure arrowFigure = new PathFigure();
  430. PolyLineSegment arrowSegment = new PolyLineSegment();
  431. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  432. lineVector.Normalize();
  433. lineVector *= ArrowLength;
  434. Matrix rotateMatrix = new Matrix();
  435. rotateMatrix.Rotate(ArrowAngle / 2);
  436. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  437. arrowSegment.Points.Add((Point)LineEnd);
  438. rotateMatrix.Rotate(-ArrowAngle);
  439. arrowSegment.Points.Add((Point)LineEnd + (lineVector * rotateMatrix));
  440. arrowFigure.Segments.Add(arrowSegment);
  441. arrowFigure.IsClosed = IsEndClosed;
  442. arrowFigure.IsFilled = IsEndClosed;
  443. return arrowFigure;
  444. }
  445. private PathFigure CreateStartButtArrow()
  446. {
  447. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  448. {
  449. return null;
  450. }
  451. PathFigure arrowFigure = new PathFigure();
  452. LineSegment buttSegment = new LineSegment();
  453. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  454. lineVector.Normalize();
  455. lineVector *= ArrowLength;
  456. Matrix rotateMatrix = new Matrix();
  457. rotateMatrix.Rotate(90);
  458. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  459. rotateMatrix.Rotate(-180);
  460. buttSegment.Point = ((Point)LineStart + (lineVector * rotateMatrix));
  461. arrowFigure.Segments.Add(buttSegment);
  462. return arrowFigure;
  463. }
  464. private PathFigure CreateEndButtArrow()
  465. {
  466. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  467. {
  468. return null;
  469. }
  470. PathFigure arrowFigure = new PathFigure();
  471. LineSegment buttSegment = new LineSegment();
  472. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  473. lineVector.Normalize();
  474. lineVector *= ArrowLength;
  475. Matrix rotateMatrix = new Matrix();
  476. rotateMatrix.Rotate(90);
  477. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  478. rotateMatrix.Rotate(-180);
  479. buttSegment.Point = ((Point)LineEnd + (lineVector * rotateMatrix));
  480. arrowFigure.Segments.Add(buttSegment);
  481. return arrowFigure;
  482. }
  483. private PathFigure CreateStartDiamondArrow()
  484. {
  485. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  486. {
  487. return null;
  488. }
  489. PathFigure arrowFigure = new PathFigure();
  490. PolyLineSegment arrowSegment = new PolyLineSegment();
  491. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  492. lineVector.Normalize();
  493. lineVector *= ArrowLength;
  494. Matrix rotateMatrix = new Matrix();
  495. rotateMatrix.Rotate(45);
  496. Point cornerTop = (Point)LineStart + (lineVector * rotateMatrix);
  497. Vector turnVector = cornerTop - (Point)LineStart;
  498. turnVector.Normalize();
  499. turnVector *= ArrowLength;
  500. Matrix turnMatrix = new Matrix();
  501. turnMatrix.Rotate(-90);
  502. Point awayPoint = cornerTop + (turnVector * turnMatrix);
  503. rotateMatrix = new Matrix();
  504. rotateMatrix.Rotate(-45);
  505. Point cornerDown = (Point)LineStart + (lineVector * rotateMatrix);
  506. arrowFigure.StartPoint = (Point)LineStart;
  507. arrowSegment.Points.Add(cornerTop);
  508. arrowSegment.Points.Add(awayPoint);
  509. arrowSegment.Points.Add(cornerDown);
  510. arrowSegment.Points.Add((Point)LineStart);
  511. arrowFigure.Segments.Add(arrowSegment);
  512. arrowFigure.IsClosed = IsStartClosed;
  513. arrowFigure.IsFilled = IsStartClosed;
  514. return arrowFigure;
  515. }
  516. private PathFigure CreateEndDiamondArrow()
  517. {
  518. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  519. {
  520. return null;
  521. }
  522. PathFigure arrowFigure = new PathFigure();
  523. PolyLineSegment arrowSegment = new PolyLineSegment();
  524. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  525. lineVector.Normalize();
  526. lineVector *= ArrowLength;
  527. Matrix rotateMatrix = new Matrix();
  528. rotateMatrix.Rotate(45);
  529. Point cornerTop = (Point)LineEnd + (lineVector * rotateMatrix);
  530. Vector turnVector = cornerTop - (Point)LineEnd;
  531. turnVector.Normalize();
  532. turnVector *= ArrowLength;
  533. Matrix turnMatrix = new Matrix();
  534. turnMatrix.Rotate(-90);
  535. Point awayPoint = cornerTop + (turnVector * turnMatrix);
  536. rotateMatrix = new Matrix();
  537. rotateMatrix.Rotate(-45);
  538. Point cornerDown = (Point)LineEnd + (lineVector * rotateMatrix);
  539. arrowFigure.StartPoint = (Point)LineEnd;
  540. arrowSegment.Points.Add(cornerTop);
  541. arrowSegment.Points.Add(awayPoint);
  542. arrowSegment.Points.Add(cornerDown);
  543. arrowSegment.Points.Add((Point)LineEnd);
  544. arrowFigure.Segments.Add(arrowSegment);
  545. arrowFigure.IsClosed = IsEndClosed;
  546. arrowFigure.IsFilled = IsEndClosed;
  547. return arrowFigure;
  548. }
  549. private PathFigure CreateStartRoundArrow()
  550. {
  551. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  552. {
  553. return null;
  554. }
  555. PathFigure arrowFigure = new PathFigure();
  556. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  557. lineVector.Normalize();
  558. lineVector *= ArrowLength;
  559. Matrix rotateMatrix = new Matrix();
  560. rotateMatrix.Rotate(180);
  561. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  562. ArcSegment circleSegment = new ArcSegment();
  563. circleSegment.Point = (Point)LineStart;
  564. circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
  565. arrowFigure.Segments.Add(circleSegment);
  566. circleSegment = new ArcSegment();
  567. circleSegment.Point = (Point)arrowFigure.StartPoint;
  568. circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
  569. arrowFigure.Segments.Add(circleSegment);
  570. return arrowFigure;
  571. }
  572. private PathFigure CreateEndRoundArrow()
  573. {
  574. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  575. {
  576. return null;
  577. }
  578. PathFigure arrowFigure = new PathFigure();
  579. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  580. lineVector.Normalize();
  581. lineVector *= ArrowLength;
  582. Matrix rotateMatrix = new Matrix();
  583. rotateMatrix.Rotate(180);
  584. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  585. ArcSegment circleSegment = new ArcSegment();
  586. circleSegment.Point = (Point)LineEnd;
  587. circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
  588. arrowFigure.Segments.Add(circleSegment);
  589. circleSegment = new ArcSegment();
  590. circleSegment.Point = (Point)arrowFigure.StartPoint;
  591. circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
  592. arrowFigure.Segments.Add(circleSegment);
  593. return arrowFigure;
  594. }
  595. private PathFigure CreateStartSquareArrow()
  596. {
  597. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  598. {
  599. return null;
  600. }
  601. PathFigure arrowFigure = new PathFigure();
  602. PolyLineSegment squreSegment = new PolyLineSegment();
  603. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  604. lineVector.Normalize();
  605. lineVector *= (ArrowLength / 2);
  606. Matrix rotateMatrix = new Matrix();
  607. rotateMatrix.Rotate(90);
  608. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  609. rotateMatrix.Rotate(-180);
  610. Point pointCorner = (Point)LineStart + (lineVector * rotateMatrix);
  611. squreSegment.Points.Add(pointCorner);
  612. Vector moveVector = arrowFigure.StartPoint - pointCorner;
  613. moveVector.Normalize();
  614. moveVector *= (ArrowLength);
  615. rotateMatrix = new Matrix();
  616. rotateMatrix.Rotate(90);
  617. squreSegment.Points.Add(pointCorner + (moveVector * rotateMatrix));
  618. squreSegment.Points.Add(arrowFigure.StartPoint + (moveVector * rotateMatrix));
  619. squreSegment.Points.Add(arrowFigure.StartPoint);
  620. squreSegment.Points.Add((Point)LineStart);
  621. arrowFigure.Segments.Add(squreSegment);
  622. return arrowFigure;
  623. }
  624. private PathFigure CreateEndSquareArrow()
  625. {
  626. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  627. {
  628. return null;
  629. }
  630. PathFigure arrowFigure = new PathFigure();
  631. PolyLineSegment squreSegment = new PolyLineSegment();
  632. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  633. lineVector.Normalize();
  634. lineVector *= (ArrowLength / 2);
  635. Matrix rotateMatrix = new Matrix();
  636. rotateMatrix.Rotate(90);
  637. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  638. rotateMatrix.Rotate(-180);
  639. Point pointCorner = (Point)LineEnd + (lineVector * rotateMatrix);
  640. squreSegment.Points.Add(pointCorner);
  641. Vector moveVector = arrowFigure.StartPoint - pointCorner;
  642. moveVector.Normalize();
  643. moveVector *= (ArrowLength);
  644. rotateMatrix = new Matrix();
  645. rotateMatrix.Rotate(90);
  646. squreSegment.Points.Add(pointCorner + (moveVector * rotateMatrix));
  647. squreSegment.Points.Add(arrowFigure.StartPoint + (moveVector * rotateMatrix));
  648. squreSegment.Points.Add(arrowFigure.StartPoint);
  649. squreSegment.Points.Add((Point)LineEnd);
  650. arrowFigure.Segments.Add(squreSegment);
  651. return arrowFigure;
  652. }
  653. private PathFigure CreateStartSlashArrow()
  654. {
  655. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  656. {
  657. return null;
  658. }
  659. PathFigure arrowFigure = new PathFigure();
  660. LineSegment buttSegment = new LineSegment();
  661. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  662. lineVector.Normalize();
  663. lineVector *= ArrowLength;
  664. Matrix rotateMatrix = new Matrix();
  665. rotateMatrix.Rotate(45);
  666. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  667. rotateMatrix.Rotate(-180);
  668. buttSegment.Point = ((Point)LineStart + (lineVector * rotateMatrix));
  669. arrowFigure.Segments.Add(buttSegment);
  670. return arrowFigure;
  671. }
  672. private PathFigure CreateEndSlashArrow()
  673. {
  674. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  675. {
  676. return null;
  677. }
  678. PathFigure arrowFigure = new PathFigure();
  679. LineSegment buttSegment = new LineSegment();
  680. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  681. lineVector.Normalize();
  682. lineVector *= ArrowLength;
  683. Matrix rotateMatrix = new Matrix();
  684. rotateMatrix.Rotate(45);
  685. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  686. rotateMatrix.Rotate(-180);
  687. buttSegment.Point = ((Point)LineEnd + (lineVector * rotateMatrix));
  688. arrowFigure.Segments.Add(buttSegment);
  689. return arrowFigure;
  690. }
  691. }
  692. }
  693. }