Bläddra i källkod

PDFAnnotation(windows) - Stamp注释部分代码,以及同步git

zhuyi 1 år sedan
förälder
incheckning
231622e2e4

+ 113 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFStampUI.xaml

@@ -0,0 +1,113 @@
+<UserControl x:Class="compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI.CPDFStampUI"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI"
+             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="800">
+    <UserControl.DataContext>
+        <local:CPDFStampUIViewModel/>
+    </UserControl.DataContext>
+    <UserControl.Resources>
+        <SolidColorBrush x:Key="TabItem.Selected.Background" Color="#FFFFFF"/>
+        <SolidColorBrush x:Key="TabItem.Selected.Border" Color="#ACACAC"/>
+        <Style x:Key="TabControlStyle1" TargetType="{x:Type TabControl}">
+            <Setter Property="Padding" Value="2"/>
+            <Setter Property="HorizontalContentAlignment" Value="Center"/>
+            <Setter Property="VerticalContentAlignment" Value="Center"/>
+            <Setter Property="Background" Value="{StaticResource TabItem.Selected.Background}"/>
+            <Setter Property="BorderBrush" Value="{StaticResource TabItem.Selected.Border}"/>
+            <Setter Property="BorderThickness" Value="1"/>
+            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type TabControl}">
+                        <Grid x:Name="templateRoot" ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition x:Name="ColumnDefinition0"/>
+                                <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
+                            </Grid.ColumnDefinitions>
+                            <Grid.RowDefinitions>
+                                <RowDefinition x:Name="RowDefinition0" Height="Auto"/>
+                                <RowDefinition x:Name="RowDefinition1" Height="*"/>
+                            </Grid.RowDefinitions>
+                            <UniformGrid x:Name="headerPanel" Background="Transparent"  Grid.Column="0"  HorizontalAlignment="Stretch" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"  Rows="1"/>
+                            <Border x:Name="contentPanel" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
+                                <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
+                            </Border>
+                        </Grid>
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="TabStripPlacement" Value="Bottom">
+                                <Setter Property="Grid.Row" TargetName="headerPanel" Value="1"/>
+                                <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
+                                <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
+                                <Setter Property="Height" TargetName="RowDefinition1" Value="Auto"/>
+                                <Setter Property="Margin" TargetName="headerPanel" Value="2,0,2,2"/>
+                            </Trigger>
+                            <Trigger Property="TabStripPlacement" Value="Left">
+                                <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
+                                <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
+                                <Setter Property="Grid.Column" TargetName="headerPanel" Value="0"/>
+                                <Setter Property="Grid.Column" TargetName="contentPanel" Value="1"/>
+                                <Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto"/>
+                                <Setter Property="Width" TargetName="ColumnDefinition1" Value="*"/>
+                                <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
+                                <Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
+                                <Setter Property="Margin" TargetName="headerPanel" Value="2,2,0,2"/>
+                            </Trigger>
+                            <Trigger Property="TabStripPlacement" Value="Right">
+                                <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
+                                <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
+                                <Setter Property="Grid.Column" TargetName="headerPanel" Value="1"/>
+                                <Setter Property="Grid.Column" TargetName="contentPanel" Value="0"/>
+                                <Setter Property="Width" TargetName="ColumnDefinition0" Value="*"/>
+                                <Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto"/>
+                                <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
+                                <Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
+                                <Setter Property="Margin" TargetName="headerPanel" Value="0,2,2,2"/>
+                            </Trigger>
+                            <Trigger Property="IsEnabled" Value="false">
+                                <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+    </UserControl.Resources>
+    <Grid>
+        <TabControl Style="{DynamicResource TabControlStyle1}">
+            <TabItem Header="Standard">
+                <ListBox
+                Height="auto"
+                VerticalAlignment="Top"
+                Background="Transparent"
+                BorderThickness="0"
+                ItemsSource="{Binding StandardStampList}"
+                    />
+            </TabItem>
+            <TabItem Header="Customize">
+                <Grid>
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="20"/>
+                        <RowDefinition Height="auto"/>
+                        <RowDefinition Height="auto"/>
+                    </Grid.RowDefinitions>
+                    <UniformGrid  Rows="1" >
+                        <Button Content="文字" Height="20" Click="Text_Click"/>
+                        <Button Content="图片" Height="20"/>
+                    </UniformGrid>
+                    <ListView
+                    Grid.Row="1"
+                    Height="auto"
+                    VerticalAlignment="Top"
+                    Background="Transparent"
+                    BorderThickness="0"
+                    ItemsSource="{Binding CustomStampList}"
+                    />
+                </Grid>
+            </TabItem>
+        </TabControl>
+    </Grid>
+</UserControl>

+ 51 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFStampUI.xaml.cs

@@ -0,0 +1,51 @@
+using compdfkit_tools.Data;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
+{
+    /// <summary>
+    /// CPDFStampUI.xaml 的交互逻辑
+    /// </summary>
+    public partial class CPDFStampUI : UserControl
+    {
+        public event EventHandler<CPDFAnnotationData> PropertyChanged;
+
+        public CPDFStampUI()
+        {
+            InitializeComponent();
+        }
+        public void InitWithAnnotationType(AnnotationType annotationType)
+        {
+            //doing something....
+        }
+
+        private void Button_Click(object sender, RoutedEventArgs e)
+        {
+
+        }
+        private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
+        {
+            PropertyChanged?.Invoke(this,new CPDFStampData());
+        }
+
+        private void Text_Click(object sender, RoutedEventArgs e)
+        {
+            CreateStampDialog createStampDialog = new CreateStampDialog();
+            createStampDialog.Owner = Window.GetWindow(this);
+            createStampDialog.ShowDialog();
+        }
+    }
+}

+ 62 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFStampUIViewModel.cs

@@ -0,0 +1,62 @@
+using compdfkit_tools.Data;
+using compdfkit_tools.Properties;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
+{
+    public class CPDFStampUIViewModel : INotifyPropertyChanged
+    {
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        public void RaisePropertyChanged(string PropertyName)
+        {
+            if (this.PropertyChanged!=null)
+            {
+                this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs(PropertyName));
+            }
+        }
+
+        public ObservableCollection<CPDFStampData> StandardStampList { get; set; }
+        public ObservableCollection<CPDFStampData> CustomStampList { get; set; }
+
+        public CPDFStampUIViewModel()
+        {
+            StandardStampList = new ObservableCollection<CPDFStampData>();
+            CustomStampList = new ObservableCollection<CPDFStampData>();
+            InitStandardStamp();
+            LoadSettings();
+        }
+
+        public void InitStandardStamp()
+        {
+
+        }
+
+        /// <summary>
+        /// Loading CacheStamp
+        /// </summary>
+        public void LoadSettings()
+        {
+
+        }
+
+        public void DeleteStamp(CPDFStampData stampData) 
+        {
+            int index = CustomStampList.IndexOf(stampData);
+            DirectoryInfo CreatedFilePathFolder = new DirectoryInfo(stampData.SourcePath);
+            if (CreatedFilePathFolder.Exists)
+            {
+                Directory.Delete(stampData.SourcePath, true);
+            }
+            CustomStampList.RemoveAt(index);
+        }
+
+    }
+}

+ 113 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CreateStampDialog.xaml

@@ -0,0 +1,113 @@
+<Window x:Class="compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI.CreateStampDialog"
+        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
+        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+        xmlns:local="clr-namespace:compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI"
+        mc:Ignorable="d"
+        ShowInTaskbar="False"
+        ResizeMode="NoResize"
+        Title="CreateStampDialog" Height="450" Width="800">
+    <Window.Resources>
+        <SolidColorBrush x:Key="TabItem.Selected.Background" Color="#FFFFFF"/>
+        <SolidColorBrush x:Key="TabItem.Selected.Border" Color="#ACACAC"/>
+        <Style x:Key="TabControlStyle1" TargetType="{x:Type TabControl}">
+            <Setter Property="Padding" Value="2"/>
+            <Setter Property="HorizontalContentAlignment" Value="Center"/>
+            <Setter Property="VerticalContentAlignment" Value="Center"/>
+            <Setter Property="Background" Value="{StaticResource TabItem.Selected.Background}"/>
+            <Setter Property="BorderBrush" Value="{StaticResource TabItem.Selected.Border}"/>
+            <Setter Property="BorderThickness" Value="1"/>
+            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type TabControl}">
+                        <Grid x:Name="templateRoot" ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition x:Name="ColumnDefinition0"/>
+                                <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
+                            </Grid.ColumnDefinitions>
+                            <Grid.RowDefinitions>
+                                <RowDefinition x:Name="RowDefinition0" Height="Auto"/>
+                                <RowDefinition x:Name="RowDefinition1" Height="*"/>
+                            </Grid.RowDefinitions>
+                            <TabPanel x:Name="headerPanel" HorizontalAlignment="Center" Background="Transparent" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/>
+                            <Border x:Name="contentPanel" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
+                                <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
+                            </Border>
+                        </Grid>
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="TabStripPlacement" Value="Bottom">
+                                <Setter Property="Grid.Row" TargetName="headerPanel" Value="1"/>
+                                <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
+                                <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
+                                <Setter Property="Height" TargetName="RowDefinition1" Value="Auto"/>
+                                <Setter Property="Margin" TargetName="headerPanel" Value="2,0,2,2"/>
+                            </Trigger>
+                            <Trigger Property="TabStripPlacement" Value="Left">
+                                <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
+                                <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
+                                <Setter Property="Grid.Column" TargetName="headerPanel" Value="0"/>
+                                <Setter Property="Grid.Column" TargetName="contentPanel" Value="1"/>
+                                <Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto"/>
+                                <Setter Property="Width" TargetName="ColumnDefinition1" Value="*"/>
+                                <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
+                                <Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
+                                <Setter Property="Margin" TargetName="headerPanel" Value="2,2,0,2"/>
+                            </Trigger>
+                            <Trigger Property="TabStripPlacement" Value="Right">
+                                <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
+                                <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
+                                <Setter Property="Grid.Column" TargetName="headerPanel" Value="1"/>
+                                <Setter Property="Grid.Column" TargetName="contentPanel" Value="0"/>
+                                <Setter Property="Width" TargetName="ColumnDefinition0" Value="*"/>
+                                <Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto"/>
+                                <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
+                                <Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
+                                <Setter Property="Margin" TargetName="headerPanel" Value="0,2,2,2"/>
+                            </Trigger>
+                            <Trigger Property="IsEnabled" Value="false">
+                                <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+    </Window.Resources>
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="20"/>
+            <RowDefinition Height="*"/>
+            <RowDefinition Height="20"/>
+        </Grid.RowDefinitions>
+        <TabControl Style="{DynamicResource TabControlStyle1}" Grid.Row="1">
+            <TabItem Header="文字">
+                <Grid>
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="*"/>
+                        <RowDefinition Height="20"/>
+                        <RowDefinition Height="20"/>
+                        <RowDefinition Height="20"/>
+                        <RowDefinition Height="20"/>
+                        <RowDefinition Height="20"/>
+                    </Grid.RowDefinitions>
+                    <Image  />
+                    <ComboBox SelectedIndex="0" Grid.Row="1">
+                        <ComboBoxItem Content="左箭头"/>
+                    </ComboBox>
+                    <StackPanel Orientation="Horizontal" Grid.Row="2">
+                        <Button Content="红" />
+                        <Button Content="绿"/>
+                        <Button Content="蓝"/>
+                    </StackPanel>
+                    <TextBox Grid.Row="3"/>
+                    <CheckBox Content="日期" Grid.Row="4"/>
+                    <CheckBox Content="时间" Grid.Row="5"/>
+                </Grid>
+            </TabItem>
+            <TabItem Header="图片">
+            </TabItem>
+        </TabControl>
+    </Grid>
+</Window>

+ 27 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CreateStampDialog.xaml.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace compdfkit_tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI
+{
+    /// <summary>
+    /// CreateStampDialog.xaml 的交互逻辑
+    /// </summary>
+    public partial class CreateStampDialog : Window
+    {
+        public CreateStampDialog()
+        {
+            InitializeComponent();
+        }
+    }
+}

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

@@ -87,6 +87,13 @@
     <Compile Include="Annotation\PDFAnnotationPanel\PDFAnnotationUI\CPDFShapeUI.xaml.cs">
       <DependentUpon>CPDFShapeUI.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Annotation\PDFAnnotationPanel\PDFAnnotationUI\CPDFStampUI.xaml.cs">
+      <DependentUpon>CPDFStampUI.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Annotation\PDFAnnotationPanel\PDFAnnotationUI\CPDFStampUIViewModel.cs" />
+    <Compile Include="Annotation\PDFAnnotationPanel\PDFAnnotationUI\CreateStampDialog.xaml.cs">
+      <DependentUpon>CreateStampDialog.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Common\BarControl\CPDFBOTABarControl.xaml.cs">
       <DependentUpon>CPDFBOTABarControl.xaml</DependentUpon>
     </Compile>
@@ -267,6 +274,14 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Annotation\PDFAnnotationPanel\PDFAnnotationUI\CPDFStampUI.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
+    <Page Include="Annotation\PDFAnnotationPanel\PDFAnnotationUI\CreateStampDialog.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Asset\Style\MenuItemStyle.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>

+ 2 - 1
compdfkit_demo_windows/compdfkit/edit-ctrl-demo/MainWindow.xaml.cs

@@ -66,10 +66,12 @@ namespace edit_ctrl_demo
         /// 上一次的PDF编辑对象
         /// </summary>
         private PDFEditEvent lastPDFEditEvent = null;
+
         /// <summary>
         /// 缩放比例
         /// </summary>
         private double[] zoomLevel = { 1.00f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
+
         public MainWindow()
         {
             InitializeComponent();
@@ -167,7 +169,6 @@ namespace edit_ctrl_demo
         /// <summary>
         /// 撤销重做状态更新事件通知
         /// </summary>
-      
         private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
             OnPropertyChanged(e.PropertyName);