Browse Source

综合-图章添加的高保真,注释的右键菜单,和颜色选择器

zhuyi 1 year ago
parent
commit
3ae03a4216

+ 1 - 0
compdfkit_demo_windows/compdfkit/annotation-ctrl-demo/MainWindow.xaml

@@ -13,6 +13,7 @@
             <ResourceDictionary.MergedDictionaries>
                 <ResourceDictionary Source="pack://application:,,,/compdfkit-assets;component/Styles/ToggleButtonStyle.xaml"></ResourceDictionary>
                 <ResourceDictionary Source="pack://application:,,,/compdfkit-assets;component/Styles/ButtonStyle.xaml"></ResourceDictionary>
+                <ResourceDictionary Source="pack://application:,,,/compdfkit-assets;component/Styles/ComboBoxStyle.xaml"></ResourceDictionary>
             </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
     </Window.Resources>

+ 21 - 0
compdfkit_demo_windows/compdfkit/annotation-ctrl-demo/MainWindow.xaml.cs

@@ -15,6 +15,7 @@ using System.Windows.Annotations;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
 using System.Windows.Input;
+using System.Windows.Media.Animation;
 
 namespace viewer_ctrl_demo
 {
@@ -100,6 +101,12 @@ namespace viewer_ctrl_demo
                         if (e.PressOnLink)
                         {
                             e.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
+                            MenuItem propertyMenu = new MenuItem();
+                            propertyMenu = new MenuItem();
+                            propertyMenu.Header = "Edit";
+                            WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(propertyMenu, "Click", EditLink_Click);
+                            propertyMenu.CommandParameter = e;
+                            e.PopupMenu.Items.Add(propertyMenu);
                         }
                         else if (e.PressOnAnnot)
                         {
@@ -121,11 +128,20 @@ namespace viewer_ctrl_demo
                         }
                     }
                     break;
+                case CommandType.Copy:
+                    e.DoCommand();
+                    break;
+                case CommandType.Cut:
+                case CommandType.Paste:
+                case CommandType.Delete:
+                    e.DoCommand();
+                    break;
                 default:
                     break;
             }
         }
 
+
         private void PasswordUI_Confirmed(object sender, string e)
         {
             if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
@@ -584,6 +600,11 @@ namespace viewer_ctrl_demo
             PropertyContainer.Child = properytPanel;
             PropertyContainer.Visibility = visible;
         }
+
+        private void EditLink_Click(object sender, RoutedEventArgs e)
+        {
+            PropertyContainer.Visibility = Visibility.Visible;
+        }
     }
 }
 

+ 1 - 0
compdfkit_demo_windows/compdfkit/annotation-ctrl-demo/annotation-ctrl-demo.csproj

@@ -43,6 +43,7 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>.\ComPDFKit.Viewer.dll</HintPath>
     </Reference>
+    <Reference Include="PresentationFramework.Aero2" />
     <Reference Include="System" />
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />

File diff suppressed because it is too large
+ 284 - 0
compdfkit_demo_windows/compdfkit/compdfkit-assets/Styles/ComboBoxStyle.xaml


+ 5 - 0
compdfkit_demo_windows/compdfkit/compdfkit-assets/compdfkit-assets.csproj

@@ -38,6 +38,7 @@
     <StartupObject />
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="PresentationFramework.Aero2" />
     <Reference Include="System" />
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />
@@ -58,6 +59,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Styles\ComboBoxStyle.xaml">
+      <Generator>MSBuild:Compile</Generator>
+      <SubType>Designer</SubType>
+    </Page>
     <Page Include="Styles\ListBoxItemStyle.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 5 - 4
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCreateSignatureDialog.xaml

@@ -13,6 +13,7 @@
         <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
                 <ResourceDictionary Source="pack://application:,,,/compdfkit-assets;component/Styles/ButtonStyle.xaml"></ResourceDictionary>
+                <ResourceDictionary Source="pack://application:,,,/compdfkit-assets;component/Styles/ComboBoxStyle.xaml"></ResourceDictionary>
             </ResourceDictionary.MergedDictionaries>
             <convert:UnVisivleConvert x:Key="UnVisivleConvert"/>
             <SolidColorBrush x:Key="TabItem.Selected.Background" Color="#FFFFFF"/>
@@ -343,7 +344,7 @@
                     </Grid>
                     <StackPanel Grid.Row="3" Grid.Column="2" VerticalAlignment="Center" Orientation="Horizontal">
                     <TextBlock Text="Width"  VerticalAlignment="Center" />
-                    <Slider  x:Name="StrokeWidthSlider" Width="96" Margin="12,0,0,0"  VerticalAlignment="Center" ValueChanged="StrokeWidth_ValueChanged"/>
+                    <Slider  x:Name="StrokeWidthSlider" Width="96" Margin="12,0,0,0" Value="4" VerticalAlignment="Center" ValueChanged="StrokeWidth_ValueChanged"/>
                     <TextBox Text="{Binding ElementName=StrokeWidthSlider, Path=Value,Mode=TwoWay}" Width="72" Height="32" VerticalContentAlignment="Center"/>
                     </StackPanel>
                     <StackPanel
@@ -352,7 +353,7 @@
                             HorizontalAlignment="Right"
                             VerticalAlignment="Center"
                             Orientation="Horizontal">
-                        <common:ColorPickerControl x:Name="ColorPickerControl"  ColorChanged="ColorPickerControl_ColorChanged"></common:ColorPickerControl>
+                        <common:ColorPickerControl x:Name="ColorPickerControl" SelectedIndexProperty="1"  ColorChanged="ColorPickerControl_ColorChanged"></common:ColorPickerControl>
                     </StackPanel>
                 </Grid>
             </TabItem>
@@ -367,7 +368,6 @@
                     <TextBox     
                     x:Name="InPutTextBox"    
                     TextChanged="InPutTextBox_TextChanged" Grid.Row="1"
-                    Text="123"
                     BorderThickness="0"
                     Background="#F2F3F5"
                     HorizontalContentAlignment="Center"
@@ -375,6 +375,7 @@
                     <StackPanel Grid.Row="3" Orientation="Horizontal" Grid.ColumnSpan="2">
                         <TextBlock Text="Font" VerticalAlignment="Center"/>
                         <ComboBox Width="232"
+                        Style="{StaticResource ComboBoxStyle1}"
                         Margin="8,0,0,0"
                         SelectionChanged="TextName_SelectionChanged"
                         x:Name="TextName"
@@ -392,7 +393,7 @@
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center"
                         Orientation="Horizontal">
-                        <common:ColorPickerControl x:Name="TextColorPickerControl" ColorChanged="TextColorPickerControl_ColorChanged"></common:ColorPickerControl>
+                        <common:ColorPickerControl x:Name="TextColorPickerControl" SelectedIndexProperty="1" ColorChanged="TextColorPickerControl_ColorChanged"></common:ColorPickerControl>
                     </StackPanel>
                 </Grid>
             </TabItem>

+ 13 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCreateSignatureDialog.xaml.cs

@@ -22,11 +22,13 @@ using ComPDFKitViewer.AnnotEvent;
 using System.Windows.Ink;
 using ComPDFKitViewer;
 using System.Net.NetworkInformation;
+using compdfkit_tools.Common;
 
 namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
 {
     public partial class CPDFCreateSignatureDialog : Window
     {
+        SolidColorBrush solidColorBrush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0xFF, 0xFF, 0x00, 0x00));
         public CPDFSignatureData cPDFSignatureData;
         private string SaveToPath;
         private string SignaturePath;
@@ -47,6 +49,9 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
             IsPageLoaded = true;
             DrawinkCanvas.DefaultDrawingAttributes.Width = StrokeWidth;
             DrawinkCanvas.DefaultDrawingAttributes.Height = StrokeHigh;
+
+            DrawinkCanvas.DefaultDrawingAttributes.Color = solidColorBrush.Color;
+            InPutTextBox.Foreground = solidColorBrush;
         }
 
         private void Cancel_Click(object sender, RoutedEventArgs e)
@@ -75,7 +80,15 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
 
         private void Clear_Click(object sender, RoutedEventArgs e)
         {
+            ColorPickerControl.SelectedIndexProperty = 1;
+            TextColorPickerControl.SelectedIndexProperty = 1;
+
+            DrawinkCanvas.Strokes.Clear();
+            InPutTextBox.Text = "";
+            ImageImage.Source = null;
 
+            DrawinkCanvas.DefaultDrawingAttributes.Color = solidColorBrush.Color;
+            InPutTextBox.Foreground = solidColorBrush;
         }
         private void UpDataToStrokesObject()
         {

+ 29 - 13
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFStampUI.xaml.cs

@@ -83,7 +83,7 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
         }
         private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
         {
-            PropertyChanged?.Invoke(this,new CPDFStampData());
+            PropertyChanged?.Invoke(this, new CPDFStampData());
         }
 
         private void Text_Click(object sender, RoutedEventArgs e)
@@ -131,7 +131,7 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
 
             Custombinding.Source = this;
             Custombinding.Path = new System.Windows.PropertyPath("CustomStampList");
-            CustomListBox.SetBinding (ListBox.ItemsSourceProperty, Custombinding);
+            CustomListBox.SetBinding(ListBox.ItemsSourceProperty, Custombinding);
 
             ICollectionView groupView = CollectionViewSource.GetDefaultView(CustomStampList);
             groupView.GroupDescriptions.Add(new PropertyGroupDescription(nameof(CPDFStampData.Type)));
@@ -208,25 +208,41 @@ namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
                 if (stampData != null)
                 {
                     int index = CustomStampList.IndexOf(stampData);
-                    if (stampData.SourcePath != null)
+                    if (index != -1)
                     {
-                        try
+
+                        CPDFDeleteDialog cPDFDeleteDialog = new CPDFDeleteDialog("Dialog Title", "A description of the dialog will appear here.");
+                        cPDFDeleteDialog.Owner = Window.GetWindow(this);
+                        cPDFDeleteDialog.WindowStartupLocation = WindowStartupLocation.CenterOwner;
+                        cPDFDeleteDialog.ShowDialog();
+                        if (!cPDFDeleteDialog.IsDelete)
+                        {
+                            return;
+                        }
+                        if (stampData.SourcePath != null)
                         {
-                            if (File.Exists(stampData.SourcePath))
+                            try
                             {
-                                File.Delete(stampData.SourcePath);
+                                if (File.Exists(stampData.SourcePath))
+                                {
+                                    File.Delete(stampData.SourcePath);
+                                }
+                            }
+                            catch (Exception)
+                            {
+
                             }
                         }
-                        catch (Exception)
-                        {
+                        CustomStampList.RemoveAt(index);
 
+                        CustomStampList stamps = Settings.Default.CustomStampList;
+                        if (stamps != null)
+                        {
+                            stamps.RemoveAt(index);
+                            Settings.Default.Save();
                         }
+                        PropertyChanged?.Invoke(this, null);
                     }
-                    CustomStampList.RemoveAt(index);
-
-                    CustomStampList stamps = Settings.Default.CustomStampList;
-                    stamps.RemoveAt(index);
-                    Settings.Default.Save();
                 }
             }
         }

+ 43 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/Convert/IntAndTagToBoolMultiBinding.cs

@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace compdfkit_tools.Common.Convert
+{
+    class IntAndTagToBoolMultiBinding : IMultiValueConverter
+    {
+        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (values[0] == null || values[1] == null)
+            {
+                return false;
+            }
+            else
+            {
+                if (values[0].ToString() == values[1].ToString())
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+        }
+
+        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
+        {
+            if (System.Convert.ToBoolean(value))
+            {
+                string Tag = parameter.ToString();
+                int index = System.Convert.ToInt32(parameter);
+                return new object[] { Tag, index };
+            }
+            return null;
+        }
+    }
+}

+ 42 - 6
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/ColorPickerControl.xaml

@@ -4,10 +4,11 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              mc:Ignorable="d" 
-             xmlns:local="clr-namespace:compdfkit_tools.Common" 
+             xmlns:local="clr-namespace:compdfkit_tools.Common" xmlns:convert="clr-namespace:compdfkit_tools.Common.Convert"
              d:DesignHeight="40" d:DesignWidth="220">
     <UserControl.Resources>
 
+        <convert:IntAndTagToBoolMultiBinding x:Key="IntAndTagToBoolMultiBinding"/>
         <Style x:Key="TransparentRadioButton" TargetType="{x:Type RadioButton}">
             <Setter Property="HorizontalAlignment" Value="Center" />
             <Setter Property="VerticalAlignment" Value="Center" />
@@ -150,11 +151,46 @@
             <ColumnDefinition></ColumnDefinition>
             <ColumnDefinition Width="2*"></ColumnDefinition>
         </Grid.ColumnDefinitions>
-        <RadioButton  Background="Transparent" Style="{StaticResource TransparentRadioButton}" Tag="Red" Click="ColorRadioButton_Click" Visibility="{Binding TransparentBtnProperty, RelativeSource={RelativeSource AncestorType={x:Type local:ColorPickerControl}},Mode=TwoWay}"></RadioButton>
-        <RadioButton  Background="#FF0000" Grid.Column="1" Style="{StaticResource CommonColorRadioButton}" Tag="Red" Click="ColorRadioButton_Click" Visibility="Visible"></RadioButton>
-        <RadioButton  Background="#FFEC66" Grid.Column="2" Style="{StaticResource CommonColorRadioButton}" Tag="Black" Click="ColorRadioButton_Click"></RadioButton>
-        <RadioButton  Background="#2D77FA" Grid.Column="3" Style="{StaticResource CommonColorRadioButton}" Tag="Green"  Click="ColorRadioButton_Click"></RadioButton>
+        <RadioButton  Background="Transparent" Style="{StaticResource TransparentRadioButton}" Tag="0" Click="ColorRadioButton_Click" Visibility="{Binding TransparentBtnProperty, RelativeSource={RelativeSource AncestorType={x:Type local:ColorPickerControl}},Mode=TwoWay}">
+            <RadioButton.IsChecked>
+                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="0" Mode="TwoWay">
+                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
+                    <Binding Path="SelectedIndexProperty" RelativeSource="{RelativeSource AncestorType={x:Type local:ColorPickerControl}}"/>
+                </MultiBinding>
+            </RadioButton.IsChecked>
+        </RadioButton>
+        <RadioButton  Background="#FF0000" Grid.Column="1" Style="{StaticResource CommonColorRadioButton}" Tag="1" Click="ColorRadioButton_Click" >
+            <RadioButton.IsChecked>
+                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="1" Mode="TwoWay">
+                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
+                    <Binding Path="SelectedIndexProperty" RelativeSource="{RelativeSource AncestorType={x:Type local:ColorPickerControl}}"/>
+                </MultiBinding>
+            </RadioButton.IsChecked>
+        </RadioButton>
+        <RadioButton  Background="#FFEC66" Grid.Column="2" Style="{StaticResource CommonColorRadioButton}" Tag="2" Click="ColorRadioButton_Click">
+            <RadioButton.IsChecked>
+                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="2" Mode="TwoWay">
+                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
+                    <Binding Path="SelectedIndexProperty"  RelativeSource="{RelativeSource AncestorType={x:Type local:ColorPickerControl}}"/>
+                </MultiBinding>
+            </RadioButton.IsChecked>
+        </RadioButton>
+        <RadioButton  Background="#2D77FA" Grid.Column="3" Style="{StaticResource CommonColorRadioButton}" Tag="3"  Click="ColorRadioButton_Click">
+            <RadioButton.IsChecked>
+                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="3" Mode="TwoWay">
+                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
+                    <Binding Path="SelectedIndexProperty" RelativeSource="{RelativeSource AncestorType={x:Type local:ColorPickerControl}}"/>
+                </MultiBinding>
+            </RadioButton.IsChecked>
+        </RadioButton>
 
-        <RadioButton x:Name="CustomColorRadioButton" Background="{Binding Brush, RelativeSource={RelativeSource AncestorType={x:Type local:ColorPickerControl}},Mode=TwoWay}" Grid.Column="4" Style="{StaticResource CustomColorRadioButton}" GroupName="Color" Click="CustomColorRadioButton_Click"></RadioButton>
+        <RadioButton x:Name="CustomColorRadioButton" Background="{Binding Brush, RelativeSource={RelativeSource AncestorType={x:Type local:ColorPickerControl}},Mode=TwoWay}" Tag="4" Grid.Column="4" Style="{StaticResource CustomColorRadioButton}" Click="CustomColorRadioButton_Click">
+            <RadioButton.IsChecked>
+                <MultiBinding  Converter="{StaticResource IntAndTagToBoolMultiBinding }" ConverterParameter="4" Mode="TwoWay">
+                    <Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
+                    <Binding Path="SelectedIndexProperty"  RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:ColorPickerControl}}"/>
+                </MultiBinding>
+            </RadioButton.IsChecked>
+        </RadioButton>
     </Grid>
 </UserControl>

+ 22 - 1
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/ColorPickerControl.xaml.cs

@@ -41,6 +41,26 @@ namespace compdfkit_tools.Common
 
 
 
+        public int SelectedIndexProperty
+        {
+            get { return (int)GetValue(SelectedIndexPropertyProperty); }
+            set
+            {
+                SetValue(SelectedIndexPropertyProperty, value);
+            }
+        }
+
+        // Using a DependencyProperty as the backing store for SelectedIndex.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty SelectedIndexPropertyProperty =
+            DependencyProperty.Register("SelectedIndexProperty", typeof(int), typeof(ColorPickerControl), new PropertyMetadata(0, OnMyPropChanged));
+
+        private static void OnMyPropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            var x = 1;
+        }
+
+
+
         /// <summary>
         /// 设置允许为空
         /// </summary>
@@ -100,8 +120,9 @@ namespace compdfkit_tools.Common
             var radioButton = sender as RadioButton;
             if (radioButton != null)
             {
-                Brush=radioButton.Background;
+                Brush = radioButton.Background;
             }
         }
+
     }
 }

+ 2 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/compdfkit-tools.csproj

@@ -45,6 +45,7 @@
     <Reference Include="ComPDFKit.Viewer">
       <HintPath>..\viewer-ctrl-demo\ComPDFKit.Viewer.dll</HintPath>
     </Reference>
+    <Reference Include="PresentationFramework.Aero2" />
     <Reference Include="System" />
     <Reference Include="System.Data" />
     <Reference Include="System.Drawing" />
@@ -87,6 +88,7 @@
     <Compile Include="Annotation\PDFAnnotationPanel\PDFAnnotationUI\CPDFDeleteDialog.xaml.cs">
       <DependentUpon>CPDFDeleteDialog.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Common\Convert\IntAndTagToBoolMultiBinding.cs" />
     <Compile Include="Common\Convert\UnVisivleConvert.cs" />
     <Compile Include="Common\PropertyControl\PDFArrow\CPDFArrowControl.xaml.cs">
       <DependentUpon>CPDFArrowControl.xaml</DependentUpon>