123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using compdfkit_tools.Data;
- 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;
- namespace compdfkit_tools.PDFControl
- {
- /// <summary>
- /// PDFAnnotationBarControl.xaml 的交互逻辑
- /// </summary>
- public partial class CPDFAnnotationBarControl : UserControl
- {
- private int annotationCounter = 0;
- private Brush brush = null;
- public event EventHandler<AnnotationType> AnnotationPropertyChanged;
- public event EventHandler AnnotationCancel;
- 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() == AnnotationType.Highlight.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Highlight.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Underline.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Underline.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Strikeout.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Strikeout.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Squiggly.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Squiggly.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.FreeText.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Freetext.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Note.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Note.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Square.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Rect.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Circle.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Round.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Arrow.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Arrow.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Line.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/StraightLine.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Freehand.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Freehand.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Stamp.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Stamp.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Signature.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Signature.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.Link.ToString())
- {
- path = "pack://application:,,,/com.compdfkit.tools;component/Asset/Resource/Annotation/Link.png";
- }
- else if (toggleButton.Tag.ToString() == AnnotationType.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)
- {
- AnnotationPropertyChanged?.Invoke(sender, CPDFAnnotationDictionary.GetAnnotationFromTag[(sender as ToggleButton).Tag.ToString()]);
- }
- else
- {
- AnnotationCancel?.Invoke(sender, EventArgs.Empty);
- }
- }
- public void InitAnnotationBar(AnnotationType[] annotationProperties)
- {
- brush = (Brush)FindResource("btn.bg.bota");
- for (int i = 0; i < annotationProperties.Length; i++)
- {
- AnnotationGrid.ColumnDefinitions.Add(new ColumnDefinition());
- AnnotationType annotation = annotationProperties[i];
- ToggleButton toggleButton = new ToggleButton();
- toggleButton.Tag = annotation.ToString();
- CreateAnnotationButton(toggleButton);
- AnnotationGrid.Width += 50;
- }
- }
- }
- }
|