CommonHelper.cs 31 KB

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