Browse Source

编辑-bug17766,17838,18424解决,编辑-bug-17678

lvle 1 year ago
parent
commit
79fcdb1f7a

+ 6 - 1
PDF Office/CustomControl/CompositeControl/CustomComboControl.xaml.cs

@@ -73,7 +73,12 @@ namespace PDF_Master.CustomControl.CompositeControl
         public void SetContent(string content)
         {
             Content = content;
-        }
+        }
+
+        public static explicit operator double(ComboDataItem v)
+        {
+            throw new NotImplementedException();
+        }
     }
 
     /// <summary>

+ 40 - 2
PDF Office/CustomControl/CompositeControl/SlidComboControl.xaml.cs

@@ -170,7 +170,7 @@ namespace PDF_Master.CustomControl.CompositeControl
             }
         }
         public static readonly DependencyProperty SelectedIndexProperty =
-           DependencyProperty.Register("SelectedIndex", typeof(int), typeof(SlidComboControl), new PropertyMetadata(0));
+                   DependencyProperty.Register("SelectedIndex", typeof(int), typeof(SlidComboControl), new PropertyMetadata(-1, SelectedIndexPropertyChanged));
         public double Value
         {
             get { return (double)GetValue(ValueProperty); }
@@ -187,6 +187,23 @@ namespace PDF_Master.CustomControl.CompositeControl
             
                 Trace.WriteLine("SelectedValuePropertyChanged" + value);
                 control.combox.SelectedItems = new ComboDataItem(value, control.Unit);
+                //判断滑动条的值是否与combox中的项匹配
+                if (control != null && control.combox.ItemSource != null)
+                {
+                    for (int i = 0; i < control.combox.ItemSource.Count; i++)
+                    {
+                        if (value == control.combox.ItemSource[i].Value)
+                        {
+                            return;
+                        }
+                        if(i==control.combox.ItemSource.Count-1)
+                        {
+                            control.combox.SelectedIndex = -1;
+                            control.combox.SelectedItems = new ComboDataItem(value, control.Unit);
+                        }
+                    }
+                }
+
             }
         }
 
@@ -196,7 +213,27 @@ namespace PDF_Master.CustomControl.CompositeControl
             set { SetValue(ItemsSourceProperty, value); }
         }
         public static readonly DependencyProperty ItemsSourceProperty =
-           DependencyProperty.Register("ItemsSource", typeof(List<ComboDataItem>), typeof(SlidComboControl), new PropertyMetadata(null, SelectedItemsSourcePropertyChanged));
+           DependencyProperty.Register("ItemsSource", typeof(List<ComboDataItem>), typeof(SlidComboControl), new PropertyMetadata(null, SelectedItemsSourcePropertyChanged));
+
+        //选中项触发属性
+        private static void SelectedIndexPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            var control = d as SlidComboControl;
+            var selectedIndex = (int)e.NewValue;
+            if (control != null /*&& control.IsSelectedEmpty == false*/)
+            {
+                //删掉了selectedIndex != -1,设置不选中任何选项的情况
+                //删掉了control.SelectedItems = null;避免崩溃
+                if (control.combox.Items != null && control.combox.Items.Count > 0)
+                {
+                    control.combox.SelectedIndex = selectedIndex;
+                    if (control.combox.SelectedItems != null)
+                        control.combox.SelectedItems = (ComboDataItem)control.combox.SelectedItems;
+
+                }
+                control.combox.UpdateSelectedIndex();
+            }
+        }
 
 
         private static void SelectedItemsSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
@@ -215,6 +252,7 @@ namespace PDF_Master.CustomControl.CompositeControl
             if(e.LeftButton == MouseButtonState.Pressed)
             {
                 ValueChanged?.Invoke(ThicknessSlider.Value, null);
+
             }
         }
     }

+ 1 - 1
PDF Office/Model/AnnotPanel/FontBoard.cs

@@ -548,7 +548,7 @@ namespace PDF_Master.Model.AnnotPanel
                 fontFamily = "Helvetica";
                 uiStr = "Helvetica";
             }
-            if(fontFamily == "Times-Roman")
+            if(fontFamily == "Times-Roman"|| fontFamily == "Times")
             {
                 uiStr = "Times New Roman";
             }

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

@@ -50,6 +50,11 @@ namespace PDF_Master.Model
 
         public static string TextEditToolContentViewModel = "TextEditToolContentViewModel";
 
+        /// <summary>
+        /// 保存方式
+        /// </summary>
+        public static string Open = "Open";
+
         /// <summary>
         /// 页码集合
         /// </summary>

+ 13 - 56
PDF Office/ViewModels/Dialog/ServiceDialog/SubscriptionDialogViewModel.cs

@@ -25,8 +25,8 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
     {
         public string Title => "";
         private WatermarkInfo watermarkInfo;
-        private CPDFWatermark watermark;
         private ViewContentViewModel viewContentViewModel;
+        private string open;
         public event Action<IDialogResult> RequestClose;
 
         #region 文案
@@ -119,62 +119,18 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
         /// </summary>
         private void WarermarkSaving()
         {
-            CPDFViewer cPDFViewer = new CPDFViewer();
-            
-            Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
-            StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
-                if (resourceInfo != null)
-                {
-                    using (Stream stream = resourceInfo.Stream)
-                    {
-                        cPDFViewer = viewContentViewModel.PDFViewer;
-                        BitmapFrame frame = null;
-                        int width = 0;
-                        int height = 0;
-                        BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
-                        if (decoder != null && decoder.Frames.Count > 0)
-                        {
-                            frame = decoder.Frames[0];
-                        }
-                        if (frame != null)
-                        {
-                            var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
-                            width = frame.PixelWidth;
-                            height = frame.PixelHeight;
-                            frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
-                            watermark = cPDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
-                            watermark.SetImage(ImageArray, width, height);
-                            watermark.SetScale(1);
-                            watermark.SetRotation(0);
-                            watermark.SetOpacity(255);
-                            watermark.SetFront(true);
-                            watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
-                            watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
-                            watermark.SetFullScreen(false);
-                            watermark.SetVertOffset(0);
-                            watermark.SetHorizOffset(0);
-                            watermark.SetHorizontalSpacing(0);
-                            watermark.SetVerticalSpacing(0);
-                        string setpages = $"0-{cPDFViewer.Document.PageCount.ToString()}";
-                            watermark.SetPages(setpages);
-                            watermark.UpdateWatermark();
-                        cPDFViewer.Document.ReleasePages();
-                        cPDFViewer.ReloadDocument();
-                        viewContentViewModel.saveAsFile(null,cPDFViewer);
-                        Close();
-
-                    }
-                   
-                }
-
-               
+            String IsFormSave = "FormSave";
+           
+            if(open!=null)
+            {
+                Close();
             }
-
-
-
-
-         
-
+            else
+            {
+                viewContentViewModel.saveAsFile(null, IsFormSave);
+                Close();
+            }
+            
         }
 
         /// <summary>
@@ -238,6 +194,7 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
         public void OnDialogOpened(IDialogParameters parameters)
         {
             parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
+            parameters.TryGetValue<String>(ParameterNames.Open, out open);
 
         }
 

+ 1 - 0
PDF Office/ViewModels/Tools/TextEditToolContentViewModel.cs

@@ -304,6 +304,7 @@ namespace PDF_Master.ViewModels.Tools
                             }
                             {
                                 PDFViewer.ClearSelectPDFEdit();
+                                PDFViewer.RemovePDFEditEmptyText();
                                 PDFViewer.ReloadDocument();
                             }
                           

+ 134 - 34
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -52,6 +52,9 @@ using System.Windows.Documents;
 using ComPDFKit.PDFPage;
 using ComPDFKitViewer;
 using SplitMode = PDF_Master.EventAggregators.SplitMode;
+using System.Windows.Resources;
+using System.Windows.Media.Imaging;
+using ComPDFKit.PDFWatermark;
 
 namespace PDF_Master.ViewModels
 {
@@ -238,6 +241,8 @@ namespace PDF_Master.ViewModels
 
         public BOTAContentViewModel botaViewModel { get; set; }
 
+        private CPDFWatermark watermark;
+
         public bool IsSettingOut = false;
         public IRegionManager region;
 
@@ -2717,7 +2722,6 @@ namespace PDF_Master.ViewModels
         /// </summary>
         public bool saveFile(bool autosave = false)
         {
-            bool flg = false;
             try
             {
                 //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
@@ -2727,16 +2731,12 @@ namespace PDF_Master.ViewModels
                     value.Add(ParameterNames.ViewContentViewModel, this);
                     dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
                     {
-                        if (dialogResult.Result == ButtonResult.Cancel)
-                        {
-                            flg = true;
-                        }
+
                     });
 
-                    if (flg == false)
-                    {
-                        return false;
-                    }
+
+                    return false;
+
                 }
 
                 if ((string.IsNullOrEmpty(PDFViewer.Document.FilePath) || mainViewModel.NewFile) && !autosave)
@@ -2984,29 +2984,10 @@ namespace PDF_Master.ViewModels
         /// <summary>
         /// 另存为或新文档保存逻辑
         /// </summary>
-        public bool saveAsFile(Action RedactionAction = null, CPDFViewer cPDFViewer = null)
+        public bool saveAsFile(Action RedactionAction = null, String IsFormSave=null)
         {
-            if (cPDFViewer == null)
+            if(IsFormSave=="FormSave")
             {
-                bool flg = false;
-                //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
-                if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && App.IsUsedVIP == true)
-                {
-                    DialogParameters value = new DialogParameters();
-                    value.Add(ParameterNames.ViewContentViewModel, this);
-                    dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
-                    {
-                        if (dialogResult.Result == ButtonResult.Cancel)
-                        {
-                            flg = true;
-                        }
-                    });
-
-                    if (flg == false)
-                    {
-                        return false;
-                    }
-                }
                 var dlg = new Microsoft.Win32.SaveFileDialog();
                 dlg.Filter = Properties.Resources.OpenDialogFilter;
                 dlg.FileName = PDFViewer.Document.FileName;
@@ -3044,6 +3025,52 @@ namespace PDF_Master.ViewModels
                         }
 
                         PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
+                            Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
+                            StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
+                            if (resourceInfo != null)
+                            {
+                                using (Stream stream = resourceInfo.Stream)
+                                {
+                                    BitmapFrame frame = null;
+                                    int width = 0;
+                                    int height = 0;
+                                    BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
+                                    if (decoder != null && decoder.Frames.Count > 0)
+                                    {
+                                        frame = decoder.Frames[0];
+                                    }
+                                    if (frame != null)
+                                    {
+                                        var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
+                                        width = frame.PixelWidth;
+                                        height = frame.PixelHeight;
+                                        frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
+                                        watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
+                                        watermark.SetImage(ImageArray, width, height);
+                                        watermark.SetScale(1);
+                                        watermark.SetRotation(0);
+                                        watermark.SetOpacity(255);
+                                        watermark.SetFront(true);
+                                        watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
+                                        watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
+                                        watermark.SetFullScreen(false);
+                                        watermark.SetVertOffset(0);
+                                        watermark.SetHorizOffset(0);
+                                        watermark.SetHorizontalSpacing(0);
+                                        watermark.SetVerticalSpacing(0);
+                                        string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
+                                        watermark.SetPages(setpages);
+                                        watermark.UpdateWatermark();
+                                        PDFViewer.Document.ReleasePages();
+                                        PDFViewer.ReloadDocument();
+
+                                    
+
+                                }
+
+                            }
+                        }
+
                         result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
                         if (result)
                         {
@@ -3065,9 +3092,30 @@ namespace PDF_Master.ViewModels
             }
             else
             {
+               
+                bool flg = false;
+                //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
+                if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && App.IsUsedVIP == true)
+                {
+                    DialogParameters value = new DialogParameters();
+                    value.Add(ParameterNames.ViewContentViewModel, this);
+                    value.Add(ParameterNames.Open, "saveAs");
+                    dialogs.ShowDialog(DialogNames.SubscriptionDialog, value, dialogResult =>
+                    {
+                        if (dialogResult.Result == ButtonResult.Cancel)
+                        {
+                            flg = true;
+                        }
+                    });
+
+                    if (flg == false)
+                    {
+                        return false;
+                    }
+                }
                 var dlg = new Microsoft.Win32.SaveFileDialog();
                 dlg.Filter = Properties.Resources.OpenDialogFilter;
-                dlg.FileName = cPDFViewer.Document.FileName;
+                dlg.FileName = PDFViewer.Document.FileName;
                 if (dlg.ShowDialog() == true && !string.IsNullOrEmpty(dlg.FileName))
                 {
                     bool result = false;
@@ -3083,7 +3131,7 @@ namespace PDF_Master.ViewModels
                     }
                     else
                     {
-                        string oldpath = cPDFViewer.Document.FilePath;
+                        string oldpath = PDFViewer.Document.FilePath;
                         string openPassword = string.Empty;
                         string permissionsPassword = string.Empty;
                         CPDFPermissionsInfo cPDFPermissionsInfo = CreateDefaultPermissionsInfo();
@@ -3101,8 +3149,58 @@ namespace PDF_Master.ViewModels
                             passwordInfo.PermissionsPassword = permissionsPassword;
                         }
 
-                        cPDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
-                        result = cPDFViewer.Document.WriteToFilePath(dlg.FileName);
+                        PDFViewer.Document.Encrypt(openPassword, permissionsPassword, cPDFPermissionsInfo);
+                        if(flg==true)
+                        {
+                            Uri resourceUri = new Uri("pack://application:,,,/PDF Master;component/Resources/Service/Warermark.png");
+                            StreamResourceInfo resourceInfo = Application.GetResourceStream(resourceUri);
+                            if (resourceInfo != null)
+                            {
+                                using (Stream stream = resourceInfo.Stream)
+                                {
+                                    BitmapFrame frame = null;
+                                    int width = 0;
+                                    int height = 0;
+                                    BitmapDecoder decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
+                                    if (decoder != null && decoder.Frames.Count > 0)
+                                    {
+                                        frame = decoder.Frames[0];
+                                    }
+                                    if (frame != null)
+                                    {
+                                        var ImageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
+                                        width = frame.PixelWidth;
+                                        height = frame.PixelHeight;
+                                        frame.CopyPixels(ImageArray, frame.PixelWidth * 4, 0);
+                                        watermark = PDFViewer.Document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_IMG);
+                                        watermark.SetImage(ImageArray, width, height);
+                                        watermark.SetScale(1);
+                                        watermark.SetRotation(0);
+                                        watermark.SetOpacity(255);
+                                        watermark.SetFront(true);
+                                        watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_TOP);
+                                        watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_LEFT);
+                                        watermark.SetFullScreen(false);
+                                        watermark.SetVertOffset(0);
+                                        watermark.SetHorizOffset(0);
+                                        watermark.SetHorizontalSpacing(0);
+                                        watermark.SetVerticalSpacing(0);
+                                        string setpages = $"0-{PDFViewer.Document.PageCount.ToString()}";
+                                        watermark.SetPages(setpages);
+                                        watermark.UpdateWatermark();
+                                        PDFViewer.Document.ReleasePages();
+                                        PDFViewer.ReloadDocument();
+
+                                    }
+
+                                }
+
+                            }
+                        }
+                          
+                        
+
+                        result = PDFViewer.Document.WriteToFilePath(dlg.FileName);
                         if (result)
                         {
                             mainViewModel.NewFile = false;
@@ -3120,7 +3218,9 @@ namespace PDF_Master.ViewModels
                 }
                 else
                     return false;
+
             }
+
         }
 
         /// <summary>

+ 0 - 1
PDF Office/Views/PropertyPanel/PDFEdit/ImageEditProperty.xaml

@@ -173,7 +173,6 @@
                     FontSize="14"
                     Foreground="Black"
                     IsEnabled="{Binding IsCrop, Converter={StaticResource InvertBoolConvert}}"
-                    IsEnabledChanged="BtnReplace_IsEnabledChanged"
                     Style="{StaticResource btn.sec}"
                     Tag="Replace"
                     Visibility="{Binding IsMultiSelectImage, Converter={StaticResource InvertBoolToVisibleConvert}}" />

+ 0 - 14
PDF Office/Views/PropertyPanel/PDFEdit/ImageEditProperty.xaml.cs

@@ -44,19 +44,5 @@ namespace PDF_Master.Views.PropertyPanel.PDFEdit
         }
 
 
-        private void BtnReplace_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
-        {
-           
-            if (BtnReplace.IsEnabled == false)
-            {
-                Items2 = slid.combox.SelectedItems;
-                slid.combox.SelectedItems = null;
-            }
-              
-            else
-            {
-                slid.combox.SelectedItems = Items2 ;
-            }
-        } 
     }
 }