Browse Source

编辑-自测bug修复,详细见自测文档

lvle 1 year ago
parent
commit
5771df6d27

+ 33 - 15
PDF Office/Model/AnnotPanel/FontBoard.cs

@@ -85,6 +85,16 @@ namespace PDF_Master.Model.AnnotPanel
         #endregion 初始化下拉框或列表默认的数据
 
         #region 属性
+
+        //文字内容对齐
+        private string _strtextAlign;
+
+        public string StrTextAlign
+        {
+            get { return _strtextAlign; }
+            set { SetProperty(ref _strtextAlign, value); }
+        }
+
         /// <summary>
         /// 预设样式
         /// </summary>
@@ -175,25 +185,33 @@ namespace PDF_Master.Model.AnnotPanel
 
                 }
                 SetProperty(ref _currentFontFamily, value);
-                switch (value.Content.ToString())
+                if (value.Content != null)
                 {
-                    case "Courier New":
-                        FontFamilySelectedIndex = 0;
-                        break;
-
-                    case "Helvetica":
-                    case "Arial":
-                        FontFamilySelectedIndex = 1;
-                        break;
-
-                    case "Times New Roman":
-                        FontFamilySelectedIndex = 2;
-                        break;
+                    switch (value.Content.ToString())
+                    {
+                        case "Courier New":
+                            FontFamilySelectedIndex = 0;
+                            break;
+
+                        case "Helvetica":
+                        case "Arial":
+                            FontFamilySelectedIndex = 1;
+                            break;
+
+                        case "Times New Roman":
+                            FontFamilySelectedIndex = 2;
+                            break;
+                    }
                 }
+                else
+                {
+                    FontFamilySelectedIndex = 0;
+                }
+                
             }
         }
 
-        private int fontFamilySelectedIndex;
+        private int fontFamilySelectedIndex = 0;
 
         public int FontFamilySelectedIndex
         {
@@ -330,7 +348,7 @@ namespace PDF_Master.Model.AnnotPanel
             set { SetProperty(ref _fontWeight, value); }
         }
 
-        private int fontStyleSelectedIndex;
+        private int fontStyleSelectedIndex = 0;
 
         public int FontStyleSelectedIndex
         {

+ 0 - 1
PDF Office/ViewModels/PropertyPanel/AnnotPanel/FreetextAnnotPropertyViewModel.cs

@@ -850,7 +850,6 @@ namespace PDF_Master.ViewModels.PropertyPanel.AnnotPanel
         {
             BasicVm.FillColor = new SolidColorBrush(Annot.BgColor);
             BasicVm.FillOpacity = Annot.Transparency;
-
             FontVm.FontColor = new SolidColorBrush(Annot.FontColor);
 
             bool isExist = FontVm.GetCurrentPresetFont(Annot);

+ 10 - 2
PDF Office/ViewModels/PropertyPanel/PDFEdit/ImageEditPropertyViewModel.cs

@@ -161,7 +161,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
             CropModeCommand = new DelegateCommand(CropMode);
             CancelCropCommand = new DelegateCommand(CancelCropImg);
             RestoreCropCommand = new DelegateCommand(RestoreCropImg);
-            EditImgModeCommand = new DelegateCommand(EditImgMode);
+            EditImgModeCommand = new DelegateCommand(EditImgMode);      
         }
 
         #region Command实现
@@ -285,10 +285,18 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                 {
                     TextEditEvent.ReplaceImagePath = openFileDialog.FileName;
                     TextEditEvent.UpdatePDFEditByEventArgs();
+                    ReplaceimgTask();
                 }
-            }
+            }       
         }
 
+        //此处只有多线程 ReplaceimgTask()才有作用
+        async Task ReplaceimgTask()
+        {
+            await Task.Delay(100);
+            GetImagePreView();
+
+        }
         private void CropMode()
         {
             IsCrop = true;

+ 100 - 30
PDF Office/ViewModels/PropertyPanel/PDFEdit/TextEditPropertyViewModel.cs

@@ -171,6 +171,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;
                     }
                 }
             }
@@ -181,6 +185,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
         /// </summary>
         private void CustomFontStyle()
         {
+
             if (CurrentPresetFont != null)
             {
                 ContextMenu menu;
@@ -220,7 +225,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
             if (string.IsNullOrEmpty(CurrentFontFamily.ValueStr) == false)
             {
              
-                GetCurrentFontFamily(TextEditEvent.FontName, TextEditEvent.FontName);
+                //GetCurrentFontFamily(TextEditEvent.FontName, TextEditEvent.FontName);
             }
             if (CurrentPresetFont != null)
             {
@@ -276,12 +281,14 @@ 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;
 
                 //Dictionary<AnnotAttrib, object> AnnotAttribDir = new Dictionary<AnnotAttrib, object>();
                 //AnnotAttribDir.Add(AnnotAttrib.IsItalic,FontStyleItem == FontStyles.Italic);
                 //AnnotAttribDir.Add(AnnotAttrib.IsBold, FontWeightItem == FontWeights.Bold);
                 //PropertyPanel.UpdateAnnotAllAttribs(AnnotAttribDir);
-               //GetFontWeights_Style(TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal, TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal);
+                //GetFontWeights_Style(TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal, TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal);
 
 
                 if (CurrentPresetFont != null)
@@ -448,18 +455,22 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                 switch ((string)obj)
                 {
                     case "AlignLeft":
+                        GetAnnotAlign(TextAlignment.Left);
                         TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignLeft;
                         break;
 
                     case "AlignCenter":
+                        GetAnnotAlign(TextAlignment.Center);
                         TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignMiddle;
                         break;
 
                     case "AlignRight":
+                        GetAnnotAlign(TextAlignment.Right);
                         TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignRight;
                         break;
 
                     case "Align":
+                        GetAnnotAlign(TextAlignment.Justify);
                         TextEditEvent.TextAlign = ComPDFKit.PDFPage.Edit.TextAlignType.AlignNone;
                         break;
                 }
@@ -468,7 +479,32 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
             }
         }
 
+        //文本内容对齐
+        private void GetAnnotAlign(TextAlignment align)
+        {
+            switch (align)
+            {
+                case TextAlignment.Left:
+                    StrTextAlign = "Left";
+                    break;
+
+                case TextAlignment.Center:
+                    StrTextAlign = "Center";
+                    break;
+
+                case TextAlignment.Right:
+                    StrTextAlign = "Right";
+                    break;
+
+                case TextAlignment.Justify:
+                    StrTextAlign = "Justify";
+                    break;
 
+                default:
+                    StrTextAlign = "None";
+                    break;
+            }
+        }
         private void SelectedColor(object obj)
         {
             if (obj != null)
@@ -496,7 +532,8 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
         {
             if (CurrentFontSize != null)
             {
-                GetCurrentFontSize((int)CurrentFontSize.Value);
+                CurrentFontSize = new ComboDataItem(TextEditEvent.FontSize);
+                //GetCurrentFontSize((int)CurrentFontSize.Value);
                 //PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.FontSize,CurrentFontSize.Value);
 
             }
@@ -889,7 +926,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                         }
                         break;
                     case FontSetModeType.FontWeight_Style:
-                        //UpdateFontWeight_Style();
+                        UpdateFontWeight_Style();
                         TextEditEvent.IsBold = FontWeightItem == FontWeights.Bold;
                         TextEditEvent.IsItalic = FontStyleItem == FontStyles.Italic;
                         TextEditEvent.UpdatePDFEditByEventArgs();
@@ -923,19 +960,30 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
 
             SelectColor = new SolidColorBrush(TextEditEvent.FontColor);
             CurrentFontSize =new ComboDataItem(TextEditEvent.FontSize);
-            //CurrentFontFamily = new ComboDataItem(TextEditEvent.FontName, TextEditEvent.FontName);
+            
+            CurrentFontFamily = new ComboDataItem(TextEditEvent.FontName, TextEditEvent.FontName);
             FontStyleItem = TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal;
             FontWeightItem = TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal;
-           
+            GetFontWeights_Style(FontStyleItem, FontWeightItem);
+         
 
             bool isExist = false;
-            if (TextEditEvent.FontSize == 0)
-            {
-                isExist = false;
-            }
-            else
+            //List<PresetFontItem> presetFontItems = TextFont.GetCachePresetFontList();
+             //遍历样式
+            foreach (var item in PresetFontList)
             {
-                isExist = true;
+                if (TextEditEvent.FontSize == item.mFontSize && TextEditEvent.IsBold == (item.mFontWeight == FontWeights.Bold) && TextEditEvent.IsItalic == (item.mFontStyle == FontStyles.Italic)
+                    && (TextEditEvent.FontName == item.mFontFamily.Source || TextEditEvent.FontName == "Arial" && item.mFontFamily.Source == "Helvetica")
+                    )
+                {
+                    if (item.mTag != "Custom")
+                    {
+                        CurrentPresetFont = new ComboDataItem(item.mTag, item.mTagContent);
+                        isExist = true;
+                    }
+
+                    break;
+                }
             }
             if (isExist == false)
             {
@@ -944,7 +992,7 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                 CurrentPresetFont = new ComboDataItem("Custom", "Custom");
                 GetCurrentFontSize((int)TextEditEvent.FontSize);
 
-                GetCurrentFontFamily(TextEditEvent.FontName, TextEditEvent.FontName);
+                GetCurrentFontFamily("Helvetica", "Helvetica");
                 GetFontWeights_Style(TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal, TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal);
             }
             else
@@ -958,38 +1006,60 @@ namespace PDF_Master.ViewModels.PropertyPanel.PDFEdit
                     {
                         if (item.mTag != "Custom")
                         {
-                            CurrentFontSize = new ComboDataItem(TextEditEvent.FontSize);
+                            //CurrentFontSize = new ComboDataItem(TextEditEvent.FontSize);
                             GetCurrentFontSize(item.mFontSize);
                             if (item.mFontFamily != null)
                             {
-                                CurrentFontFamily = new ComboDataItem(TextEditEvent.FontName, TextEditEvent.FontName);
+                                //CurrentFontFamily = new ComboDataItem(TextEditEvent.FontName, TextEditEvent.FontName);
                                 GetCurrentFontFamily(item.mFontFamily.ToString(), item.mFontFamily.ToString());
                             }
-                            FontStyleItem = item.mFontStyle;
-                            FontWeightItem = item.mFontWeight;
+                            //FontStyleItem = item.mFontStyle;
+                            //FontWeightItem = item.mFontWeight;
                             GetFontWeights_Style(TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal, TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal);
                         }
-                        TextAlign = TextEditEvent.TextAlign;
+                      
                     }
                 }
             }
-            //if (TextEditEvent != null && TextEditEventList.Count == 1)
-            //{
-            //    SelectColor = new SolidColorBrush(TextEditEvent.FontColor);
+            //初始化传入的对齐方式
+            switch (TextEditEvent.TextAlign.ToString())
+            {
+                case "AlignLeft":
+                    GetAnnotAlign(TextAlignment.Left);
+                    break;
 
-            //    GetCurrentFontSize((int)TextEditEvent.FontSize);
+                case "AlignCenter":
+                    GetAnnotAlign(TextAlignment.Center);
+                    break;
 
-            //    if (TextEditEvent.FontName != null)
-            //    {
-            //        GetCurrentFontFamily(TextEditEvent.FontName, TextEditEvent.FontName);
-            //    }
+                case "AlignRight":
+                    GetAnnotAlign(TextAlignment.Right);
+                    break;
 
-            //    GetFontWeights_Style(TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal, TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal);
-            //    TextAlign = TextEditEvent.TextAlign;
+                case "Align":
+                    GetAnnotAlign(TextAlignment.Justify);
+                    break;
+            }
+            TextAlign = TextEditEvent.TextAlign;
+            TextEditEvent.UpdatePDFEditByEventArgs();
+        
+        //if (TextEditEvent != null && TextEditEventList.Count == 1)
+        //{
+        //    SelectColor = new SolidColorBrush(TextEditEvent.FontColor);
 
+        //    GetCurrentFontSize((int)TextEditEvent.FontSize);
 
-            //}
-        }
+        //    if (TextEditEvent.FontName != null)
+        //    {
+        //        GetCurrentFontFamily(TextEditEvent.FontName, TextEditEvent.FontName);
+        //    }
+
+        //    GetFontWeights_Style(TextEditEvent.IsItalic ? FontStyles.Italic : FontStyles.Normal, TextEditEvent.IsBold ? FontWeights.Bold : FontWeights.Normal);
+        //    TextAlign = TextEditEvent.TextAlign;
+
+
+        //}
+    }
 
         public bool IsNavigationTarget(NavigationContext navigationContext) { return true; }
 

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

@@ -287,7 +287,11 @@ namespace PDF_Master.ViewModels.Tools
                     regions.RequestNavigate(RegionNames.PropertyRegionName, btnToProperty[type], parameters);
                 }));
 
-                ShowPropertyPanel(true);
+                if(e!=null)
+                {
+                    ShowPropertyPanel(true);
+                }
+               
             }
         }
         private void ShowPropertyPanel(bool show = true)

+ 2 - 0
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -1987,6 +1987,8 @@ namespace PDF_Master.ViewModels
                     PDFViewer.SetMouseMode(MouseModes.PDFEdit);
                     CommonDrawData.PDFEditCoverBrush = brush;
                     CommonDrawData.PDFEditCoverPen = new System.Windows.Media.Pen(System.Windows.Media.Brushes.Red, 1);
+                    PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
+                    PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
                     //SelectedPrpoertyPanel("TextEditProperty", null);
                     //IsPropertyOpen = true;
                 }

+ 15 - 10
PDF Office/Views/PropertyPanel/PDFEdit/TextEditProperty.xaml

@@ -13,7 +13,9 @@
     xmlns:local="clr-namespace:PDF_Master.Views.PropertyPanel"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:pdfedit="clr-namespace:PDF_Master.Views.PropertyPanel.PDFEdit"
+    xmlns:pdfedit1="clr-namespace:PDF_Master.ViewModels.PropertyPanel.PDFEdit"
     xmlns:prism="http://prismlibrary.com/"
+    d:DataContext="{d:DesignInstance Type=pdfedit1:TextEditPropertyViewModel}"
     d:DesignHeight="450"
     d:DesignWidth="260"
     prism:ViewModelLocator.AutoWireViewModel="True"
@@ -31,7 +33,7 @@
             <Convert:BoolToVisible x:Key="BoolToVisible" />
             <Convert:InvertBoolToVisibleConvert x:Key="InvertBoolToVisibleConvert" />
             <Convert:InvertBoolConvert x:Key="InvertBoolConvert" />
-
+            <Convert:TextAlignToCheckedConverter x:Key="TextAlignToCheckedConverter" />
             <DataTemplate x:Key="FontStyleData">
                 <Grid>
                     <TextBlock Foreground="Black" Text="{Binding mFontStyleName}" />
@@ -121,8 +123,8 @@
                     <Grid>
                         <CompositeControl:CustomComboControl
                             x:Name="FontTitleBox"
+                            Title="{Binding Title, Mode=TwoWay, NotifyOnSourceUpdated=True}"
                             Width="188"
-                             Title="{Binding Title, Mode=TwoWay, NotifyOnSourceUpdated=True}"
                             Height="32"
                             HorizontalAlignment="Left"
                             IsSelectedEmpty="{Binding IsSelectedEmpty}"
@@ -209,22 +211,23 @@
                                 </i:Interaction.Triggers>
                             </CompositeControl:CustomComboControl>
                         </Grid>
-                        
-                        
+
+
                         <Grid>
                             <StackPanel Orientation="Horizontal">
                                 <RadioButton
                                     x:Name="TextAlignLeftBtn"
                                     Width="32"
-                                    Margin="8,0"
                                     Height="32"
+                                    Margin="8,0"
+                                    VerticalAlignment="Bottom"
                                     VerticalContentAlignment="Center"
                                     Background="Transparent"
                                     Foreground="#616469"
                                     GroupName="TextAlign"
-                                    IsChecked="True"
+                                    IsChecked="{Binding StrTextAlign, Mode=OneWay, Converter={StaticResource TextAlignToCheckedConverter}, ConverterParameter=AlignLeft}"
                                     Style="{DynamicResource GreyBgRadioBtnStyle}"
-                                    Tag="AlignLeft" VerticalAlignment="Bottom">
+                                    Tag="AlignLeft">
                                     <RadioButton.Content>
                                         <Grid Width="32" Height="32">
                                             <Canvas Margin="5,10,0,0">
@@ -271,6 +274,7 @@
                                     Background="Transparent"
                                     Foreground="#616469"
                                     GroupName="TextAlign"
+                                    IsChecked="{Binding StrTextAlign, Mode=OneWay, Converter={StaticResource TextAlignToCheckedConverter}, ConverterParameter=AlignCenter}"
                                     Style="{DynamicResource GreyBgRadioBtnStyle}"
                                     Tag="AlignCenter">
                                     <RadioButton.Content>
@@ -316,12 +320,13 @@
                                     x:Name="TextAlignRightBtn"
                                     Grid.Column="2"
                                     Width="32"
-                                    Margin="8,0"
                                     Height="32"
+                                    Margin="8,0"
                                     VerticalContentAlignment="Center"
                                     Background="Transparent"
                                     Foreground="#616469"
                                     GroupName="TextAlign"
+                                    IsChecked="{Binding StrTextAlign, Mode=OneWay, Converter={StaticResource TextAlignToCheckedConverter}, ConverterParameter=AlignRight}"
                                     Style="{DynamicResource GreyBgRadioBtnStyle}"
                                     Tag="AlignRight">
                                     <RadioButton.Content>
@@ -367,7 +372,6 @@
                                     x:Name="TextAlignBtn"
                                     Grid.Column="3"
                                     Width="32"
-                                    Visibility="Collapsed"
                                     Height="32"
                                     Margin="8,0"
                                     VerticalContentAlignment="Center"
@@ -375,7 +379,8 @@
                                     Foreground="#616469"
                                     GroupName="TextAlign"
                                     Style="{DynamicResource GreyBgRadioBtnStyle}"
-                                    Tag="Align">
+                                    Tag="Align"
+                                    Visibility="Collapsed">
                                     <RadioButton.Content>
                                         <Grid Width="32" Height="32">
                                             <Canvas Margin="5,10,0,0">

+ 2 - 1
PDF Office/Views/PropertyPanel/PDFEdit/TextEditProperty.xaml.cs

@@ -31,7 +31,8 @@ namespace PDF_Master.Views.PropertyPanel.PDFEdit
         private void UserControl_Loaded(object sender, RoutedEventArgs e)
         {
             InitEventHandler();
-            InitVariable();
+            //不需要在cs中初始化
+            //InitVariable();
         }
 
         private void InitEventHandler()