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
{
///
/// PDFAnnotationBarControl.xaml 的交互逻辑
///
public partial class CPDFAnnotationBarControl : UserControl
{
private int annotationCounter = 0;
private Brush brush = null;
public event EventHandler 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;
}
}
}
}