123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFDocument;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Reflection;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace Compdfkit_Tools.Helper
- {
- public static class CommonHelper
- {
- /// <summary>
- /// Returns the file size based on the specified file path, with the smallest unit being bytes (B).
- /// </summary>
- /// <param name="filePath">The path to the file.</param>
- /// <returns>
- /// The calculated file size, with units in bytes (B), kilobytes (KB), megabytes (MB), or gigabytes (GB).
- /// </returns>
- public static string GetFileSize(string filePath)
- {
- FileInfo fileInfo = null;
- try
- {
- fileInfo = new FileInfo(filePath);
- }
- catch
- {
- return "0B";
- }
- if (fileInfo != null && fileInfo.Exists)
- {
- double fileSize = fileInfo.Length;
- if (fileSize > 1024)
- {
- fileSize = Math.Round(fileSize / 1024, 2);
- if (fileSize > 1024)
- {
- fileSize = Math.Round(fileSize / 1024, 2);
- if (fileSize > 1024)
- {
- fileSize = Math.Round(fileSize / 1024, 2);
- return fileSize + " GB";
- }
- else
- {
- return fileSize + " MB";
- }
- }
- else
- {
- return fileSize + " KB";
- }
- }
- else
- {
- return fileSize + " B";
- }
- }
- return "0B";
- }
-
- public static string GetFilePathOrEmpty()
- {
- string selectedFilePath = string.Empty;
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
- if (openFileDialog.ShowDialog() == true)
- {
- selectedFilePath = openFileDialog.FileName;
- }
- return selectedFilePath;
- }
-
- public static bool GetPagesInRange(ref List<int> pageList, string pageRange, int count, char[] enumerationSeparator, char[] rangeSeparator, bool inittag = false)
- {
- string[] rangeSplit = pageRange.Split(enumerationSeparator);
- pageList.Clear();
- foreach (string range in rangeSplit)
- {
- int starttag = 1;
- if (inittag)
- {
- starttag = 0;
- }
- if (range.Contains("-"))
- {
- try
- {
- string[] limits = range.Split(rangeSeparator);
- if (limits.Length >= 2 && !string.IsNullOrWhiteSpace(limits[0]) && !string.IsNullOrWhiteSpace(limits[1]))
- {
- int start = int.Parse(limits[0]);
- int end = int.Parse(limits[1]);
- if ((start < starttag) || (end > count) || (start > end))
- {
- return false;
- }
- for (int i = start; i <= end; ++i)
- {
- if (pageList.Contains(i))
- {
- return false;
- }
- pageList.Add(i - 1);
- }
- continue;
- }
- }
- catch (Exception ex)
- {
- return false;
- }
- }
- int pageNr;
- try
- {
- pageNr = int.Parse(range);
- }
- catch (Exception)
- {
- return false;
- }
- if (pageNr < starttag || pageNr > count)
- {
- return false;
- }
- if (pageList.Contains(pageNr))
- {
- return false;
- }
- pageList.Add(pageNr - 1);
- }
- return true;
- }
- internal static class PageEditHelper
- {
- public static T FindVisualParent<T>(DependencyObject obj) where T : class
- {
- while (obj != null)
- {
- if (obj is T)
- return obj as T;
- obj = VisualTreeHelper.GetParent(obj);
- }
- return null;
- }
- public static childItem FindVisualChild<childItem>(DependencyObject obj)
- where childItem : DependencyObject
- {
- for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
- {
- DependencyObject child = VisualTreeHelper.GetChild(obj, i);
- if (child != null && child is childItem)
- return (childItem)child;
- else
- {
- childItem childOfChild = FindVisualChild<childItem>(child);
- if (childOfChild != null)
- return childOfChild;
- }
- }
- return null;
- }
- }
- public static class ViewportHelper
- {
- public static CPDFDocument CopyDoc;
- public static bool IsInViewport(ScrollViewer sv, Control item)
- {
- if (item == null) return false;
- ItemsControl itemsControl = null;
- if (item is ListBoxItem)
- itemsControl = ItemsControl.ItemsControlFromItemContainer(item) as ListBox;
- else
- throw new NotSupportedException(item.GetType().Name);
- ScrollContentPresenter scrollContentPresenter = (ScrollContentPresenter)sv.Template.FindName("PART_ScrollContentPresenter", sv);
- MethodInfo isInViewportMethod = sv.GetType().GetMethod("IsInViewport", BindingFlags.NonPublic | BindingFlags.Instance);
- return (bool)isInViewportMethod.Invoke(sv, new object[] { scrollContentPresenter, item });
- }
- public static T FindVisualParent<T>(DependencyObject obj) where T : class
- {
- while (obj != null)
- {
- if (obj is T)
- return obj as T;
- obj = VisualTreeHelper.GetParent(obj);
- }
- return null;
- }
- public static childItem FindVisualChild<childItem>(DependencyObject obj)
- where childItem : DependencyObject
- {
- for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
- {
- DependencyObject child = VisualTreeHelper.GetChild(obj, i);
- if (child != null && child is childItem)
- return (childItem)child;
- else
- {
- childItem childOfChild = FindVisualChild<childItem>(child);
- if (childOfChild != null)
- return childOfChild;
- }
- }
- return null;
- }
- }
- public class ArrowHelper
- {
- public bool HasStartArrow
- {
- get
- {
- if (StartSharp != C_LINE_TYPE.LINETYPE_UNKNOWN && StartSharp != C_LINE_TYPE.LINETYPE_NONE)
- {
- return true;
- }
- return false;
- }
- }
- public bool IsStartClosed
- {
- get
- {
- if (StartSharp == C_LINE_TYPE.LINETYPE_CLOSEDARROW || StartSharp == C_LINE_TYPE.LINETYPE_RCLOSEDARROW || StartSharp == C_LINE_TYPE.LINETYPE_DIAMOND)
- {
- return true;
- }
- return false;
- }
- }
- public bool HasEndArrow
- {
- get
- {
- if (EndSharp != C_LINE_TYPE.LINETYPE_UNKNOWN && EndSharp != C_LINE_TYPE.LINETYPE_NONE)
- {
- return true;
- }
- return false;
- }
- }
- public bool IsEndClosed
- {
- get
- {
- if (EndSharp == C_LINE_TYPE.LINETYPE_CLOSEDARROW || EndSharp == C_LINE_TYPE.LINETYPE_RCLOSEDARROW || EndSharp == C_LINE_TYPE.LINETYPE_DIAMOND)
- {
- return true;
- }
- return false;
- }
- }
- public uint ArrowAngle { get; set; }
- public uint ArrowLength { get; set; }
- public Point? LineStart { get; set; }
- public Point? LineEnd { get; set; }
- public PathGeometry Body { get; set; }
- public C_LINE_TYPE StartSharp { get; set; }
- public C_LINE_TYPE EndSharp { get; set; }
- public ArrowHelper()
- {
- Body = new PathGeometry();
- ArrowLength = 12;
- ArrowAngle = 60;
- }
- protected PathFigure CreateLineBody()
- {
- if (LineStart != null && LineEnd != null)
- {
- PathFigure lineFigure = new PathFigure();
- lineFigure.StartPoint = (Point)LineStart;
- LineSegment linePath = new LineSegment();
- linePath.Point = (Point)LineEnd;
- lineFigure.Segments.Add(linePath);
- return lineFigure;
- }
- return null;
- }
- protected PathFigure CreateStartArrow()
- {
- switch (StartSharp)
- {
- case C_LINE_TYPE.LINETYPE_NONE:
- case C_LINE_TYPE.LINETYPE_UNKNOWN:
- break;
- case C_LINE_TYPE.LINETYPE_ARROW:
- case C_LINE_TYPE.LINETYPE_CLOSEDARROW:
- return CreateStartOpenArrow();
- case C_LINE_TYPE.LINETYPE_ROPENARROW:
- case C_LINE_TYPE.LINETYPE_RCLOSEDARROW:
- return CreateStartReverseArrow();
- case C_LINE_TYPE.LINETYPE_BUTT:
- return CreateStartButtArrow();
- case C_LINE_TYPE.LINETYPE_DIAMOND:
- return CreateStartDiamondArrow();
- case C_LINE_TYPE.LINETYPE_CIRCLE:
- return CreateStartRoundArrow();
- case C_LINE_TYPE.LINETYPE_SQUARE:
- return CreateStartSquareArrow();
- case C_LINE_TYPE.LINETYPE_SLASH:
- return CreateStartSlashArrow();
- default:
- break;
- }
- return null;
- }
- protected virtual PathFigure CreateEndArrow()
- {
- switch (EndSharp)
- {
- case C_LINE_TYPE.LINETYPE_NONE:
- case C_LINE_TYPE.LINETYPE_UNKNOWN:
- break;
- case C_LINE_TYPE.LINETYPE_ARROW:
- case C_LINE_TYPE.LINETYPE_CLOSEDARROW:
- return CreateEndOpenArrow();
- case C_LINE_TYPE.LINETYPE_ROPENARROW:
- case C_LINE_TYPE.LINETYPE_RCLOSEDARROW:
- return CreateEndReverseArrow();
- case C_LINE_TYPE.LINETYPE_BUTT:
- return CreateEndButtArrow();
- case C_LINE_TYPE.LINETYPE_DIAMOND:
- return CreateEndDiamondArrow();
- case C_LINE_TYPE.LINETYPE_CIRCLE:
- return CreateEndRoundArrow();
- case C_LINE_TYPE.LINETYPE_SQUARE:
- return CreateEndSquareArrow();
- case C_LINE_TYPE.LINETYPE_SLASH:
- return CreateEndSlashArrow();
- default:
- break;
- }
- return null;
- }
- public PathGeometry BuildArrowBody()
- {
- Body.Figures.Clear();
- PathFigure lineBody = CreateLineBody();
- if (lineBody != null)
- {
- Body.Figures.Add(lineBody);
- PathFigure arrowFigure = CreateStartArrow();
- if (arrowFigure != null)
- {
- Body.Figures.Add(arrowFigure);
- }
- arrowFigure = CreateEndArrow();
- if (arrowFigure != null)
- {
- Body.Figures.Add(arrowFigure);
- }
- }
- return Body;
- }
-
- private PathFigure CreateStartOpenArrow()
- {
- if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- PolyLineSegment arrowSegment = new PolyLineSegment();
- Vector lineVector = (Point)LineEnd - (Point)LineStart;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(ArrowAngle / 2);
- arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
- arrowSegment.Points.Add((Point)LineStart);
- rotateMatrix.Rotate(-ArrowAngle);
- arrowSegment.Points.Add((Point)LineStart + (lineVector * rotateMatrix));
- arrowFigure.Segments.Add(arrowSegment);
- arrowFigure.IsClosed = IsStartClosed;
- arrowFigure.IsFilled = IsStartClosed;
- return arrowFigure;
- }
- private PathFigure CreateEndOpenArrow()
- {
- if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- PolyLineSegment arrowSegment = new PolyLineSegment();
- Vector lineVector = (Point)LineStart - (Point)LineEnd;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(ArrowAngle / 2);
- arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
- arrowSegment.Points.Add((Point)LineEnd);
- rotateMatrix.Rotate(-ArrowAngle);
- arrowSegment.Points.Add((Point)LineEnd + (lineVector * rotateMatrix));
- arrowFigure.Segments.Add(arrowSegment);
- arrowFigure.IsClosed = IsEndClosed;
- arrowFigure.IsFilled = IsEndClosed;
- return arrowFigure;
- }
- private PathFigure CreateStartReverseArrow()
- {
- if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- PolyLineSegment arrowSegment = new PolyLineSegment();
- Vector lineVector = (Point)LineStart - (Point)LineEnd;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(ArrowAngle / 2);
- arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
- arrowSegment.Points.Add((Point)LineStart);
- rotateMatrix.Rotate(-ArrowAngle);
- arrowSegment.Points.Add((Point)LineStart + (lineVector * rotateMatrix));
- arrowFigure.Segments.Add(arrowSegment);
- arrowFigure.IsClosed = IsStartClosed;
- arrowFigure.IsFilled = IsStartClosed;
- return arrowFigure;
- }
- private PathFigure CreateEndReverseArrow()
- {
- if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- PolyLineSegment arrowSegment = new PolyLineSegment();
- Vector lineVector = (Point)LineEnd - (Point)LineStart;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(ArrowAngle / 2);
- arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
- arrowSegment.Points.Add((Point)LineEnd);
- rotateMatrix.Rotate(-ArrowAngle);
- arrowSegment.Points.Add((Point)LineEnd + (lineVector * rotateMatrix));
- arrowFigure.Segments.Add(arrowSegment);
- arrowFigure.IsClosed = IsEndClosed;
- arrowFigure.IsFilled = IsEndClosed;
- return arrowFigure;
- }
-
- private PathFigure CreateStartButtArrow()
- {
- if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- LineSegment buttSegment = new LineSegment();
- Vector lineVector = (Point)LineStart - (Point)LineEnd;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(90);
- arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
- rotateMatrix.Rotate(-180);
- buttSegment.Point = ((Point)LineStart + (lineVector * rotateMatrix));
- arrowFigure.Segments.Add(buttSegment);
- return arrowFigure;
- }
- private PathFigure CreateEndButtArrow()
- {
- if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- LineSegment buttSegment = new LineSegment();
- Vector lineVector = (Point)LineEnd - (Point)LineStart;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(90);
- arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
- rotateMatrix.Rotate(-180);
- buttSegment.Point = ((Point)LineEnd + (lineVector * rotateMatrix));
- arrowFigure.Segments.Add(buttSegment);
- return arrowFigure;
- }
- private PathFigure CreateStartDiamondArrow()
- {
- if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- PolyLineSegment arrowSegment = new PolyLineSegment();
- Vector lineVector = (Point)LineStart - (Point)LineEnd;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(45);
- Point cornerTop = (Point)LineStart + (lineVector * rotateMatrix);
- Vector turnVector = cornerTop - (Point)LineStart;
- turnVector.Normalize();
- turnVector *= ArrowLength;
- Matrix turnMatrix = new Matrix();
- turnMatrix.Rotate(-90);
- Point awayPoint = cornerTop + (turnVector * turnMatrix);
- rotateMatrix = new Matrix();
- rotateMatrix.Rotate(-45);
- Point cornerDown = (Point)LineStart + (lineVector * rotateMatrix);
- arrowFigure.StartPoint = (Point)LineStart;
- arrowSegment.Points.Add(cornerTop);
- arrowSegment.Points.Add(awayPoint);
- arrowSegment.Points.Add(cornerDown);
- arrowSegment.Points.Add((Point)LineStart);
- arrowFigure.Segments.Add(arrowSegment);
- arrowFigure.IsClosed = IsStartClosed;
- arrowFigure.IsFilled = IsStartClosed;
- return arrowFigure;
- }
- private PathFigure CreateEndDiamondArrow()
- {
- if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- PolyLineSegment arrowSegment = new PolyLineSegment();
- Vector lineVector = (Point)LineEnd - (Point)LineStart;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(45);
- Point cornerTop = (Point)LineEnd + (lineVector * rotateMatrix);
- Vector turnVector = cornerTop - (Point)LineEnd;
- turnVector.Normalize();
- turnVector *= ArrowLength;
- Matrix turnMatrix = new Matrix();
- turnMatrix.Rotate(-90);
- Point awayPoint = cornerTop + (turnVector * turnMatrix);
- rotateMatrix = new Matrix();
- rotateMatrix.Rotate(-45);
- Point cornerDown = (Point)LineEnd + (lineVector * rotateMatrix);
- arrowFigure.StartPoint = (Point)LineEnd;
- arrowSegment.Points.Add(cornerTop);
- arrowSegment.Points.Add(awayPoint);
- arrowSegment.Points.Add(cornerDown);
- arrowSegment.Points.Add((Point)LineEnd);
- arrowFigure.Segments.Add(arrowSegment);
- arrowFigure.IsClosed = IsEndClosed;
- arrowFigure.IsFilled = IsEndClosed;
- return arrowFigure;
- }
- private PathFigure CreateStartRoundArrow()
- {
- if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- Vector lineVector = (Point)LineEnd - (Point)LineStart;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(180);
- arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
- ArcSegment circleSegment = new ArcSegment();
- circleSegment.Point = (Point)LineStart;
- circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
- arrowFigure.Segments.Add(circleSegment);
- circleSegment = new ArcSegment();
- circleSegment.Point = (Point)arrowFigure.StartPoint;
- circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
- arrowFigure.Segments.Add(circleSegment);
- return arrowFigure;
- }
- private PathFigure CreateEndRoundArrow()
- {
- if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- Vector lineVector = (Point)LineStart - (Point)LineEnd;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(180);
- arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
- ArcSegment circleSegment = new ArcSegment();
- circleSegment.Point = (Point)LineEnd;
- circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
- arrowFigure.Segments.Add(circleSegment);
- circleSegment = new ArcSegment();
- circleSegment.Point = (Point)arrowFigure.StartPoint;
- circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
- arrowFigure.Segments.Add(circleSegment);
- return arrowFigure;
- }
- private PathFigure CreateStartSquareArrow()
- {
- if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- PolyLineSegment squreSegment = new PolyLineSegment();
- Vector lineVector = (Point)LineEnd - (Point)LineStart;
- lineVector.Normalize();
- lineVector *= (ArrowLength / 2);
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(90);
- arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
- rotateMatrix.Rotate(-180);
- Point pointCorner = (Point)LineStart + (lineVector * rotateMatrix);
- squreSegment.Points.Add(pointCorner);
- Vector moveVector = arrowFigure.StartPoint - pointCorner;
- moveVector.Normalize();
- moveVector *= (ArrowLength);
- rotateMatrix = new Matrix();
- rotateMatrix.Rotate(90);
- squreSegment.Points.Add(pointCorner + (moveVector * rotateMatrix));
- squreSegment.Points.Add(arrowFigure.StartPoint + (moveVector * rotateMatrix));
- squreSegment.Points.Add(arrowFigure.StartPoint);
- squreSegment.Points.Add((Point)LineStart);
- arrowFigure.Segments.Add(squreSegment);
- return arrowFigure;
- }
- private PathFigure CreateEndSquareArrow()
- {
- if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- PolyLineSegment squreSegment = new PolyLineSegment();
- Vector lineVector = (Point)LineStart - (Point)LineEnd;
- lineVector.Normalize();
- lineVector *= (ArrowLength / 2);
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(90);
- arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
- rotateMatrix.Rotate(-180);
- Point pointCorner = (Point)LineEnd + (lineVector * rotateMatrix);
- squreSegment.Points.Add(pointCorner);
- Vector moveVector = arrowFigure.StartPoint - pointCorner;
- moveVector.Normalize();
- moveVector *= (ArrowLength);
- rotateMatrix = new Matrix();
- rotateMatrix.Rotate(90);
- squreSegment.Points.Add(pointCorner + (moveVector * rotateMatrix));
- squreSegment.Points.Add(arrowFigure.StartPoint + (moveVector * rotateMatrix));
- squreSegment.Points.Add(arrowFigure.StartPoint);
- squreSegment.Points.Add((Point)LineEnd);
- arrowFigure.Segments.Add(squreSegment);
- return arrowFigure;
- }
- private PathFigure CreateStartSlashArrow()
- {
- if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- LineSegment buttSegment = new LineSegment();
- Vector lineVector = (Point)LineStart - (Point)LineEnd;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(45);
- arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
- rotateMatrix.Rotate(-180);
- buttSegment.Point = ((Point)LineStart + (lineVector * rotateMatrix));
- arrowFigure.Segments.Add(buttSegment);
- return arrowFigure;
- }
- private PathFigure CreateEndSlashArrow()
- {
- if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
- {
- return null;
- }
- PathFigure arrowFigure = new PathFigure();
- LineSegment buttSegment = new LineSegment();
- Vector lineVector = (Point)LineEnd - (Point)LineStart;
- lineVector.Normalize();
- lineVector *= ArrowLength;
- Matrix rotateMatrix = new Matrix();
- rotateMatrix.Rotate(45);
- arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
- rotateMatrix.Rotate(-180);
- buttSegment.Point = ((Point)LineEnd + (lineVector * rotateMatrix));
- arrowFigure.Segments.Add(buttSegment);
- return arrowFigure;
- }
- }
- }
- }
|