lvle 1 год назад
Родитель
Сommit
2d50a5ae17

+ 4 - 2
PDF Office/App.xaml.cs

@@ -208,7 +208,10 @@ namespace PDF_Master
                 Settings.Default.ADDate = new PDFSettings.ADDate();
             }
 
-
+            if (Settings.Default.PDFEditList == null)
+            {
+                Settings.Default.PDFEditList = new PDFSettings.PDFEditList();
+            }
             if (Settings.Default.UserDate == null)
             {
                 Settings.Default.UserDate = new PDFSettings.UserDate();
@@ -548,7 +551,6 @@ namespace PDF_Master
             containerRegistry.RegisterForNavigation<TextAnnotProperty>();
             containerRegistry.RegisterForNavigation<ImageEditProperty>();
             containerRegistry.RegisterForNavigation<TextEditProperty>();
-            containerRegistry.RegisterForNavigation<ImageEditProperty>();
             containerRegistry.RegisterForNavigation<ImageTextEditProperty>();
             containerRegistry.RegisterForNavigation<ScanPropertyPanel>();
             containerRegistry.RegisterForNavigation<BatesContent>();

+ 2 - 0
PDF Office/Model/ParameterNames.cs

@@ -46,6 +46,8 @@ namespace PDF_Master.Model
 
         public static string Tag = "Tag";
 
+        public static string TextEditToolContentViewModel = "TextEditToolContentViewModel";
+
         /// <summary>
         /// 页码集合
         /// </summary>

+ 11 - 0
PDF Office/Properties/Settings.Designer.cs

@@ -294,5 +294,16 @@ namespace PDF_Master.Properties {
                 this["IsNewInViewContent"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        public global::PDFSettings.PDFEditList PDFEditList {
+            get {
+                return ((global::PDFSettings.PDFEditList)(this["PDFEditList"]));
+            }
+            set {
+                this["PDFEditList"] = value;
+            }
+        }
     }
 }

+ 3 - 0
PDF Office/Properties/Settings.settings

@@ -74,5 +74,8 @@
     <Setting Name="IsNewInViewContent" Type="System.Boolean" Scope="User">
       <Value Profile="(Default)">True</Value>
     </Setting>
+    <Setting Name="PDFEditList" Type="PDFSettings.PDFEditList" Scope="User">
+      <Value Profile="(Default)" />
+    </Setting>
   </Settings>
 </SettingsFile>

Разница между файлами не показана из-за своего большого размера
+ 38 - 38
PDF Office/Styles/ContextMenuTextEditStyle.xaml


+ 38 - 18
PDF Office/ViewModels/PropertyPanel/PDFEdit/ImageEditPropertyViewModel.cs

@@ -3,11 +3,13 @@ using ComPDFKitViewer.PdfViewer;
 using Microsoft.Win32;
 using PDF_Master.Helper;
 using PDF_Master.Model;
+using PDF_Master.ViewModels.Tools;
 using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Regions;
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -19,7 +21,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
 {
     public class ImageEditPropertyViewModel : PDFEditVM, INavigationAware
     {
-        
+        public TextEditToolContentViewModel TextEditToolContentViewModel;
         #region 快捷键
         private void ShortCut_KeyDown(object sender, KeyEventArgs e)
         {
@@ -81,10 +83,25 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                 
             }
         }
-
         //是否为图片裁剪状态
         private bool _isCrop = false;
         public bool IsCrop { get { return _isCrop; } set { SetProperty(ref _isCrop, value); } }
+        public  TextEditToolContentViewModel _viewModel1;
+
+
+        //public ImageEditPropertyViewModel(TextEditToolContentViewModel viewModel1)
+        //{
+        //    _viewModel1 = viewModel1;
+        //    _viewModel1.PropertyChanged += OnViewModel1PropertyChanged;
+        //}
+
+        private void OnViewModel1PropertyChanged(object sender, PropertyChangedEventArgs e)
+        {
+            if (e.PropertyName == "flg")
+            {
+                IsCrop = _viewModel1.flg;
+            }
+        }
 
         //选中的图像
         private System.Windows.Media.Imaging.BitmapSource _currentImg;
@@ -135,7 +152,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
 
         public ImageEditPropertyViewModel()
         {
-           
             InitCommand();
         }
 
@@ -289,7 +305,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
             }
         }
 
-        //替换裁剪
+        //替换图片
         private void ReplaceImg()
         {
             OpenFileDialog openFileDialog = new OpenFileDialog();
@@ -405,8 +421,11 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
 
             navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
             navigationContext.Parameters.TryGetValue<List<PDFEditEvent>>(ParameterNames.AnnotEvent, out TextEditEventList);
+            navigationContext.Parameters.TryGetValue<TextEditToolContentViewModel>(ParameterNames.TextEditToolContentViewModel, out TextEditToolContentViewModel);
             if (PDFViewer != null)
             {
+                _viewModel1 = TextEditToolContentViewModel;
+                _viewModel1.PropertyChanged += OnViewModel1PropertyChanged;
                 PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
                 PDFViewer.PDFEditActiveHandler += PDFViewer_PDFEditActiveHandler;
                 PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
@@ -536,32 +555,33 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
         private void PDFViewer_PDFEditActiveHandler(object sender, List<PDFEditEvent> e)
         {
             //退出编辑模式
-            IsCrop = false;
+               IsCrop = false;
         }
 
         //右键逻辑
         private void PDFViewer_PDFEditCommandHandler(object sender, PDFEditCommand e)
         {
-
+            
             if (e == null)
                 return;
 
             switch (e.CommandType)
             {
                 case CommandType.Context:
-                     if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
-                    {
-                        if (IsCrop == true)
-                            {
-                            e.PopupMenu =CropImgPDFEdit(sender);
-                        }
-                        else
-                        {
-                            e.PopupMenu = SelectImgPDFEdit(sender);
-                        }
+                    // if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
+                    //{
+                    //    if (IsCrop == true)
+                    //        {
+                    //        e.PopupMenu =CropImgPDFEdit(sender);
+                    //    }
+                    //    else
+                    //    {
+                    //        e.PopupMenu = SelectImgPDFEdit(sender);
+                    //    }
                         
-                    }
-                    else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.None)
+                    //}
+                    //else 
+                    if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.None)
                     {
                         e.PopupMenu = EmptyStateMenu(sender);
 

+ 58 - 17
PDF Office/ViewModels/PropertyPanel/PDFEdit/TextEditPropertyViewModel.cs

@@ -173,10 +173,10 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                             GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
                         }
                         GetFontWeights_Style(item.mFontStyle, item.mFontWeight);
-                        CurrentFontSize = new ComboDataItem(TextEditEvent.FontSize);
-                        CurrentFontFamily = new ComboDataItem(TextEditEvent.FontName, TextEditEvent.FontName);
-                        FontStyleItem = TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal;
-                        FontWeightItem = TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal;
+                        //CurrentFontSize = new ComboDataItem(TextEditEvent.FontSize);
+                        //CurrentFontFamily = new ComboDataItem(TextEditEvent.FontName, TextEditEvent.FontName);
+                        //FontStyleItem = TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal;
+                        //FontWeightItem = TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal;
                     }
                 }
             }
@@ -198,14 +198,16 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                 else
                 {
                     menu = SelectAnnotContextMenu(false);
-
+                    var defaultlists = TextFont.GetPresetFontStyle();
+                    var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
                     var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
                     if (currentItem.mTag != "Custom")
                     {
-                        if (FontWeightItem != currentItem.mFontWeight ||
-                            FontStyleItem != currentItem.mFontStyle ||
-                            CurrentFontSize.Value != currentItem.mFontSize ||
-                            CurrentFontFamily.ValueStr != currentItem.mFontFamily.Source)
+                        
+                        if (FontWeightItem != defaulItem.mFontWeight ||
+                            FontStyleItem != defaulItem.mFontStyle ||
+                            CurrentFontSize.Value != defaulItem.mFontSize ||
+                            CurrentFontFamily.ValueStr != defaulItem.mFontFamily.Source)
                         {
                             menu = SelectAnnotContextMenu(true);
                         }
@@ -271,8 +273,8 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
             if (CurrrentFontWeightStyle != null)
             {
                 UpdateFontWeight_Style();
-                FontStyleItem = TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal;
-                FontWeightItem = TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal;
+                //FontStyleItem = TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal;
+                //FontWeightItem = TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal;
 
                 if (CurrentPresetFont != null)
                 {
@@ -509,10 +511,10 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
         //设置字体大小
         private void FontSizeChanged(object obj)
         {
-            if (CurrentFontSize != null)
-            {
-                CurrentFontSize = new ComboDataItem(TextEditEvent.FontSize);
-            }
+            //if (CurrentFontSize != null)
+            //{
+            //    CurrentFontSize = new ComboDataItem(TextEditEvent.FontSize);
+            //}
             if (CurrentPresetFont != null)
             {
                 var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
@@ -643,7 +645,11 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                 if (TextEditEventList != null && TextEditEventList.Count > 0)
                 {
                     TextEditEvent = TextEditEventList[0];
-                    GetPDFEdit();
+                    if(TextEditEvent.FontName!=""&& TextEditEvent.FontName !=null)
+                    {
+                        GetPDFEdit();
+                    }
+                    
                     if (TextEditEventList.Count > 1)
                         IsSelectedEmpty = true;
                     else
@@ -665,6 +671,41 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                         IsLayoutAvgAlign = false;
                     }
                 }
+                else if(TextEditEventList==null)
+                {
+                    var defaultlists = TextFont.GetPresetFontStyle();
+
+                        var defaulItem = defaultlists.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
+                        if (defaulItem != null)
+                        {
+                            var currentItem = PresetFontList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
+                            if (currentItem != null)
+                            {
+                           
+
+                                currentItem.mTagContent = defaulItem.mTagContent;
+                                currentItem.mFontStyle = defaulItem.mFontStyle;
+                                currentItem.mFontWeight = defaulItem.mFontWeight;
+                                currentItem.mFontFamily = defaulItem.mFontFamily;
+                                currentItem.mFontSize = defaulItem.mFontSize;
+                                GetCurrentFontFamily(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
+                                GetCurrentFontSize(currentItem.mFontSize);
+                                GetFontWeights_Style(currentItem.mFontStyle, currentItem.mFontWeight);
+                                CurrentPresetFont = new ComboDataItem(defaulItem.mTag, defaulItem.mTagContent);
+                                SelectedPresetFont();
+
+                            SelectColor = new SolidColorBrush(Colors.Black);
+                            CurrentFontSize = new ComboDataItem(currentItem.mFontSize);
+
+                            CurrentFontFamily = new ComboDataItem(currentItem.mFontFamily.ToString(), currentItem.mFontFamily.ToString());
+                            FontStyleItem = FontStyles.Normal;
+                            FontWeightItem = FontWeights.Normal;
+                            
+                        }
+                        
+                    }
+
+                }
 
                 PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
                 PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
@@ -677,7 +718,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
         //文本内容改变触发
         private void FontMode_ChangedValue(object sender, FontSetModeType e)
         {
-            if (sender != null)
+            if (sender != null&& TextEditEvent != null)
             {
                 switch (e)
                 {

+ 263 - 18
PDF Office/ViewModels/Tools/TextEditToolContentViewModel.cs

@@ -33,13 +33,23 @@ namespace PDF_Master.ViewModels.Tools
         public bool IsTextEdit
         {
             get { return _isTextEdit; }
-            set { SetProperty(ref _isTextEdit, value); }
+            set { SetProperty(ref _isTextEdit, value);
+            }
         }
         private bool _isImgEdit = false;
         public bool IsImgEdit
         {
             get { return _isImgEdit; }
-            set { SetProperty(ref _isImgEdit, value); }
+            set
+            {
+                SetProperty(ref _isImgEdit, value);
+            }
+        }
+        private bool _flg=false;
+        public bool flg
+        {
+            get { return _flg; }
+            set { SetProperty(ref _flg, value); }
         }
         #endregion
 
@@ -57,7 +67,7 @@ namespace PDF_Master.ViewModels.Tools
         {
            
           
-          regions = regionManager;
+             regions = regionManager;
             InitCommand();
             InitBtnToProperty();
         }
@@ -102,13 +112,13 @@ namespace PDF_Master.ViewModels.Tools
             CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
          
             //复制
-            customMenu.SetMenuBinding(1, ApplicationCommands.Copy);
+            customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
             //剪切
-            customMenu.SetMenuBinding(2, ApplicationCommands.Cut);
+            customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
             //粘贴
-            customMenu.SetMenuBinding(3, ApplicationCommands.Paste);
+            customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
             //删除
-            customMenu.SetMenuBinding(4, ApplicationCommands.Delete);
+            customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
 
             customMenu.SetVisibilityProperty(6, false);
 
@@ -158,7 +168,65 @@ namespace PDF_Master.ViewModels.Tools
             return popMenu;
         }
         #endregion
+        #region 图片右键菜单
 
+        //选中图像时
+        private ContextMenu SelectImgPDFEdit(object sender)
+        {
+            var popMenu = App.Current.FindResource("SelectImgMenu") as ContextMenu;
+            CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
+            //复制
+            customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
+            //剪切
+            customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
+
+            //粘贴
+            customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
+            //删除
+            customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
+            //裁剪
+            customMenu.SetMenuBinding(4, new DelegateCommand(CropMode));
+            //替换
+            customMenu.SetMenuBinding(5, new DelegateCommand(ReplaceImg));
+            //导出
+            customMenu.SetMenuBinding(6, new DelegateCommand(ExportImg));
+            return popMenu;
+        }
+
+        //选中裁剪图像时
+        private ContextMenu CropImgPDFEdit(object sender)
+        {
+            var popMenu = App.Current.FindResource("CropImgMenu") as ContextMenu;
+            CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
+
+            //确认裁剪
+            customMenu.SetMenuBinding(0, new DelegateCommand(CropImg));
+            //取消裁剪
+            customMenu.SetMenuBinding(1, new DelegateCommand(CancelCropImg));
+            //还原裁剪
+            customMenu.SetMenuBinding(2, new DelegateCommand(RestoreCropImg));
+            return popMenu;
+        }
+        //多选图片右键
+        private ContextMenu SelectMoreImage(object sender)
+        {
+            var popMenu = App.Current.FindResource("SelectMoreImageMenu") as ContextMenu;
+            CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
+            //复制
+            customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
+            //剪切
+            customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
+            //粘贴
+            customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
+            //删除
+            customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
+            //导出
+            customMenu.SetMenuBinding(4, new DelegateCommand(ExportImg));
+
+
+            return popMenu;
+        }
+        #endregion
         #region 快捷键
         private void ShortCut_KeyDown(object sender, KeyEventArgs e)
         {
@@ -177,7 +245,18 @@ namespace PDF_Master.ViewModels.Tools
                             {
                                 PDFViewer.RemoveTool(false);
                             }
-
+                            else if (IsTextEdit == true || IsImgEdit == true)
+                            {
+                                IsImgEdit = false;
+                                IsTextEdit = false;
+                                PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
+
+                                //文本和图像都框选
+                                PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
+                                PDFViewer.SetMouseMode(MouseModes.PDFEdit);
+                                PDFViewer.ReloadDocument();
+                                ShowPropertyPanel(false);
+                            }
                         }
 
                         else if (PDFViewer.ToolManager != null && PDFViewer.GetPDFEditCreateType() == ComPDFKit.PDFPage.CPDFEditType.EditImage)
@@ -188,8 +267,20 @@ namespace PDF_Master.ViewModels.Tools
                             {
                                 PDFViewer.RemoveTool(false);
                             }
+                            else if (IsTextEdit == true || IsImgEdit == true)
+                            {
+                                IsImgEdit = false;
+                                IsTextEdit = false;
+                                PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
+
+                                //文本和图像都框选
+                                PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
+                                PDFViewer.SetMouseMode(MouseModes.PDFEdit);
+                                PDFViewer.ReloadDocument();
+                                ShowPropertyPanel(false);
+                            }
                         }
-
+                        
 
 
 
@@ -207,7 +298,6 @@ namespace PDF_Master.ViewModels.Tools
         }
         #endregion
 
-
         //模式选择进入
         public void AddContent(object obj)
         {
@@ -238,7 +328,10 @@ namespace PDF_Master.ViewModels.Tools
                     PDFViewer.SetMouseMode(MouseModes.PDFEdit);
                     PDFViewer.ReloadDocument();
                     PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
-                   
+
+                    List<PDFEditEvent> pDFEditEvents = new List<PDFEditEvent>();
+                    AddToPropertyPanel("Text", null);
+                    ShowPropertyPanel(true);
                 }
                 else
                 {
@@ -251,6 +344,7 @@ namespace PDF_Master.ViewModels.Tools
                     PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
                     PDFViewer.SetMouseMode(MouseModes.PDFEdit);
                     PDFViewer.ReloadDocument();
+        
                 }
             }
             else
@@ -261,9 +355,9 @@ namespace PDF_Master.ViewModels.Tools
 
                 //文本和图像都框选
                 PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
-
                 PDFViewer.SetMouseMode(MouseModes.PDFEdit);
                 PDFViewer.ReloadDocument();
+                ShowPropertyPanel(false);
 
             }
         }
@@ -279,7 +373,139 @@ namespace PDF_Master.ViewModels.Tools
         {
             EnterEditMode(true, "Image");
         }
+        //进入裁剪模式
+        private void CropMode()
+        {
+            if (TextEditEvent != null)
+            {
+              
+                TextEditEvent.ClipImage = true;
+                TextEditEvent.UpdatePDFEditByEventArgs();
+                flg = true;
+            }
+        }
+
+        //取消裁剪
+        private void CancelCropImg()
+        {
+            if (TextEditEvent != null)
+            {
+                TextEditEvent.ClipImage = false;
+                TextEditEvent.CancelClip();
+                flg = false;
+                TextEditEvent.UpdatePDFEditByEventArgs();
+            }
+        }
+
+        //还原裁剪
+        private void RestoreCropImg()
+        {
+            if (TextEditEvent != null)
+            {
+                TextEditEvent.RestoreClip();
+            }
+        }
 
+        //完成裁剪
+        private void CropImg()
+        {
+            if (TextEditEvent != null)
+            {
+                TextEditEvent.SaveClip();
+                TextEditEvent.ClipImage = false;
+                flg = false;
+                TextEditEvent.UpdatePDFEditByEventArgs();
+                GetImagePreView();
+            }
+        }
+        //导出图片
+        private void ExportImg()
+        {
+            if (PDFViewer == null || TextEditEvent == null || TextEditEvent.EditType != ComPDFKit.PDFPage.CPDFEditType.EditImage) return;
+
+            System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();
+            folder.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
+
+            if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+            {
+                if (string.IsNullOrEmpty(folder.SelectedPath))
+                    return;
+
+                var keyValueList = PDFViewer.GetSelectedImages();
+                int i = 0;
+                foreach (var bitmap in keyValueList)
+                {
+                    foreach (var bitmapItem in bitmap.Value)
+                    {
+                        bitmapItem.Save(folder.SelectedPath + "\\" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
+                        i++;
+                    }
+                }
+
+                var strFilePath = folder.SelectedPath + "\\0.png";
+                CommonHelper.ShowFileBrowser(strFilePath);
+            }
+        }
+            //替换图片
+            private void ReplaceImg()
+        {
+            OpenFileDialog openFileDialog = new OpenFileDialog();
+            openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
+            openFileDialog.Multiselect = true;
+            if ((bool)openFileDialog.ShowDialog())
+            {
+                if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
+                {
+                    TextEditEvent.ReplaceImagePath = openFileDialog.FileName;
+                    TextEditEvent.UpdatePDFEditByEventArgs();
+                    ReplaceimgTask();
+                }
+            }
+        }
+
+        //此处只有异步 ReplaceimgTask()才有作用
+        async Task ReplaceimgTask()
+        {
+            await Task.Delay(100);
+            GetImagePreView();
+
+        }
+        //选中的图像
+        private System.Windows.Media.Imaging.BitmapSource _currentImg;
+        public System.Windows.Media.Imaging.BitmapSource CurrentImg { get { return _currentImg; } set { SetProperty(ref _currentImg, value); } }
+        private void GetImagePreView()
+        {
+            try
+            {
+                var list = PDFViewer.GetSelectedImages();
+                if (list != null && list.Count > 0)
+                {
+                    System.Drawing.Bitmap bitmap = null;
+                    foreach (var item in list)
+                    {
+                        if (item.Value.Count > 0)
+                        {
+                            bitmap = item.Value[0];
+                            break;
+                        }
+                    }
+
+                    if (bitmap != null)
+                    {
+                        IntPtr ip = bitmap.GetHbitmap();
+                        System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, Int32Rect.Empty,
+                        System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
+                        CurrentImg = bitmapSource;
+                    }
+
+                }
+            }
+            catch
+            {
+
+            }
+
+        }
         #endregion
 
 
@@ -292,6 +518,7 @@ namespace PDF_Master.ViewModels.Tools
                 NavigationParameters parameters = new NavigationParameters();
                 parameters.Add(ParameterNames.PDFViewer, PDFViewer);
                 parameters.Add(ParameterNames.AnnotEvent, e);
+                parameters.Add(ParameterNames.TextEditToolContentViewModel, this);
                 System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
                 {
                     regions.RequestNavigate(RegionNames.PropertyRegionName, btnToProperty[type], parameters);
@@ -319,6 +546,11 @@ namespace PDF_Master.ViewModels.Tools
 
             if (PDFViewer != null)
             {
+                if(viewContentViewModel.TabSelectedIndex==2)
+                {
+                    IsImgEdit = false;
+                    IsTextEdit = false;
+                }
               //左键激活
                 PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
                 PDFViewer.PDFEditActiveHandler += PDFViewer_PDFEditActiveHandler;
@@ -346,7 +578,7 @@ namespace PDF_Master.ViewModels.Tools
             PDFViewer.SelectPDFEdit(e,true);
         }
 
-
+        protected PDFEditEvent TextEditEvent;
         //左键激活逻辑
         private void PDFViewer_PDFEditActiveHandler(object sender, List<PDFEditEvent> e)
         {
@@ -354,6 +586,7 @@ namespace PDF_Master.ViewModels.Tools
 
             if (e != null && e.Count > 0)
             {
+                TextEditEvent=e[0];
                 bool isText = false;
                 bool isImg = false;
                 foreach (var item in e)
@@ -392,11 +625,14 @@ namespace PDF_Master.ViewModels.Tools
                 AddToPropertyPanel("PropertyPanelContent", null);
             }
 
+          
+            
         }
 
         //右键点击逻辑
         private void PDFViewer_PDFEditCommandHandler(object sender, PDFEditCommand e)
         {
+            
             if (e == null)
                 return;
 
@@ -412,8 +648,7 @@ namespace PDF_Master.ViewModels.Tools
                     else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditText)
                     {
 
-                           if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditText)
-                    {
+                         
                         //文字编辑
                         if (e.PressOnBorder == true)
                         {
@@ -435,11 +670,20 @@ namespace PDF_Master.ViewModels.Tools
                         }
 
                     }
-
+                   else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
+                    {
+                        if (e.IsClipState == true)
+                        {
+                            e.PopupMenu = CropImgPDFEdit(sender);
+                        }
+                        else
+                        {
+                            e.PopupMenu = SelectImgPDFEdit(sender);
+                        }
 
                     }
-
-                    break;
+                  
+                        break;
 
                 default:
                     e.DoCommand();
@@ -450,6 +694,7 @@ namespace PDF_Master.ViewModels.Tools
             {
                 e.Handle = true;
             }
+            flg = e.IsClipState;
         }
 
 

+ 20 - 0
PDFSettings/PDFEditList.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Media;
+
+namespace PDFSettings
+{
+    public class PDFEditList
+    {
+        public string mTag { get; set; }
+        public string mTagContent { get; set; }
+        public int mFontSize { get; set; }
+        public FontFamily mFontFamily { get; set; }
+        public FontStyle mFontStyle { get; set; }
+        public FontWeight mFontWeight { get; set; }
+    }
+}

+ 1 - 0
PDFSettings/PDFSettings.csproj

@@ -98,6 +98,7 @@
     <Compile Include="DpiHelpers.cs" />
     <Compile Include="BackgroundTemplateList.cs" />
     <Compile Include="list.cs" />
+    <Compile Include="PDFEditList.cs" />
     <Compile Include="PDFToolsList.cs" />
     <Compile Include="PresetFontList.cs" />
     <Compile Include="ProductActiveInfo.cs" />