Browse Source

ComPDFKit.Demo - 云朵线修改

liuaoran 3 weeks ago
parent
commit
f783d3df1f

+ 10 - 0
Demo/Examples/Compdfkit.Controls/Annotation/AnnotationControl/AnnotationControl.xaml.cs

@@ -20,6 +20,8 @@ using ComPDFKitViewer.Widget;
 using ComPDFKit.Tool.Help;
 using ComPDFKit.Tool.DrawTool;
 using System.Collections.Generic;
+using ComPDFKitViewer.BaseObject;
+using ComPDFKitViewer;
 
 namespace ComPDFKit.Controls.PDFControl
 {
@@ -185,6 +187,14 @@ baseWidget.GetAnnotData().Annot);
                     }
                 }
             }
+            else
+            {
+                 BaseAnnot baseAnnot = PDFViewControl.GetCacheHitTestWidget();
+                if (baseAnnot != null)
+                {
+                    AnnotData annotData = baseAnnot.GetAnnotData();
+                }
+            }
         }
 
         private void UserControl_Unloaded(object sender, RoutedEventArgs e)

+ 11 - 0
Demo/Examples/Compdfkit.Controls/Annotation/PDFAnnotationPanel/PDFAnnotationControl/CPDFAnnotationControl.xaml.cs

@@ -1157,6 +1157,17 @@ namespace ComPDFKit.Controls.PDFControl
                         (tempAnnotationPanel as CPDFLinkUI).SetPresentAnnotAttrib(annotParam as LinkParam, baseAnnot.GetAnnotData().Annot as CPDFLinkAnnotation, pdfViewerControl, pdfViewerControl.PDFToolManager.GetDocument().PageCount);
                     }
                     break;
+                case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
+                    {
+                        tempAnnotationPanel = new CPDFCloudUI();
+                        AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
+                            pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
+                            baseAnnot.GetAnnotData().PageIndex,
+                            baseAnnot.GetAnnotData().Annot
+                            );
+                        (tempAnnotationPanel as CPDFCloudUI).SetPresentAnnotAttrib(annotParam as PolygonMeasureParam, baseAnnot.GetAnnotData().Annot as CPDFPolygonAnnotation, pdfViewerControl, pdfViewerControl.PDFToolManager.GetDocument().PageCount);
+                    }
+                    break;
                 case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
                     tempAnnotationPanel = null;
                     break;

+ 6 - 2
Demo/Examples/Compdfkit.Controls/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCloudUI.xaml

@@ -33,9 +33,13 @@
                         <TextBlock Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_FillColor}"></TextBlock>
                         <cpdfcommon:ColorPickerControl x:Name="ctlFillColorPicker" TransparentBtnProperty="Collapsed"></cpdfcommon:ColorPickerControl>
                     </StackPanel>
+                    <StackPanel Height="80" Margin="5">
+                        <TextBlock Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_LineShape}"></TextBlock>
+                        <cpdfcommon:CPDFLineStyleControl x:Name="ctlLineStyle"></cpdfcommon:CPDFLineStyleControl>
+                    </StackPanel>
                     <StackPanel Height="100" Margin="5">
                         <TextBlock Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_LineStyle}"></TextBlock>
-                        <cpdfcommon:CPDFCloudStyleControl x:Name="CPDFLineStyleControl"></cpdfcommon:CPDFCloudStyleControl>
+                        <cpdfcommon:CPDFCloudStyleControl x:Name="CPDFLineShapeControl"></cpdfcommon:CPDFCloudStyleControl>
                     </StackPanel>
                     <StackPanel Height="75" Margin="5">
                         <TextBlock Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_Opacity}"></TextBlock>
@@ -47,7 +51,7 @@
                     </StackPanel>
                     <StackPanel Height="200" Margin="5">
                         <TextBlock Text="{Binding Converter={StaticResource PropertyPanelResourceConverter},ConverterParameter=Property_Note}"></TextBlock>
-                        <TextBox Height="150" x:Name="NoteTextBox" TextWrapping="Wrap" AcceptsReturn="True"></TextBox>
+                        <TextBox Height="150" x:Name="NoteTextBox" TextWrapping="Wrap" AcceptsReturn="True" TextChanged="NoteTextBox_TextChanged"></TextBox>
                     </StackPanel>
                 </StackPanel>
             </StackPanel>

+ 204 - 7
Demo/Examples/Compdfkit.Controls/Annotation/PDFAnnotationPanel/PDFAnnotationUI/CPDFCloudUI.xaml.cs

@@ -1,10 +1,16 @@
-using ComPDFKit.Controls.Data;
+using ComPDFKit.Controls.Common;
+using ComPDFKit.Controls.Data;
 using ComPDFKit.Controls.PDFControl;
 using ComPDFKit.PDFAnnotation;
 using ComPDFKit.PDFDocument;
 using ComPDFKit.Tool;
+using ComPDFKit.Tool.Help;
 using ComPDFKit.Tool.UndoManger;
+using ComPDFKitViewer.Annot;
+using ComPDFKitViewer.Helper;
 using System;
+using System.Collections.Generic;
+using System.Linq;
 using System.Windows.Controls;
 using System.Windows.Media;
 
@@ -24,7 +30,7 @@ namespace ComPDFKit.Controls.PDFControlUI
 
         private AnnotHistory GetHistory()
         {
-            if(annotCore != null && annotCore.IsValid())
+            if (annotCore != null && annotCore.IsValid())
             {
                 return new PolygonAnnotHistory();
             }
@@ -38,32 +44,210 @@ namespace ComPDFKit.Controls.PDFControlUI
             ctlBorderColorPicker.ColorChanged -= CtlBorderColorPicker_ColorChanged;
             ctlFillColorPicker.ColorChanged -= CtlFillColorPicker_ColorChanged;
             CPDFOpacityControl.OpacityChanged -= CPDFOpacityControl_OpacityChanged;
+            CPDFThicknessControl.ThicknessChanged -= CPDFThicknessControl_ThicknessChanged;
+            CPDFLineShapeControl.LineShapeChanged -= CPDFLineShapeControl_LineShapeChanged;
+            ctlLineStyle.LineStyleChanged -= CtlLineStyle_LineStyleChanged;
 
             ctlBorderColorPicker.ColorChanged += CtlBorderColorPicker_ColorChanged;
             ctlFillColorPicker.ColorChanged += CtlFillColorPicker_ColorChanged;
             CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
+            CPDFThicknessControl.ThicknessChanged += CPDFThicknessControl_ThicknessChanged;
+            CPDFLineShapeControl.LineShapeChanged += CPDFLineShapeControl_LineShapeChanged;
+            ctlLineStyle.LineStyleChanged += CtlLineStyle_LineStyleChanged;
+        }
+
+        private void CtlLineStyle_LineStyleChanged(object sender, EventArgs e)
+        {
+            if (annotParam == null)
+            {
+
+            }
+            else
+            {
+                if (annotCore != null && annotCore.IsValid())
+                {
+                    float[] dashArray = null;
+                    C_BORDER_STYLE borderStyle;
+                    if (ctlLineStyle.DashStyle == DashStyles.Solid || ctlLineStyle.DashStyle == null)
+                    {
+                        dashArray = new float[0];
+                        borderStyle = C_BORDER_STYLE.BS_SOLID;
+                    }
+                    else
+                    {
+                        List<float> floatArray = new List<float>();
+                        foreach (double num in ctlLineStyle.DashStyle.Dashes)
+                        {
+                            floatArray.Add((float)num);
+                        }
+                        dashArray = floatArray.ToArray();
+                        borderStyle = C_BORDER_STYLE.BS_DASHDED;
+                    }
+
+                    if (viewControl != null && viewControl.PDFViewTool != null)
+                    {
+                        AnnotHistory history = GetHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = HistoryAction.Update;
+                        CPDFPolygonAnnotation polygonAnnotation = annotCore as CPDFPolygonAnnotation;
+                        if (polygonAnnotation == null || polygonAnnotation.Dash.SequenceEqual(dashArray)) return;
+                        history.PreviousParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
+                        polygonAnnotation.SetBorderStyle(borderStyle, dashArray);
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
+                        annotCore.UpdateAp();
+                        viewControl.UpdateAnnotFrame();
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                    }
+                }
+            }
+        }
+
+        private void CPDFLineShapeControl_LineShapeChanged(object sender, CPDFBorderEffector e)
+        {
+            if (IsLoadedData)
+            {
+                if (annotCore != null && annotCore.IsValid())
+                {
+                    (annotCore as CPDFPolygonAnnotation).SetAnnotBorderEffector(e);
+                    annotCore.UpdateAp();
+                    viewControl.UpdateAnnotFrame();
+                }
+            }
+        }
+
+        private void CPDFThicknessControl_ThicknessChanged(object sender, EventArgs e)
+        {
+            if (IsLoadedData)
+            {
+                if (annotCore != null && annotCore.IsValid())
+                {
+                    double thickness = (sender as CPDFThicknessControl).Thickness;
+
+                    if (Math.Abs(thickness - annotCore.GetTransparency()) > 1)
+                    {
+                        annotCore.SetBorderWidth((byte)thickness);
+                        annotCore.UpdateAp();
+                        viewControl.UpdateAnnotFrame();
+                    }
+                }
+            }
         }
 
         private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
         {
-            throw new NotImplementedException();
+            if (IsLoadedData)
+            {
+                if (annotCore != null && annotCore.IsValid())
+                {
+                    double opacity = (sender as CPDFOpacityControl).OpacityValue / 100.0;
+                    if (opacity > 0 && opacity <= 1)
+                    {
+                        opacity *= 255;
+                    }
+                    if (Math.Abs(opacity - annotCore.GetTransparency()) > 0.01)
+                    {
+                        annotCore.SetTransparency((byte)opacity);
+                        annotCore.UpdateAp();
+                        viewControl.UpdateAnnotFrame();
+                    }
+                }
+            }
         }
 
         private void CtlFillColorPicker_ColorChanged(object sender, EventArgs e)
         {
-            throw new NotImplementedException();
+            if (IsLoadedData)
+            {
+                if (annotCore != null && annotCore.IsValid())
+                {
+                    if (annotCore is CPDFPolygonAnnotation polygonAnnotation)
+                    {
+                        PolygonAnnotHistory history = new PolygonAnnotHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = ComPDFKitViewer.Helper.HistoryAction.Update;
+                        SolidColorBrush brush = (sender as ColorPickerControl)?.Brush as SolidColorBrush;
+
+                        polygonAnnotation.SetBgColor(new byte[3]
+                        {
+                            brush.Color.R,
+                            brush.Color.G,
+                            brush.Color.B
+                        });
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
+
+                        annotCore.UpdateAp();
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                        viewControl.UpdateAnnotFrame();
+                    }
+                }
+            }
         }
 
         private void CtlBorderColorPicker_ColorChanged(object sender, EventArgs e)
         {
-            throw new NotImplementedException();
+            if (IsLoadedData)
+            {
+                if (annotCore != null && annotCore.IsValid())
+                {
+                    if (annotCore is CPDFPolygonAnnotation polygonAnnotation)
+                    {
+                        PolygonAnnotHistory history = new PolygonAnnotHistory();
+                        history.PDFDoc = viewControl.GetCPDFViewer().GetDocument();
+                        history.Action = ComPDFKitViewer.Helper.HistoryAction.Update;
+                        SolidColorBrush brush = (sender as ColorPickerControl)?.Brush as SolidColorBrush;
+                        polygonAnnotation.SetLineColor(new byte[3]
+                        {
+                            brush.Color.R,
+                            brush.Color.G,
+                            brush.Color.B
+                        });
+
+                        history.CurrentParam = ParamConverter.CPDFDataConverterToAnnotParam(history.PDFDoc, annotCore.Page.PageIndex, polygonAnnotation);
+
+                        annotCore.UpdateAp();
+
+                        viewControl.GetCPDFViewer().UndoManager.AddHistory(history);
+                        viewControl.UpdateAnnotFrame();
+                    }
+                }
+            }
         }
 
-        public void SetPresentAnnotAttrib(PolygonMeasureParam polygonParam, CPDFPolygonAnnotation annotation, CPDFDocument document, PDFViewControl view)
+        public void SetPresentAnnotAttrib(PolygonMeasureParam polygonParam, CPDFPolygonAnnotation annotation, PDFViewControl view, int PageCount)
         {
             annotParam = polygonParam;
             annotCore = annotation;
-            viewControl = view;
+            viewControl = view; 
+            if (polygonParam == null)
+            {
+                return;
+            } 
+            Color lineColor = Color.FromRgb(polygonParam.LineColor[0], polygonParam.LineColor[1], polygonParam.LineColor[2]);
+
+            ctlBorderColorPicker.SetCheckedForColor(lineColor);
+
+            double opacity = polygonParam.Transparency / 255.0 * 100.0;
+            CPDFOpacityControl.OpacityValue = (int)Math.Ceiling(opacity);
+
+            float thickness = polygonParam.LineWidth;
+            CPDFThicknessControl.Thickness = (int)Math.Ceiling(thickness);
+
+            CPDFLineShapeControl.BorderEffector = annotation.GetAnnotBorderEffector();
+            if (polygonParam.BorderStyle == C_BORDER_STYLE.BS_SOLID)
+            {
+                ctlLineStyle.DashStyle = DashStyles.Solid;
+            }
+            else
+            {
+                List<double> dashArray = new List<double>();
+                foreach (double num in polygonParam.LineDash)
+                {
+                    dashArray.Add(num);
+                }
+                ctlLineStyle.DashStyle = new DashStyle(dashArray, 0); 
+            }
+
+            NoteTextBox.Text = polygonParam.Content;
         }
 
         public CPDFAnnotationData GetPolygonData()
@@ -91,5 +275,18 @@ namespace ComPDFKit.Controls.PDFControlUI
         {
             IsLoadedData = false;
         }
+
+        private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            if (IsLoadedData)
+            {
+                if (annotCore != null && annotCore.IsValid())
+                {
+                    annotCore.SetContent(NoteTextBox.Text);
+                    annotCore.UpdateAp();
+                    viewControl?.UpdateAnnotFrame();
+                }
+            }
+        }
     }
 }

+ 16 - 4
Demo/Examples/Compdfkit.Controls/Common/PropertyControl/PDFLineStyle/CPDFCloudStyleControl.xaml

@@ -5,7 +5,7 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:ComPDFKit.Controls.Common"
              mc:Ignorable="d" 
-             d:DesignHeight="70" d:DesignWidth="260">
+             d:DesignHeight="80" d:DesignWidth="260">
     <UserControl.Resources>
         <Style x:Key="LineRadioButton" TargetType="{x:Type RadioButton}">
             <Setter Property="HorizontalAlignment" Value="Left"></Setter>
@@ -47,7 +47,10 @@
         </Style>
     </UserControl.Resources>
     <StackPanel  Margin="16,0,0,0" VerticalAlignment="Center">
-        <RadioButton IsChecked="True" Style="{StaticResource LineRadioButton}">
+        <RadioButton x:Name="rdoStreat" Tag="Streat" GroupName="Shape"  Style="{StaticResource LineRadioButton}" Checked="rdoShape_Checked">
+            <Rectangle Fill="Black" Height="2" Width="90" HorizontalAlignment="Left"  Margin="5,0,0,0"></Rectangle>
+        </RadioButton>
+        <RadioButton x:Name="rdoCloud1" GroupName="Shape" IsChecked="True" Style="{StaticResource LineRadioButton}" Tag="Cloud1" Margin="0,6,0,6" Checked="rdoShape_Checked">
             <Canvas VerticalAlignment="Center">
                 <Path Stroke="Black" StrokeThickness="2">
                     <Path.Data>
@@ -75,9 +78,9 @@
                 </Path>
             </Canvas>
         </RadioButton>
-        <RadioButton  Style="{StaticResource LineRadioButton}" Margin="0,12,0,0">
+        <RadioButton x:Name="rdoCloud2" Tag="Cloud2" GroupName="Shape" Style="{StaticResource LineRadioButton}" Checked="rdoShape_Checked">
             <Canvas VerticalAlignment="Center">
-                <Path Stroke="Black" StrokeThickness="2">
+                <Path Stroke="Black" StrokeThickness="2" Margin="-5,0,0,0">
                     <Path.Data> 
                         <PathGeometry>
                             <PathFigure StartPoint="20,0">
@@ -95,6 +98,15 @@
                             <PathFigure StartPoint="60,0">
                                 <ArcSegment Point="50,0" Size="2,2" SweepDirection="Counterclockwise"/>
                             </PathFigure>
+                            <PathFigure StartPoint="70,0">
+                                <ArcSegment Point="60,0" Size="2,2" SweepDirection="Counterclockwise"/>
+                            </PathFigure>
+                            <PathFigure StartPoint="80,0">
+                                <ArcSegment Point="70,0" Size="2,2" SweepDirection="Counterclockwise"/>
+                            </PathFigure>
+                            <PathFigure StartPoint="90,0">
+                                <ArcSegment Point="80,0" Size="2,2" SweepDirection="Counterclockwise"/>
+                            </PathFigure>
                         </PathGeometry>
                     </Path.Data>
                 </Path>

+ 75 - 2
Demo/Examples/Compdfkit.Controls/Common/PropertyControl/PDFLineStyle/CPDFCloudStyleControl.xaml.cs

@@ -1,6 +1,8 @@
-using System;
+using ComPDFKit.PDFAnnotation;
+using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
@@ -20,10 +22,81 @@ namespace ComPDFKit.Controls.Common
     /// </summary>
     public partial class CPDFCloudStyleControl : UserControl
     {
+        private const string streat = "Streat";
+        private const string cloud1 = "Cloud1";
+        private const string cloud2 = "Cloud2";
+
+        private bool isChecked = false;
+
+        public event EventHandler<CPDFBorderEffector> LineShapeChanged;
+
+        private CPDFBorderEffector _borderEffector;
+        public CPDFBorderEffector BorderEffector
+        {
+            get
+            {
+                return _borderEffector;
+            }
+            set
+            {
+                _borderEffector = value;
+                  
+                rdoStreat.Checked -= rdoShape_Checked;
+                rdoCloud1.Checked -= rdoShape_Checked;
+                rdoCloud2.Checked -= rdoShape_Checked;
+
+                if (_borderEffector == null)
+                {
+                    rdoStreat.IsChecked = true;
+                }
+                else if (_borderEffector.BorderType == C_BORDER_TYPE.C_BORDER_TYPE_Cloud)
+                {
+                    if (_borderEffector.BorderIntensity == C_BORDER_INTENSITY.C_INTENSITY_TWO)
+                    {
+                        rdoCloud1.IsChecked = true;
+                    }
+                    else if (_borderEffector.BorderIntensity == C_BORDER_INTENSITY.C_INTENSITY_ONE)
+                    {
+                        rdoCloud2.IsChecked = true;
+                    }
+                    else
+                    {
+                        rdoStreat.IsChecked = true;
+                    }
+                }
+                else
+                {
+                    rdoStreat.IsChecked = true;
+                }
+
+                // 恢复事件处理程序
+                rdoStreat.Checked += rdoShape_Checked;
+                rdoCloud1.Checked += rdoShape_Checked;
+                rdoCloud2.Checked += rdoShape_Checked;
+            }
+        }
+
         public CPDFCloudStyleControl()
         {
             DataContext = this;
             InitializeComponent();
-        } 
+        }
+
+        private void rdoShape_Checked(object sender, RoutedEventArgs e)
+        {
+            switch ((sender as RadioButton).Tag)
+            {
+                case streat:
+                    BorderEffector = new CPDFBorderEffector(C_BORDER_TYPE.C_BORDER_TYPE_STRAIGHT, C_BORDER_INTENSITY.C_INTENSITY_ZERO);
+                    break;
+                case cloud1:
+                    BorderEffector = new CPDFBorderEffector(C_BORDER_TYPE.C_BORDER_TYPE_Cloud, C_BORDER_INTENSITY.C_INTENSITY_TWO);
+                    break;
+                case cloud2:
+                    BorderEffector = new CPDFBorderEffector(C_BORDER_TYPE.C_BORDER_TYPE_Cloud, C_BORDER_INTENSITY.C_INTENSITY_ONE);
+                    break;
+            }
+            LineShapeChanged?.Invoke(this, BorderEffector);
+        }
     }
 }

+ 9 - 0
Demo/Examples/Compdfkit.Controls/Strings/PropertyPanel.Designer.cs

@@ -735,6 +735,15 @@ namespace ComPDFKit.Controls.Strings {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Line and Border Shape.
+        /// </summary>
+        internal static string Property_LineShape {
+            get {
+                return ResourceManager.GetString("Property_LineShape", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Line and Border Style.
         /// </summary>

+ 3 - 0
Demo/Examples/Compdfkit.Controls/Strings/PropertyPanel.resx

@@ -597,4 +597,7 @@
   <data name="Title_Cloud" xml:space="preserve">
     <value>Cloud</value>
   </data>
+  <data name="Property_LineShape" xml:space="preserve">
+    <value>Line and Border Shape</value>
+  </data>
 </root>

+ 4 - 1
Demo/Examples/Compdfkit.Controls/Strings/PropertyPanel.zh.resx

@@ -157,7 +157,7 @@
     <value>线宽</value>
   </data>
   <data name="Property_LineStyle" xml:space="preserve">
-    <value>线型</value>
+    <value>线条类型</value>
   </data>
   <data name="Title_Line" xml:space="preserve">
     <value>线</value>
@@ -597,4 +597,7 @@
   <data name="Title_Cloud" xml:space="preserve">
     <value>云朵线</value>
   </data>
+  <data name="Property_LineShape" xml:space="preserve">
+    <value>线条形状</value>
+  </data>
 </root>