zhuyi 2 лет назад
Родитель
Сommit
c24971bfcf

+ 10 - 0
PDF Office/Model/AnnotPanel/Signature.cs

@@ -26,6 +26,16 @@ namespace PDF_Office.Model.AnnotPanel
                 SetProperty(ref sourcePath, value);
             }
         }
+        private string drawingPath;
+
+        public string DrawingPath
+        {
+            get { return drawingPath; }
+            set
+            {
+                SetProperty(ref drawingPath, value);
+            }
+        }
         public SignatureType Type { get; set; }
         public DrawingAttributes DrawingAttributesObject { get; set; }
     }

+ 39 - 1
PDF Office/ViewModels/PropertyPanel/AnnotPanel/SignatureAnnotPropertyViewModel.cs

@@ -15,6 +15,8 @@ using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Ink;
 using System.Windows.Media.Imaging;
 
 namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
@@ -50,7 +52,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 case SignatureType.Drawing:
                     {
                         StampAnnotArgs stampArgs = new StampAnnotArgs();
-                        stampArgs.SetInkData(tuple.Item2, signature.DrawingAttributesObject.Width, signature.DrawingAttributesObject.Color);
+                        stampArgs.SetInkData(GetPoints(signature.DrawingPath), signature.DrawingAttributesObject.Width, signature.DrawingAttributesObject.Color);
                         PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
                         PDFViewer.SetToolParam(stampArgs);
                     }
@@ -59,6 +61,30 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                     break;
             }
         }
+        private List<List<Point>> GetPoints(string Path)
+        {
+            StrokeCollection Strokes;
+            List<List<Point>> RawPointList = new List<List<Point>>();
+            using (FileStream strokeStream = File.OpenRead(Path))
+            {
+                Strokes = new StrokeCollection(strokeStream);
+            }
+
+            for (int kk = 0; kk < Strokes.Count; kk++)
+            {
+                List<Point> p = new List<Point>();
+                RawPointList.Add(p);
+                for (int gg = 0; gg < Strokes[kk].StylusPoints.Count; gg++)
+                {
+                    var point = Strokes[kk].StylusPoints[gg].ToPoint();
+
+                    if (point.X >= 0 && point.Y >= 0)
+                        RawPointList[kk].Add(point);
+
+                }
+            }
+            return RawPointList;
+        }
         private void ShowDialog()
         {
             bool result = true;
@@ -101,6 +127,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             {
                 Signature.SourcePath = viewModel.SaveToPath;
             }
+            Signature.DrawingPath = viewModel.DrawingSaveToPath;
             Signature.Type = (SignatureType)viewModel.TabItemIndex;
             Signature.DrawingAttributesObject = viewModel.DrawingAttributeObject;
             SignatureList.Add(Signature);
@@ -156,6 +183,11 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         {
             int index = SignatureList.IndexOf(Item);
             App.CachePath.AddToDeleteFiles(Item.SourcePath);
+            if (!string.IsNullOrEmpty(Item.DrawingPath))
+            {
+                App.CachePath.AddToDeleteFiles(Item.DrawingPath);
+
+            }
             SignatureList.RemoveAt(index);
         }
         public void DeleteAll()
@@ -163,6 +195,12 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             foreach (Signature item in SignatureList)
             {
                 App.CachePath.AddToDeleteFiles(item.SourcePath);
+
+                if (!string.IsNullOrEmpty(item.DrawingPath))
+                {
+                    App.CachePath.AddToDeleteFiles(item.DrawingPath);
+
+                }
             }
             SignatureList.Clear();
         }

+ 41 - 9
PDF Office/ViewModels/PropertyPanel/AnnotPanel/SignatureCreateDialogViewModel.cs

@@ -1,4 +1,5 @@
-using ComPDFKitViewer.PdfViewer;
+using ComPDFKitViewer.AnnotEvent;
+using ComPDFKitViewer.PdfViewer;
 using Microsoft.Win32;
 using PDF_Office.Model;
 using Prism.Commands;
@@ -198,6 +199,10 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         public string RemoveBackgroundSaveToPath { get; private set; }
 
+        public string DrawingSaveToPath { get; private set; }
+
+
+
         /// <summary>
         /// 用于判断是否更换了文件,更换了文件则需要重新计算去背功能
         /// </summary>
@@ -463,18 +468,45 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 case 1:
                     {
 
-                        var guid = Guid.NewGuid().ToString();
-                        var path = System.IO.Path.Combine(App.CurrentPath, "Signature", "FreeHand");
-                        if (!Directory.Exists(path))
-                        {
-                            Directory.CreateDirectory(path);
-                        }
+                        var FreeHandpath = App.CachePath.SignatureFreeHandPath;
                         string name = Guid.NewGuid().ToString();
-                        path = System.IO.Path.Combine(path, name);
-                        using (System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.Create))
+                        FreeHandpath = System.IO.Path.Combine(FreeHandpath, name);
+                        using (System.IO.FileStream stream = new System.IO.FileStream(FreeHandpath, System.IO.FileMode.Create))
                         {
                             StrokesObject.Save(stream);
                         }
+
+                        StampAnnotArgs stampArgs = new StampAnnotArgs();
+
+                        List<List<System.Windows.Point>> RawPointList = new List<List<System.Windows.Point>>();
+                        for (int kk = 0; kk < StrokesObject.Count; kk++)
+                        {
+                            List<System.Windows.Point> p = new List<System.Windows.Point>();
+                            RawPointList.Add(p);
+                            for (int gg = 0; gg < StrokesObject[kk].StylusPoints.Count; gg++)
+                            {
+                                var point = StrokesObject[kk].StylusPoints[gg].ToPoint();
+
+                                if (point.X >= 0 && point.Y >= 0)
+                                    RawPointList[kk].Add(point);
+
+                            }
+                        }
+                        DrawingSaveToPath = FreeHandpath;
+
+                        stampArgs.SetInkData(RawPointList, drawingAttributes.Width, drawingAttributes.Color);
+                        var writeStamp = stampArgs.GetStampDrawing();
+
+                        FreeHandpath = App.CachePath.SignatureStampPath;
+                        string thumbnailName = Guid.NewGuid().ToString();
+                        FreeHandpath = System.IO.Path.Combine(FreeHandpath, thumbnailName);
+                        using (FileStream stream5 = new FileStream(FreeHandpath, FileMode.Create))
+                        {
+                            PngBitmapEncoder encoder5 = new PngBitmapEncoder();
+                            encoder5.Frames.Add(BitmapFrame.Create(writeStamp));
+                            encoder5.Save(stream5);
+                        }
+                        SaveToPath = FreeHandpath;
                     }
                     break;
                 case 2: