|
@@ -0,0 +1,168 @@
|
|
|
+using ComPDFKitViewer.AnnotEvent;
|
|
|
+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.Controls.Primitives;
|
|
|
+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
|
|
|
+{
|
|
|
+ public enum AnnotationProperties
|
|
|
+ {
|
|
|
+ Highlight,
|
|
|
+ Underline,
|
|
|
+ Strikeout,
|
|
|
+ Squiggly,
|
|
|
+ Freetext,
|
|
|
+ Note,
|
|
|
+ Sharp,
|
|
|
+ Line,
|
|
|
+ Stamp,
|
|
|
+ Signature,
|
|
|
+ Link,
|
|
|
+ Sound
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// PDFAnnotationBarControl.xaml 的交互逻辑
|
|
|
+ /// </summary>
|
|
|
+ public partial class CPDFAnnotationBarControl : UserControl
|
|
|
+ {
|
|
|
+ private int annotationCounter = 0;
|
|
|
+ private Brush brush = null;
|
|
|
+
|
|
|
+ public event EventHandler<string> AnnotationPropertiesChanged;
|
|
|
+ public event EventHandler AnnotationPropertiesCancel;
|
|
|
+
|
|
|
+ public CPDFAnnotationBarControl()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void CreateAnnotationButton(ToggleButton toggleButton)
|
|
|
+ {
|
|
|
+
|
|
|
+ toggleButton.Width = 50;
|
|
|
+ toggleButton.Background = brush;
|
|
|
+ Geometry annotationGeometry = Geometry.Parse(""); ;
|
|
|
+
|
|
|
+ ImageBrush imageBrush = new ImageBrush();
|
|
|
+ string path = string.Empty;
|
|
|
+ if (toggleButton.Tag.ToString() == AnnotationProperties.Highlight.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Highlight.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Underline.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Underline.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Strikeout.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Strikeout.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Squiggly.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Squiggly.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Freetext.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Freetext.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Note.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Note.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Sharp.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Sharp.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Line.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Line.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Stamp.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Stamp.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Signature.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Signature.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Link.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Link.png";
|
|
|
+ }
|
|
|
+ else if (toggleButton.Tag.ToString() == AnnotationProperties.Sound.ToString())
|
|
|
+ {
|
|
|
+ path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Sound.png";
|
|
|
+
|
|
|
+ }
|
|
|
+ if (path != string.Empty)
|
|
|
+ {
|
|
|
+ BitmapImage bitmapImage = new BitmapImage(new Uri(path, UriKind.Absolute));
|
|
|
+ Image image = new Image();
|
|
|
+ image.Source = bitmapImage;
|
|
|
+ imageBrush.ImageSource = bitmapImage;
|
|
|
+ Grid grid = new Grid();
|
|
|
+ grid.Height = 20;
|
|
|
+ grid.Width = 20;
|
|
|
+ grid.Children.Add(image);
|
|
|
+
|
|
|
+ toggleButton.Content = grid;
|
|
|
+ toggleButton.Click += ToggleButton_Click;
|
|
|
+
|
|
|
+ Grid.SetColumn(toggleButton, annotationCounter++);
|
|
|
+ AnnotationGrid.Children.Add(toggleButton);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ClearToolState(UIElement sender)
|
|
|
+ {
|
|
|
+ foreach (UIElement child in AnnotationGrid.Children)
|
|
|
+ {
|
|
|
+ if(child is ToggleButton toggle && (child as ToggleButton) != (sender as ToggleButton))
|
|
|
+ {
|
|
|
+ toggle.IsChecked = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ToggleButton_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ ClearToolState(sender as ToggleButton);
|
|
|
+ if ((bool)(sender as ToggleButton).IsChecked)
|
|
|
+ {
|
|
|
+ AnnotationPropertiesChanged?.Invoke(sender, (sender as ToggleButton).Tag.ToString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ AnnotationPropertiesCancel?.Invoke(sender, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void InitAnnotationBar(AnnotationProperties[] annotationProperties)
|
|
|
+ {
|
|
|
+ brush = (Brush)FindResource("btn.bg.bota");
|
|
|
+
|
|
|
+ for (int i = 0; i < annotationProperties.Length; i++)
|
|
|
+ {
|
|
|
+ AnnotationGrid.ColumnDefinitions.Add(new ColumnDefinition());
|
|
|
+ AnnotationProperties annotation = annotationProperties[i];
|
|
|
+ ToggleButton toggleButton = new ToggleButton();
|
|
|
+ toggleButton.Tag = annotation.ToString();
|
|
|
+ CreateAnnotationButton(toggleButton);
|
|
|
+ AnnotationGrid.Width += 50;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|