12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFDocument;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Runtime.CompilerServices;
- using System.Text.RegularExpressions;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Interop;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Xml;
- using ComPDFKit.DigitalSign;
- using ComPDFKit.PDFAnnotation.Form;
- using Point = System.Windows.Point;
- using Size = System.Windows.Size;
- using System.Collections.ObjectModel;
- using Brush = System.Windows.Media.Brush;
- using Color = System.Windows.Media.Color;
- using System.Drawing.Drawing2D;
- using Matrix = System.Windows.Media.Matrix;
- using System.Drawing.Imaging;
- using System.Runtime.InteropServices;
- using ComPDFKit.NativeMethod;
- namespace ComPDFKit.Controls.Helper
- {
- public class SDKLicenseHelper
- {
- public static string ParseLicenseXML()
- {
- try
- {
- XmlDocument xmlDocument = new XmlDocument();
- xmlDocument.Load("license_key_windows.xml");
- XmlNode xmlNode = xmlDocument.SelectSingleNode("/license/key");
- if (xmlNode == null)
- {
- return string.Empty;
- }
- else
- {
- return xmlNode.InnerText;
- }
- }
- catch
- {
- return string.Empty;
- }
- }
- }
- public static class CommonHelper
- {
- [DllImport("shell32.dll", ExactSpelling = true)]
- private static extern void ILFree(IntPtr pidlList);
- [DllImport("shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
- private static extern IntPtr ILCreateFromPathW(string pszPath);
- [DllImport("shell32.dll", ExactSpelling = true)]
- private static extern int SHOpenFolderAndSelectItems(IntPtr pidlList, uint cild, IntPtr children, uint dwFlags);
- public static bool IsImageCorrupted(string imagePath)
- {
- try
- {
- using (Bitmap bitmap = new Bitmap(imagePath))
- {
- int width = bitmap.Width;
- int height = bitmap.Height;
- }
- return false;
- }
- catch (Exception)
- {
- MessageBox.Show(LanguageHelper.CommonManager.GetString("Text_ImageCorrupted"), LanguageHelper.CommonManager.GetString("Button_OK"), MessageBoxButton.OK);
- return true;
- }
- }
- public static Bitmap ConvertTo32bppArgb(Bitmap source)
- {
- // Create a new Bitmap with 32bppArgb pixel format
- Bitmap newBitmap = new Bitmap(source.Width, source.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
- // Create a Graphics object to draw the source image on the new Bitmap
- using (Graphics g = Graphics.FromImage(newBitmap))
- {
- // Set the interpolation mode and pixel offset mode for high-quality rendering
- g.InterpolationMode = InterpolationMode.HighQualityBicubic;
- g.PixelOffsetMode = PixelOffsetMode.HighQuality;
- g.SmoothingMode = SmoothingMode.HighQuality;
- // Draw the source image on the new Bitmap
- g.DrawImage(source, new System.Drawing.Rectangle(0, 0, source.Width, source.Height));
- }
- return newBitmap;
- }
- public static byte[] ConvertBrushToByteArray(Brush brush)
- {
- if (brush is SolidColorBrush solidColorBrush)
- {
- Color color = solidColorBrush.Color;
- byte[] colorBytes = new byte[3];
- colorBytes[0] = color.R;
- colorBytes[1] = color.G;
- colorBytes[2] = color.B;
- return colorBytes;
- }
- else
- {
- throw new ArgumentException("The provided brush is not a SolidColorBrush.");
- }
- }
- public static int GetBitmapPointer(Bitmap bitmap)
- {
- IntPtr hBitmap = bitmap.GetHbitmap();
- int bitmapPointer = hBitmap.ToInt32();
- return bitmapPointer;
- }
- public static string EmailPattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
- public static bool IsValidEmail(string email)
- {
- string emailPattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
- return Regex.IsMatch(email, emailPattern);
- }
- public static string GetExactDateFromString(string dateString)
- {
- DateTime dateTime = GetDateTimeFromString(dateString);
- return dateTime.ToString("yyyy/MM/dd HH:mm:ss");
- }
- public static DateTime GetDateTimeFromString(string dateString)
- {
- int start = 0;
- for (int i = 0; i < dateString.Length; i++)
- {
- if (char.IsNumber(dateString[i]))
- {
- start = i;
- break;
- }
- }
- string date = dateString.Substring(start, 14);
- string year = date.Substring(0, 4);
- string month = date.Substring(4, 2);
- string day = date.Substring(6, 2);
- string hour = date.Substring(8, 2);
- string minute = date.Substring(10, 2);
- string second = date.Substring(12, 2);
- return new DateTime(int.Parse(year), int.Parse(month), int.Parse(day), int.Parse(hour), int.Parse(minute), int.Parse(second));
- }
- /// <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)
- {
- try
- {
- long fileSize = new FileInfo(filePath).Length;
- string[] sizes = { "B", "KB", "MB", "GB" };
- int order = 0;
- while (fileSize >= 1024 && order < sizes.Length - 1)
- {
- fileSize /= 1024;
- order++;
- }
- return $"{fileSize} {sizes[order]}";
- }
- catch
- {
- return "0B";
- }
- }
- public static string GetExistedPathOrEmpty(string filter = "PDF files (*.pdf)|*.pdf")
- {
- string selectedFilePath = string.Empty;
- OpenFileDialog openFileDialog;
- try
- {
- openFileDialog = new OpenFileDialog
- {
- Filter = filter
- };
- }
- catch
- {
- return string.Empty;
- };
- if (openFileDialog.ShowDialog() == true)
- {
- selectedFilePath = openFileDialog.FileName;
- }
- return selectedFilePath;
- }
- public static string GetGeneratePathOrEmpty(string filter, string defaultFileName = "")
- {
- string selectedFilePath = string.Empty;
- SaveFileDialog saveFileDialog = new SaveFileDialog
- {
- Filter = filter,
- FileName = defaultFileName
- };
- if (saveFileDialog.ShowDialog() == true)
- {
- selectedFilePath = saveFileDialog.FileName;
- }
- return selectedFilePath;
- }
- public static string GetPageParmFromList(List<int> pagesList)
- {
- string pageParam = "";
- if (pagesList.Count != 0)
- {
- pagesList.Sort();
- for (int i = 0; i < pagesList.Count; i++)
- {
- if (i == 0)
- {
- pageParam += pagesList[0].ToString();
- }
- else
- {
- if (pagesList[i] == pagesList[i - 1] + 1)
- {
- if (i >= 2)
- {
- if (pagesList[i - 1] != pagesList[i - 2] + 1)
- pageParam += "-";
- }
- else
- pageParam += "-";
- if (i == pagesList.Count - 1)
- {
- pageParam += pagesList[i].ToString();
- }
- }
- else
- {
- if (i >= 2)
- {
- if (pagesList[i - 1] == pagesList[i - 2] + 1)
- pageParam += pagesList[i - 1].ToString();
- }
- pageParam += "," + pagesList[i].ToString();
- }
- }
- }
- }
- return pageParam;
- }
- public static List<int> GetDefaultPageList(CPDFDocument document)
- {
- List<int> pageRangeList = new List<int>();
- for (int i = 0; i < document.PageCount; i++)
- {
- pageRangeList.Add(i + 1);
- }
- return pageRangeList;
- }
- public static bool GetPagesInRange(ref List<int> pageList, string pageRange, int count, char[] enumerationSeparator, char[] rangeSeparator, bool inittag = false)
- {
- if (pageRange == null || pageList == null)
- {
- return false;
- }
- pageList.Clear();
- int starttag = inittag ? 0 : 1;
- string[] rangeSplit = pageRange.Split(enumerationSeparator);
- foreach (string range in rangeSplit)
- {
- if (range.Contains("-"))
- {
- string[] limits = range.Split(rangeSeparator);
- if (limits.Length == 2 && int.TryParse(limits[0], out int start) && int.TryParse(limits[1], out int end))
- {
- if (start < starttag || end > count || start > end)
- {
- return false;
- }
- for (int i = start; i <= end; i++)
- {
- if (pageList.Contains(i - 1))
- {
- return false;
- }
- pageList.Add(i - 1);
- }
- }
- else
- {
- return false;
- }
- }
- else if (int.TryParse(range, out int pageNr))
- {
- if (pageNr < starttag || pageNr > count)
- {
- return false;
- }
- if (pageList.Contains(pageNr - 1))
- {
- return false;
- }
- pageList.Add(pageNr - 1);
- }
- else
- {
- return false;
- }
- }
- return true;
- }
- internal static byte[] ConvertBitmapToByteArray(Bitmap bitmap)
- {
- BitmapData bmpdata = null;
- try
- {
- bmpdata = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
- int numbytes = bmpdata.Stride * bitmap.Height;
- byte[] bytedata = new byte[numbytes];
- IntPtr ptr = bmpdata.Scan0;
- Marshal.Copy(ptr, bytedata, 0, numbytes);
- return bytedata;
- }
- finally
- {
- if (bmpdata != null)
- bitmap.UnlockBits(bmpdata);
- }
- }
- public static string CreateFilePath(string path)
- {
- int i = 1;
- string oldDestName = path;
- do
- {
- if (File.Exists(path))
- {
- int lastDot = oldDestName.LastIndexOf('.');
- string fileExtension = string.Empty;
- string fileName = oldDestName;
- if (lastDot > 0)
- {
- fileExtension = fileName.Substring(lastDot);
- fileName = fileName.Substring(0, lastDot);
- }
- path = fileName + string.Format(@"({0})", i) + fileExtension;
- }
- ++i;
- } while (File.Exists(path));
- return path;
- }
- public static void ExplorerFile(string filePath)
- {
- try
- {
- if (!File.Exists(filePath) && !Directory.Exists(filePath))
- return;
- if (Directory.Exists(filePath))
- Process.Start(@"explorer.exe", "/select,\"" + filePath + "\"");
- else
- {
- IntPtr pidlList = ILCreateFromPathW(filePath);
- if (pidlList != IntPtr.Zero)
- {
- try
- {
- Marshal.ThrowExceptionForHR(SHOpenFolderAndSelectItems(pidlList, 0, IntPtr.Zero, 0));
- }
- finally
- {
- ILFree(pidlList);
- }
- }
- }
- }
- catch { }
- }
- 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;
- }
- }
- }
- public class PanelState
- {
- private static PanelState instance;
- public enum RightPanelState
- {
- None,
- PropertyPanel,
- ViewSettings
- }
- private bool _isLeftPanelExpand;
- public bool IsLeftPanelExpand
- {
- get { return _isLeftPanelExpand; }
- set
- {
- if (_isLeftPanelExpand != value)
- {
- _isLeftPanelExpand = value;
- OnPropertyChanged();
- }
- }
- }
- private RightPanelState _rightPanel;
- public RightPanelState RightPanel
- {
- get { return _rightPanel; }
- set
- {
- if (_rightPanel != value)
- {
- _rightPanel = value;
- OnPropertyChanged();
- }
- }
- }
- private PanelState() { }
- public static PanelState GetInstance()
- {
- if (instance == null)
- {
- instance = new PanelState();
- }
- return instance;
- }
- public event PropertyChangedEventHandler PropertyChanged;
- protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- public class CommandHelper
- {
- public static void CopyImage_Click(Dictionary<int, List<Bitmap>> imageDict)
- {
- try
- {
- if (imageDict != null && imageDict.Count > 0)
- {
- foreach (int pageIndex in imageDict.Keys)
- {
- List<Bitmap> imageList = imageDict[pageIndex];
- foreach (Bitmap image in imageList)
- {
- MemoryStream ms = new MemoryStream();
- image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
- BitmapImage imageData = new BitmapImage();
- imageData.BeginInit();
- imageData.StreamSource = ms;
- imageData.CacheOption = BitmapCacheOption.OnLoad;
- imageData.EndInit();
- imageData.Freeze();
- Clipboard.SetImage(imageData);
- break;
- }
- }
- }
- }
- catch (Exception ex)
- {
- }
- }
- public static void ExtraImage_Click(Dictionary<int, List<Bitmap>> imageDict)
- {
- System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
- if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- string choosePath = folderDialog.SelectedPath;
- string openPath = choosePath;
- try
- {
- if (imageDict != null && imageDict.Count > 0)
- {
- foreach (int pageIndex in imageDict.Keys)
- {
- List<Bitmap> imageList = imageDict[pageIndex];
- foreach (Bitmap image in imageList)
- {
- string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
- image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
- openPath = savePath;
- }
- }
- }
- Process.Start("explorer", "/select,\"" + openPath + "\"");
- }
- catch (Exception ex)
- {
- }
- }
- }
- public static double CheckZoomLevel(double[] zoomLevelList, double zoom, bool IsGrowth)
- {
- double standardZoom = 100;
- if (zoom <= 0.01)
- {
- return 0.01;
- }
- if (zoom >= 10)
- {
- return 10;
- }
- zoom *= 100;
- for (int i = 0; i < zoomLevelList.Length - 1; i++)
- {
- if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
- {
- standardZoom = zoomLevelList[i + 1];
- break;
- }
- if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
- {
- standardZoom = zoomLevelList[i];
- break;
- }
- }
- return standardZoom / 100;
- }
- }
- public class SignatureHelper
- {
- public static List<CPDFSignature> SignatureList;
- public static void InitEffectiveSignatureList(CPDFDocument document)
- {
- SignatureList = document.GetSignatureList();
- for (int index = SignatureList.Count - 1; index >= 0; index--)
- {
- if (SignatureList[index].SignerList.Count <= 0)
- {
- SignatureList.RemoveAt(index);
- }
- }
- }
- public static void VerifySignatureList(CPDFDocument document)
- {
- foreach (var sig in SignatureList)
- {
- sig.VerifySignatureWithDocument(document);
- }
- }
- }
- }
|