Browse Source

标记密文-补充标记密文逻辑

ZhouJieSheng 2 years ago
parent
commit
642a08fb25

+ 1 - 0
PDF Office/Styles/ContextMenuStyle.xaml

@@ -86,6 +86,7 @@
         <MenuItem
             Name="MenuDelete"
             Command="{x:Static ApplicationCommands.Delete}"
+            CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}"
             Header="Delete" />
         <Separator Style="{StaticResource HorizontalSeparatorStyle}" />
         <MenuItem Name="MenuProperties" Header="Properties..." />

+ 223 - 3
PDF Office/ViewModels/Dialog/Redaction/MarkSettingDialogViewModel.cs

@@ -1,4 +1,7 @@
-using Prism.Commands;
+using ComPDFKitViewer;
+using ComPDFKitViewer.AnnotEvent;
+using PDF_Office.Model;
+using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Services.Dialogs;
 using System;
@@ -6,6 +9,8 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Media;
 
 namespace PDF_Office.ViewModels.Dialog.Redaction
 {
@@ -15,16 +20,190 @@ namespace PDF_Office.ViewModels.Dialog.Redaction
 
         public event Action<IDialogResult> RequestClose;
 
+        private RedactionAnnotArgs annotArgs;
         public DelegateCommand OkCommand { get; set; }
 
         public DelegateCommand CancelCommand { get; set; }
 
+        public DelegateCommand<string> AlignCommand { get; set; }
+
+
+        private Color lineColor;
+
+        public Color LineColor
+        {
+            get { return lineColor; }
+            set
+            {
+                SetProperty(ref lineColor, value);
+            }
+        }
+
+        private Color bgColor;
+
+        public Color BgColor
+        {
+            get { return bgColor; }
+            set
+            {
+                SetProperty(ref bgColor, value);
+            }
+        }
+
+        private Color fontColor;
+
+        public Color FontColor
+        {
+            get { return fontColor; }
+            set
+            {
+                SetProperty(ref fontColor, value);
+            }
+        }
+
+
+        private bool isUserText;
+
+        public bool IsUseText
+        {
+            get { return isUserText; }
+            set
+            {
+                SetProperty(ref isUserText, value);
+            }
+        }
+
+        private bool leftChecked = true;
+
+        public bool LeftChecked
+        {
+            get { return leftChecked; }
+            set
+            {
+                SetProperty(ref leftChecked, value);
+            }
+        }
+
+        private bool centerChecked;
+
+        public bool CenterChecked
+        {
+            get { return centerChecked; }
+            set
+            {
+                SetProperty(ref centerChecked, value);
+            }
+        }
+
+
+        private bool rightChecked;
+
+        public bool RightChecked
+        {
+            get { return rightChecked; }
+            set
+            {
+                SetProperty(ref rightChecked, value);
+            }
+        }
+
+        private bool strechChecked;
+
+        public bool StrechChecked
+        {
+            get { return strechChecked; }
+            set
+            {
+                SetProperty(ref strechChecked, value);
+            }
+        }
+
+
+        private string overText;
+
+        public string OvertText
+        {
+            get { return overText; }
+            set
+            {
+                SetProperty(ref overText, value);
+            }
+        }
+
+        private int fontFamilySelectedIndex;
+
+        public int FontFamilySelectedIndex
+        {
+            get { return fontFamilySelectedIndex; }
+            set
+            {
+                SetProperty(ref fontFamilySelectedIndex, value);
+            }
+        }
+
+        private string fontFamily = "";
+
+        private int fontWeightSelectedIndex;
+
+        public int FontWeightSelectedIndex
+        {
+            get { return fontWeightSelectedIndex; }
+            set
+            {
+                SetProperty(ref fontWeightSelectedIndex, value);
+            }
+        }
+
+        private FontWeight fontWeight = FontWeights.Regular;
+
+        private int fontSizeSelectedIndex;
+
+        public int FontSizeSelectedIndex
+        {
+            get { return fontSizeSelectedIndex; }
+            set
+            {
+                SetProperty(ref fontSizeSelectedIndex, value);
+            }
+        }
+
+        public List<string> FontFamilys { get; set; }
+
+        public List<string> FontWeight { get; set; }
+
+        public List<string> FontSizes { get; set; }
+
 
 
         public MarkSettingDialogViewModel()
         {
             OkCommand = new DelegateCommand(ok);
             CancelCommand = new DelegateCommand(cancel);
+            AlignCommand = new DelegateCommand<string>(align);
+
+            InitFontFamily();
+            InitFontWeight();
+            InitFontSize();
+        }
+
+        private void InitFontFamily()
+        {
+            FontFamilys.Add("Courier New");
+            FontFamilys.Add("Arial");
+            FontFamilys.Add("Times New Roman");
+        }
+
+        private void InitFontWeight()
+        {
+            FontWeight.Add("Regular");
+            FontWeight.Add("Bold");
+            FontWeight.Add("Italic");
+            FontWeight.Add("Bold Italic");
+        }
+
+        private void InitFontSize()
+        {
+            FontSizes.Add("Auto");
         }
 
         private void cancel()
@@ -34,7 +213,26 @@ namespace PDF_Office.ViewModels.Dialog.Redaction
 
         private void ok()
         {
-            
+            //annotArgs.UpdateAttrib(AnnotAttrib.FillColor, frm.SaveredactionArgs.BgColor);
+            //annotArgs.UpdateAttrib(AnnotAttrib.NoteText, frm.SaveredactionArgs.Content);
+            //annotArgs.UpdateAttrib(AnnotAttrib.FontColor, frm.SaveredactionArgs.FontColor);
+
+            //annotArgs.UpdateAttrib(AnnotAttrib.Color, frm.SaveredactionArgs.LineColor);
+
+            //annotArgs.UpdateAttrib(AnnotAttrib.FontSize, frm.SaveredactionArgs.FontSize);
+
+            //annotArgs.UpdateAttrib(AnnotAttrib.TextAlign, frm.SaveredactionArgs.Align);
+            //if (IsUseText)
+            //{
+            //    annotArgs.UpdateAttrib(AnnotAttrib.NoteText, string.Empty);
+            //}
+            //annotArgs.UpdateAnnot();
+            RequestClose.Invoke(new DialogResult(ButtonResult.OK));
+        }
+
+        private void align(string tag)
+        {
+
         }
 
         public bool CanCloseDialog()
@@ -49,7 +247,29 @@ namespace PDF_Office.ViewModels.Dialog.Redaction
 
         public void OnDialogOpened(IDialogParameters parameters)
         {
-           
+            annotArgs = parameters.GetValue<RedactionAnnotArgs>(ParameterNames.DataModel);
+
+            BgColor = annotArgs.BgColor;
+            LineColor = annotArgs.LineColor;
+            FontColor = annotArgs.FontColor;
+
+            OvertText = annotArgs.Content;
+            switch (annotArgs.FontFamily.ToString())
+            {
+                case "":
+                    FontFamilySelectedIndex = 0;
+                    break;
+                case "1":
+                    FontFamilySelectedIndex = 1;
+                    break;
+                case "2":
+                    FontFamilySelectedIndex = 2;
+                    break;
+                default:
+                    break;
+            }
+
+
         }
     }
 }

+ 96 - 3
PDF Office/ViewModels/Dialog/Redaction/RepeatMarkDialogViewModel.cs

@@ -1,4 +1,7 @@
-using Prism.Commands;
+using PDF_Office.CustomControl;
+using PDF_Office.Helper;
+using PDF_Office.Model;
+using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Services.Dialogs;
 using System;
@@ -19,15 +22,105 @@ namespace PDF_Office.ViewModels.Dialog.Redaction
 
         public DelegateCommand CancelCommand { get; set; }
 
+        public DelegateCommand<string> CheckedCommand { get; set; }
+
+        private int pageCount;
+        /// <summary>
+        /// 最大页码
+        /// </summary>
+        public int PageCount
+        {
+            get { return pageCount; }
+            set
+            {
+                SetProperty(ref pageCount, value);
+            }
+        }
+
+        private string inputString;
+
+        public string InputString
+        {
+            get { return inputString; }
+            set
+            {
+                SetProperty(ref inputString, value);
+                if (!string.IsNullOrEmpty(value))
+                {
+                    CheckCustomPage();
+                }
+            }
+        }
+
+        public List<int> PageList = new List<int>();
+
         public RepeatMarkDialogViewModel()
         {
             OkCommand = new DelegateCommand(ok);
             CancelCommand = new DelegateCommand(cancel);
+            CheckedCommand = new DelegateCommand<string>(check);
         }
 
-        private void ok()
+        private void check(string args)
         {
+            switch (args)
+            {
+                case "Old":
+                    PageList = new List<int>();
+                    for (int i = 1; i <= pageCount; i++)
+                    {
+                        if (i % 2 != 0)
+                        {
+                            PageList.Add(i - 1);
+                        }
+                    }
+                    break;
+                case "Even":
+                    PageList = new List<int>();
+                    for (int i = 1; i <= pageCount; i++)
+                    {
+                        if (i % 2 == 0)
+                        {
+                            PageList.Add(i - 1);
+                        }
+                    }
+                    break;
+                case "All":
+                    PageList = new List<int>();
+                    for (int i = 0; i < pageCount; i++)
+                    {
+                        PageList.Add(i);
+                    }
+                    break;
+                case "Custom":
+                    if (!string.IsNullOrEmpty(InputString))
+                    {
+                        CheckCustomPage();
+                    }
+                    break;
+                default:
+                    break;
+            }
+        }
 
+        private void CheckCustomPage()
+        {
+            var result = CommonHelper.GetPagesInRange(ref PageList, InputString, pageCount, new char[] { ',' }, new char[] { '-' });
+            if (!result)
+            {
+                AlertsMessage alertsMessage = new AlertsMessage();
+                alertsMessage.ShowDialog("", "页码错误", "ok");
+                InputString = "";
+                return;
+            }
+        }
+
+
+        private void ok()
+        {
+            DialogParameters valuePairs = new DialogParameters();
+            valuePairs.Add(ParameterNames.PageList,PageList);
+            RequestClose.Invoke(new DialogResult(ButtonResult.OK,valuePairs));
         }
 
         private void cancel()
@@ -47,7 +140,7 @@ namespace PDF_Office.ViewModels.Dialog.Redaction
 
         public void OnDialogOpened(IDialogParameters parameters)
         {
-           
+           PageCount = parameters.GetValue<int>(ParameterNames.PageCount);
         }
     }
 }

+ 9 - 1
PDF Office/ViewModels/EditTools/Redaction/RedactionContentViewModel.cs

@@ -145,8 +145,11 @@ namespace PDF_Office.ViewModels.EditTools.Redaction
         /// <param name="args"></param>
         private void SetDefualtProperty(RedactionCommandEventArgs args)
         {
+            var annoteargs = args.args.AnnotEventArgsList[0] as RedactionAnnotArgs;
             DialogParameters keyValues = new DialogParameters();
             keyValues.Add(ParameterNames.DataModel,args.args.AnnotEventArgsList[0] as RedactionAnnotArgs);
+
+            Settings.Default.RedactionsSettings.SetDefualtValue(annoteargs.Content, annoteargs.LineColor,annoteargs.BgColor,annoteargs.FontColor, (int)annoteargs.FontSize,string.IsNullOrEmpty(annoteargs.Content) ? false : true, annoteargs.Align, annoteargs.FontFamily.ToString(),FontWeights.Regular);
         }
 
         /// <summary>
@@ -168,7 +171,12 @@ namespace PDF_Office.ViewModels.EditTools.Redaction
         {
             DialogParameters keyValues = new DialogParameters();
             keyValues.Add(ParameterNames.PageCount,PDFViewer.Document.PageCount);
-            dialogs.ShowDialog(DialogNames.RepeatMarkDialog, keyValues, null);
+            dialogs.ShowDialog(DialogNames.RepeatMarkDialog, keyValues, e=> {
+                if (e.Result == ButtonResult.OK)
+                {
+                    PDFViewer.AddRedaction(e.Parameters.GetValue<List<int>>(ParameterNames.PageList), args.args);
+                }
+            });
         }
         /// <summary>
         /// 应用

+ 44 - 8
PDF Office/Views/Dialog/Redaction/MarkSettingDialog.xaml

@@ -9,8 +9,10 @@
     xmlns:local="clr-namespace:PDF_Office.Views.Dialog.Redaction"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:prism="http://prismlibrary.com/"
+    xmlns:redaction="clr-namespace:PDF_Office.ViewModels.Dialog.Redaction"
     Width="432"
     Height="462"
+    d:DataContext="{d:DesignInstance Type=redaction:MarkSettingDialogViewModel}"
     d:DesignHeight="450"
     d:DesignWidth="800"
     prism:Dialog.WindowStyle="{StaticResource DialogWindowStyle}"
@@ -37,19 +39,26 @@
                     Name="TbOurline"
                     VerticalAlignment="Center"
                     Text="Redaction Mark Outline Color:" />
-                <com:ColorContent Margin="16,0,0,0" ShowColorList="Collapsed" />
+                <com:ColorContent
+                    Margin="16,0,0,0"
+                    SelectedColor="{Binding LineColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                    ShowColorList="Collapsed" />
             </StackPanel>
             <StackPanel Height="32" Orientation="Horizontal">
                 <TextBlock
                     Width="{Binding ElementName=TbOurline, Path=Width}"
                     VerticalAlignment="Center"
                     Text="Redact Area Fill Color:" />
-                <com:ColorContent Margin="16,0,0,0" ShowColorList="Collapsed" />
+                <com:ColorContent
+                    Margin="16,0,0,0"
+                    SelectedColor="{Binding BgColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                    ShowColorList="Collapsed" />
             </StackPanel>
             <CheckBox
                 Name="chkText"
                 Margin="0,16,0,8"
-                Content="Use Overlay Text" />
+                Content="Use Overlay Text"
+                IsChecked="{Binding IsUseText}" />
             <Border
                 Width="400"
                 Height="198"
@@ -60,7 +69,7 @@
                     <cus:TextBoxEx
                         Height="70"
                         VerticalContentAlignment="Top"
-                        Text="123" />
+                        Text="{Binding OvertText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                     <TextBlock
                         Margin="0,10"
                         FontSize="12"
@@ -68,33 +77,58 @@
                         Text="Font" />
 
                     <StackPanel Orientation="Horizontal">
-                        <ComboBox Width="122.67" Height="32" />
                         <ComboBox
                             Width="122.67"
                             Height="32"
-                            Margin="8,0" />
-                        <ComboBox Width="122.67" Height="32" />
+                            ItemsSource="{Binding FontFamilys}"
+                            SelectedIndex="{Binding FontFamilySelectedIndex}" />
+                        <ComboBox
+                            Width="122.67"
+                            Height="32"
+                            Margin="8,0"
+                            ItemsSource="{Binding FontWeight}"
+                            SelectedIndex="{Binding FontWeightSelectedIndex}" />
+                        <ComboBox
+                            Width="122.67"
+                            Height="32"
+                            ItemsSource="{Binding FontSizes}"
+                            SelectedIndex="{Binding FontSizeSelectedIndex}" />
                     </StackPanel>
                     <StackPanel Margin="0,8,0,0" Orientation="Horizontal">
                         <RadioButton
                             Width="32"
                             Height="32"
+                            Command="{Binding AlignCommand}"
+                            CommandParameter="Left"
+                            IsChecked="{Binding LeftChecked, Mode=TwoWay}"
                             Style="{StaticResource RectangleRadionButtonWithCorner}" />
                         <RadioButton
                             Width="32"
                             Height="32"
                             Margin="8,0"
+                            Command="{Binding AlignCommand}"
+                            CommandParameter="Center"
+                            IsChecked="{Binding CenterChecked, Mode=TwoWay}"
                             Style="{StaticResource RectangleRadionButtonWithCorner}" />
                         <RadioButton
                             Width="32"
                             Height="32"
+                            Command="{Binding AlignCommand}"
+                            CommandParameter="Right"
+                            IsChecked="{Binding RightChecked, Mode=TwoWay}"
                             Style="{StaticResource RectangleRadionButtonWithCorner}" />
                         <RadioButton
                             Width="32"
                             Height="32"
                             Margin="8,0"
+                            Command="{Binding AlignCommand}"
+                            CommandParameter="Strech"
+                            IsChecked="{Binding StrechChecked, Mode=TwoWay}"
                             Style="{StaticResource RectangleRadionButtonWithCorner}" />
-                        <com:ColorContent Margin="16,0,0,0" ShowColorList="Collapsed" />
+                        <com:ColorContent
+                            Margin="16,0,0,0"
+                            SelectedColor="{Binding FontColor}"
+                            ShowColorList="Collapsed" />
                     </StackPanel>
                 </StackPanel>
             </Border>
@@ -108,12 +142,14 @@
                 <Button
                     Width="80"
                     Height="32"
+                    Command="{Binding OkCommand}"
                     Content="Apply"
                     Style="{StaticResource Btn.cta}" />
                 <Button
                     Width="80"
                     Height="32"
                     Margin="16,0,0,0"
+                    Command="{Binding CancelCommand}"
                     Content="Cancel"
                     Style="{StaticResource btn.sec}" />
             </StackPanel>

+ 18 - 2
PDF Office/Views/Dialog/Redaction/RepeatMarkDialog.xaml

@@ -6,8 +6,10 @@
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:prism="http://prismlibrary.com/"
+    xmlns:redaction="clr-namespace:PDF_Office.ViewModels.Dialog.Redaction"
     Width="432"
     Height="236"
+    d:DataContext="{d:DesignInstance Type=redaction:RepeatMarkDialogViewModel}"
     d:DesignHeight="450"
     d:DesignWidth="800"
     prism:Dialog.WindowStyle="{StaticResource DialogWindowStyle}"
@@ -19,6 +21,8 @@
             <RadioButton
                 Height="22"
                 VerticalContentAlignment="Center"
+                Command="{Binding CheckedCommand}"
+                CommandParameter="All"
                 Content="All Pages"
                 GroupName="Page"
                 IsChecked="True" />
@@ -26,11 +30,15 @@
                 Height="22"
                 Margin="0,8"
                 VerticalContentAlignment="Center"
+                Command="{Binding CheckedCommand}"
+                CommandParameter="Odd"
                 Content="Odd Pages"
                 GroupName="Page" />
             <RadioButton
                 Height="22"
                 VerticalContentAlignment="Center"
+                Command="{Binding CheckedCommand}"
+                CommandParameter="Even"
                 Content="Even Pages"
                 GroupName="Page" />
 
@@ -43,6 +51,8 @@
                     Name="RbtnCustomPage"
                     Height="22"
                     VerticalContentAlignment="Center"
+                    Command="{Binding CheckedCommand}"
+                    CommandParameter="Custom"
                     Content="Custom"
                     GroupName="Page" />
                 <cus:TextBoxEx
@@ -51,12 +61,16 @@
                     Margin="8,0,0,0"
                     CornerRadius="4"
                     IsEnabled="{Binding ElementName=RbtnCustomPage, Path=IsChecked}"
-                    PlaceholderText="e.g. 1,3-5,10" />
+                    PlaceholderText="e.g. 1,3-5,10"
+                    PreviewKeyDown="TextBoxEx_PreviewKeyDown"
+                    Text="{Binding InputString, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" />
                 <TextBlock
+                    Name="TbSeparator"
                     Margin="8,0,0,0"
                     VerticalAlignment="Center"
+                    FocusVisualStyle="{x:Null}"
                     Text="/ " />
-                <TextBlock VerticalAlignment="Center" Text="1" />
+                <TextBlock VerticalAlignment="Center" Text="{Binding PageCount}" />
             </StackPanel>
         </StackPanel>
         <cus:DialogContent.BottmBar>
@@ -67,12 +81,14 @@
                 <Button
                     Width="80"
                     Height="32"
+                    Command="{Binding OkCommand}"
                     Content="Apply"
                     Style="{StaticResource Btn.cta}" />
                 <Button
                     Width="80"
                     Height="32"
                     Margin="16,0,0,0"
+                    Command="{Binding CancelCommand}"
                     Content="Cancel"
                     Style="{StaticResource btn.sec}" />
             </StackPanel>

+ 8 - 0
PDF Office/Views/Dialog/Redaction/RepeatMarkDialog.xaml.cs

@@ -24,5 +24,13 @@ namespace PDF_Office.Views.Dialog.Redaction
         {
             InitializeComponent();
         }
+
+        private void TextBoxEx_PreviewKeyDown(object sender, KeyEventArgs e)
+        {
+            if(e.Key==Key.Enter)
+            {
+                TbSeparator.Focus();
+            }
+        }
     }
 }

+ 1 - 1
PDF Office/Views/EditTools/Redaction/RedactionContent.xaml

@@ -87,7 +87,7 @@
                     Height="24"
                     Margin="8,0"
                     Padding="8,0"
-                    Command="{Binding RemoveCommand}"
+                    Command="{Binding EraseCommand}"
                     Content="擦除密文"
                     Style="{StaticResource Btn.cta}" />
                 <Button

+ 36 - 0
PDFSettings/RedactionSettings.cs

@@ -28,11 +28,47 @@ namespace PDFSettings
 
         public int FontSize { get { return fontsize; } set { fontsize = value; } }
 
+
+        private FontWeight fontWeight = FontWeights.Regular;
+
+        public FontWeight FontWeight
+        {
+            get { return fontWeight; }
+            set { fontWeight = value; }
+        }
+
+        /// <summary>
+        /// 跟WPF UI一致的字体
+        /// </summary>
+        private string fontFamily = "Helvetica";
+
+        public string FontFamily
+        {
+            get { return fontFamily; }
+            set { fontFamily = value; }
+        }
+
+
+
+
         private bool isusetext = false;
         public bool isUseText { get { return isusetext; } set { isusetext = value; } }
 
         private TextAlignment align = TextAlignment.Left;
         public TextAlignment Align { get { return align; } set { align = value; } }
 
+        public void SetDefualtValue(string content,Color lineColor,Color bgColor,Color fontColor,int FontSize,bool isUserText,TextAlignment align,string fontFamily,FontWeight fontWeight)
+        {
+            this.Content = content;
+            this.LineColor = lineColor;
+            this.BgColor = bgColor;
+            this.FontColor = fontColor;
+            this.FontSize = FontSize;
+            this.isUseText = isUserText;
+            this.Align = align;
+            this.FontFamily = fontFamily;
+            this.FontWeight = fontWeight;
+        }
+
     }
 }