Browse Source

PDFAnnotation(windows) - Shape

liuaoran 1 year ago
parent
commit
3fca03912b

+ 18 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/ArrowControl/CPDFArrowControl.xaml

@@ -0,0 +1,18 @@
+<UserControl x:Class="compdfkit_tools.PDFControl.CPDFArrowControl"
+             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:cpdftoolsui="clr-namespace:compdfkit_tools.PDFControlUI"
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:compdfkit_tools.PDFControl"
+             mc:Ignorable="d" 
+             d:DesignHeight="75" d:DesignWidth="300">
+    <Grid>
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition></ColumnDefinition>
+            <ColumnDefinition></ColumnDefinition>
+        </Grid.ColumnDefinitions>
+        <cpdftoolsui:CPDFArrowUI x:Name="CPDFHeadArrowUI"></cpdftoolsui:CPDFArrowUI>
+        <cpdftoolsui:CPDFArrowUI x:Name="CPDFTailArrowUI" Grid.Column="1"></cpdftoolsui:CPDFArrowUI>
+    </Grid>
+</UserControl>

+ 57 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Annotation/ArrowControl/CPDFArrowControl.xaml.cs

@@ -0,0 +1,57 @@
+using ComPDFKit.PDFAnnotation;
+using compdfkit_tools.Data;
+using compdfkit_tools.PDFControlUI;
+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.PDFControl
+{
+    /// <summary>
+    /// CPDFArrowControlControl.xaml 的交互逻辑
+    /// </summary>
+    public partial class CPDFArrowControl : UserControl
+    {
+
+        public event EventHandler ArrowChanged;
+        public LineType LineType
+        {
+            get
+            {
+                return new LineType()
+                {
+                    HeadType = CPDFAnnotationDictionary.GetLineTypeFromIndex[CPDFHeadArrowUI.SelectedIndex],
+                    TailType = CPDFAnnotationDictionary.GetLineTypeFromIndex[CPDFTailArrowUI.SelectedIndex]
+                };
+            }
+        }
+
+        public CPDFArrowControl()
+        {
+            InitializeComponent();
+            CPDFHeadArrowUI.ArrowChanged += CPDFHeadArrowUI_ArrowChanged;
+            CPDFTailArrowUI.ArrowChanged += CPDFTailArrowUI_ArrowChanged;
+        }
+
+        private void CPDFTailArrowUI_ArrowChanged(object sender, EventArgs e)
+        {
+            ArrowChanged?.Invoke(this, EventArgs.Empty);
+        }
+
+        private void CPDFHeadArrowUI_ArrowChanged(object sender, EventArgs e)
+        {
+            ArrowChanged?.Invoke((object)this, EventArgs.Empty);
+        }
+    }
+}

+ 12 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/PDFLineStyle/CPDFLineStyleControl.xaml

@@ -0,0 +1,12 @@
+<UserControl x:Class="compdfkit_tools.Common.CPDFLineStyleControl"
+             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.Common"
+             mc:Ignorable="d" 
+              d:DesignHeight="70" d:DesignWidth="260">
+    <Grid>
+        <local:CPDFLineStyleUI x:Name="CPDFLineStyleUI"></local:CPDFLineStyleUI>
+    </Grid>
+</UserControl>

+ 39 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/PDFLineStyle/CPDFLineStyleControl.xaml.cs

@@ -0,0 +1,39 @@
+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.Common
+{
+    /// <summary>
+    /// CPDFLineStyleControl.xaml 的交互逻辑
+    /// </summary>
+    public partial class CPDFLineStyleControl : UserControl
+    {
+        public event EventHandler LineStyleChanged;
+
+        public CPDFDash CPDFDash { get => CPDFLineStyleUI.DashStyle;  }
+
+        public CPDFLineStyleControl()
+        {
+            InitializeComponent();
+            CPDFLineStyleUI.LineStyleChanged += CPDFLineStyleUI_LineStyleChanged;
+        }
+
+        private void CPDFLineStyleUI_LineStyleChanged(object sender, EventArgs e)
+        {
+            LineStyleChanged?.Invoke(this, EventArgs.Empty);
+        }
+    }
+}

+ 68 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/PDFLineStyle/CPDFLineStyleUI.xaml

@@ -0,0 +1,68 @@
+<UserControl x:Class="compdfkit_tools.Common.CPDFLineStyleUI"
+             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.Common"
+             mc:Ignorable="d" 
+             d:DesignHeight="70" d:DesignWidth="260">
+    <UserControl.Resources>
+        <Style x:Key="LineRadioButton" TargetType="{x:Type RadioButton}">
+            <Setter Property="HorizontalAlignment" Value="Left"></Setter>
+            <Setter Property="VerticalAlignment" Value="Center"></Setter>
+            <Setter Property="Height" Value="20"></Setter>
+            <Setter Property="Width" Value="200"></Setter>
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type RadioButton}">
+                        <Grid>
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition Width="20"></ColumnDefinition>
+                                <ColumnDefinition></ColumnDefinition>
+                            </Grid.ColumnDefinitions>
+                            <Grid Grid.Column="0">
+                                <Border x:Name="BackgroundBorder" CornerRadius="20" BorderThickness="2" BorderBrush="#000000" Background="Transparent">
+                                    <Ellipse Name="CheckedEllipse" Height="10" Width="10" Fill="#000000" Visibility="Collapsed"></Ellipse>
+                                </Border>
+                            </Grid>
+                            <ContentPresenter Grid.Column="1"/>
+                        </Grid>
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="IsMouseOver" Value="True">
+                                <Setter TargetName="BackgroundBorder" Property="BorderBrush" Value="#477EDE"></Setter>
+                            </Trigger>
+
+                            <Trigger Property="IsPressed" Value="True">
+                                <Setter TargetName="BackgroundBorder" Property="BorderBrush" Value="#477EDE"></Setter>
+                                <Setter TargetName="BackgroundBorder" Property="Background" Value="#87CEFA"></Setter>
+                            </Trigger>
+
+                            <Trigger Property="IsChecked" Value="True">
+                                <Setter TargetName="CheckedEllipse" Property="Visibility" Value="Visible"></Setter>
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+    </UserControl.Resources>
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition></RowDefinition>
+            <RowDefinition></RowDefinition>
+        </Grid.RowDefinitions>
+        <RadioButton Tag="Solid" IsChecked="True" Grid.Row="0" Style="{StaticResource LineRadioButton}" VerticalAlignment="Center"  GroupName="LineStyleGroup" Margin="16,0,0,0" Click="RadioButton_Click">
+            <Line Name="SolidLineControl" Margin="10,0,0,0" Grid.Column="1" Stroke="#000000" StrokeThickness="1" X1="0" Y1="0" X2="112" Y2="0" VerticalAlignment="Center"></Line>
+        </RadioButton>
+        <Grid Grid.Row="1">
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="2*"></ColumnDefinition>
+                <ColumnDefinition Width="1*"></ColumnDefinition>
+            </Grid.ColumnDefinitions>
+            <RadioButton x:Name="DashRadioButton" Tag="Dash" Margin="16,0,0,0" Style="{StaticResource LineRadioButton}" GroupName="LineStyleGroup" Click="RadioButton_Click">
+                <Line Name="DashLineControl" Margin="10,0,0,0" Grid.Row="1" Grid.Column="1" Stroke="#000000" StrokeThickness="2" X1="0" Y1="0" X2="112" Y2="0" VerticalAlignment="Center" StrokeDashArray="0,1,1"></Line>
+            </RadioButton>
+            <local:NumericUpDownControl x:Name="NumericUpDownControl" Text="{Binding DashSpacing, Mode=TwoWay}" Grid.Column="1" Width="72" Height="28" Unit="pt" Minimum="1" Maxium="100" IsEnabled="{Binding ElementName=DashRadioButton, Path=IsChecked}"></local:NumericUpDownControl>
+        </Grid>
+    </Grid>
+</UserControl>

+ 74 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/PDFLineStyle/CPDFLineStyleUI.xaml.cs

@@ -0,0 +1,74 @@
+using compdfkit_tools.Data;
+using System;
+using System.Collections.Generic;
+using System.Drawing.Drawing2D;
+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;
+using DashStyle = System.Windows.Media.DashStyle;
+
+namespace compdfkit_tools.Common
+{
+    /// <summary>           
+    /// CPDFLineStyleUI.xaml 的交互逻辑
+    /// </summary>
+    public partial class CPDFLineStyleUI : UserControl
+    {
+        private CPDFDash _dashStyle = new CPDFDash();
+        public CPDFDash DashStyle
+        {
+            get => _dashStyle;
+            set => _dashStyle = value;
+        }
+
+        private int _dashSpacing = 1;
+        public int DashSpacing
+        {
+            get => _dashSpacing;
+            set
+            {
+                _dashSpacing = value;
+                DashStyle.DashSpacing = _dashSpacing;
+                OnDashSpacingChanged();
+            }
+        }
+
+        public event EventHandler LineStyleChanged;
+
+        public CPDFLineStyleUI()
+        {
+            InitializeComponent();
+            this.DataContext = this;
+        }
+
+        private void RadioButton_Click(object sender, RoutedEventArgs e)
+        {
+            RadioButton radioButton = sender as RadioButton;
+            if (radioButton.Tag.ToString() == "Solid")
+            {
+                DashStyle.IsSolid = true;
+            }
+            else
+            {
+                DashStyle.IsSolid = false;
+                DashStyle.DashSpacing = DashSpacing;
+            }
+            LineStyleChanged?.Invoke(this, EventArgs.Empty);
+        }
+
+        public void OnDashSpacingChanged()
+        {
+            LineStyleChanged?.Invoke(this, EventArgs.Empty);
+        }
+
+    }
+}

+ 12 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/PDFThickness/CPDFThicknessControl.xaml

@@ -0,0 +1,12 @@
+<UserControl x:Class="compdfkit_tools.Common.CPDFThicknessControl"
+             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.Common"
+             mc:Ignorable="d" 
+             d:DesignHeight="40" d:DesignWidth="300">
+    <Grid>
+        <local:CPDFThicknessUI x:Name="CPDFThicknessUI"></local:CPDFThicknessUI>
+    </Grid>
+</UserControl>

+ 41 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/PDFThickness/CPDFThicknessControl.xaml.cs

@@ -0,0 +1,41 @@
+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.Common
+{
+    /// <summary>
+    /// CPDFThicknessControl.xaml 的交互逻辑
+    /// </summary>
+    public partial class CPDFThicknessControl : UserControl
+    {
+        public event EventHandler ThicknessChanged;
+
+        public int Thickness
+        {
+            get => CPDFThicknessUI.Thickness;
+        }
+
+        public CPDFThicknessControl()
+        {
+            InitializeComponent();
+            CPDFThicknessUI.ThicknessChanged += CPDFThicknessUI_ThicknessChanged;
+        }
+
+        private void CPDFThicknessUI_ThicknessChanged(object sender, EventArgs e)
+        {
+            ThicknessChanged?.Invoke(this, EventArgs.Empty);
+        }
+    }
+}

+ 17 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/PDFThickness/CPDThicknessUI.xaml

@@ -0,0 +1,17 @@
+<UserControl x:Class="compdfkit_tools.Common.CPDFThicknessUI"
+             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.Common"
+             mc:Ignorable="d" 
+             d:DesignHeight="40" d:DesignWidth="300">
+    <Grid>
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition></ColumnDefinition>
+            <ColumnDefinition Width="80"></ColumnDefinition>
+        </Grid.ColumnDefinitions>
+        <Slider MinHeight="40" VerticalAlignment="Center" Maximum="16" Minimum="0" TickFrequency="1" IsSnapToTickEnabled="True" Value="{Binding Thickness, Mode=TwoWay}" Margin="10,0,10,0"></Slider>
+        <local:DropDownNumberBoxControl x:Name="DropDownNumberBoxControl"  Grid.Column="1" Unit="pt" Maxium="16" Minimum="0" Text="{Binding Thickness,Mode=TwoWay}"></local:DropDownNumberBoxControl>
+    </Grid>
+</UserControl>

+ 73 - 0
compdfkit_demo_windows/compdfkit/compdfkit-tools/Common/PropertyControl/PDFThickness/CPDThicknessUI.xaml.cs

@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+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.Common
+{
+    /// <summary>
+    /// CPDFBorderWidthUI.xaml 的交互逻辑
+    /// </summary>
+    public partial class CPDFThicknessUI : UserControl, INotifyPropertyChanged
+    {
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        public event EventHandler ThicknessChanged;
+
+        private int _thickness = 1;
+        public int Thickness
+        {
+            get
+            {
+                return _thickness;
+            }
+            set
+            {
+                _thickness = value;
+                OnPropertyChanged(nameof(Thickness));
+                OnThicknessChanged();
+            }
+        }
+
+        public CPDFThicknessUI()
+        {
+            InitializeComponent();
+            this.DataContext = this;
+            InitPresetNumberArray();
+        }
+
+        public void InitPresetNumberArray()
+        {
+            List<int> list = new List<int>();
+            list.Add(1);
+            list.Add(3);
+            list.Add(6);
+            list.Add(9);
+            list.Add(12);
+            list.Add(16);
+            DropDownNumberBoxControl.InitPresetNumberArray(list);
+        }
+
+        private void OnThicknessChanged()
+        {
+            ThicknessChanged?.Invoke(this, EventArgs.Empty);
+        }
+
+        protected void OnPropertyChanged(string propertyName)
+        {
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+        }
+
+    }
+}