123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.PDFAnnotation.Form;
- using ComPDFKit.PDFDocument;
- using ComPDFKit.Tool;
- using ComPDFKit.Tool.Help;
- using Compdfkit_Tools.Data;
- using Compdfkit_Tools.PDFControl;
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace Compdfkit_Tools.PDFControlUI
- {
- public partial class CPDFFreehandUI : UserControl
- {
- public event EventHandler<CPDFAnnotationData> PropertyChanged;
- public event EventHandler<bool> EraseClickHandler;
- public event EventHandler<double> EraseChangeHandler;
- private InkParam inkParam = null;
- private CPDFInkAnnotation cPDFAnnotation = null;
- private PDFViewControl pdfViewerControl = null;
- private CPDFDocument cPDFDocument = null;
- public CPDFFreehandUI()
- {
- InitializeComponent();
- ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
- CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
- CPDFThicknessControl.ThicknessChanged += CPDFThicknessControl_ThicknessChanged;
- CPDFAnnotationPreviewerControl.DrawFreehandPreview(GetFreehandData());
- EraseThickness.ThicknessChanged += EraseThickness_ThicknessChanged;
- }
- private void EraseThickness_ThicknessChanged(object sender, EventArgs e)
- {
- EraseChangeHandler?.Invoke(this, EraseThickness.Thickness);
- EraseCircle.Width = EraseThickness.Thickness * 6;
- EraseCircle.Height = EraseThickness.Thickness * 6;
- }
- private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
- {
- if (cPDFAnnotation == null)
- {
- PropertyChanged?.Invoke(this, GetFreehandData());
- }
- else
- {
- double transparent = CPDFOpacityControl.OpacityValue / 100.0;
- if(transparent<=1)
- {
- transparent = transparent * 255;
- }
- cPDFAnnotation.SetTransparency((byte)transparent);
- pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
- }
- CPDFAnnotationPreviewerControl.DrawFreehandPreview(GetFreehandData());
- }
- private void CPDFThicknessControl_ThicknessChanged(object sender, EventArgs e)
- {
- if (cPDFAnnotation == null)
- {
- PropertyChanged?.Invoke(this, GetFreehandData());
- }
- else
- {
- cPDFAnnotation.SetThickness(CPDFThicknessControl.Thickness);
- pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
- }
- CPDFAnnotationPreviewerControl.DrawFreehandPreview(GetFreehandData());
- }
- private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- if (cPDFAnnotation == null)
- {
- PropertyChanged?.Invoke(this, GetFreehandData());
- }
- else
- {
- byte[] Color = new byte[3];
- Color[0] = ((SolidColorBrush)ColorPickerControl.Brush).Color.R;
- Color[1] = ((SolidColorBrush)ColorPickerControl.Brush).Color.G;
- Color[2] = ((SolidColorBrush)ColorPickerControl.Brush).Color.B;
- cPDFAnnotation.SetInkColor(Color);
- pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
- }
- CPDFAnnotationPreviewerControl.DrawFreehandPreview(GetFreehandData());
- }
- private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (cPDFAnnotation == null)
- {
- PropertyChanged?.Invoke(this, GetFreehandData());
- }
- else
- {
- byte[] Color = new byte[3];
- Color[0] = ((SolidColorBrush)ColorPickerControl.Brush).Color.R;
- Color[1] = ((SolidColorBrush)ColorPickerControl.Brush).Color.G;
- Color[2] = ((SolidColorBrush)ColorPickerControl.Brush).Color.B;
- cPDFAnnotation.SetContent(NoteTextBox.Text);
- pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDateAnnotFrame();
- }
- }
- public void SetPresentAnnotAttrib(AnnotParam annotParam, CPDFAnnotation annotation, CPDFDocument doc, PDFViewControl cPDFViewer)
- {
- inkParam = (InkParam)annotParam;
- cPDFAnnotation = (CPDFInkAnnotation)annotation;
- pdfViewerControl = cPDFViewer;
- cPDFDocument = doc;
- if (inkParam==null)
- {
- return;
- }
- ColorPickerControl.Brush = new SolidColorBrush(ParamConverter.ConverterByteForColor(inkParam.InkColor));
- CPDFOpacityControl.OpacityValue = (int)(inkParam.Transparency * 100);
- CPDFThicknessControl.Thickness = Convert.ToInt16(inkParam.Thickness);
- ColorPickerControl.SetCheckedForColor(ParamConverter.ConverterByteForColor(inkParam.InkColor));
- NoteTextBox.Text = inkParam.Content;
- }
- public CPDFFreehandData GetFreehandData()
- {
- CPDFFreehandData pdfFreehandData = new CPDFFreehandData();
- pdfFreehandData.AnnotationType = CPDFAnnotationType.Freehand;
- pdfFreehandData.BorderColor = ((SolidColorBrush)ColorPickerControl.Brush).Color;
- pdfFreehandData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
- pdfFreehandData.Thickness = CPDFThicknessControl.Thickness;
- pdfFreehandData.Note = NoteTextBox.Text;
- return pdfFreehandData;
- }
- public void SetEraseCheck(bool isCheck)
- {
- if(isCheck)
- {
- FreehandBtn.IsChecked = false;
- EraseBtn.IsChecked = true;
- FreehandPanel.Visibility = Visibility.Collapsed;
- ErasePanel.Visibility = Visibility.Visible;
- CPDFAnnotationPreviewerControl.Visibility = Visibility.Collapsed;
- EraseCirclePanel.Visibility = Visibility.Visible;
- }
- else
- {
- FreehandBtn.IsChecked = true;
- EraseBtn.IsChecked = false;
- FreehandPanel.Visibility = Visibility.Visible;
- ErasePanel.Visibility = Visibility.Collapsed;
- CPDFAnnotationPreviewerControl.Visibility = Visibility.Visible;
- EraseCirclePanel.Visibility=Visibility.Collapsed;
- }
- }
- internal void ClearAnnotAttribEvent()
- {
- cPDFAnnotation = null;
- }
- internal int GetEraseThickness()
- {
- return EraseThickness.Thickness;
- }
- private void FreehandBtn_Click(object sender, RoutedEventArgs e)
- {
- SetEraseCheck(false);
- EraseClickHandler?.Invoke(this, false);
- }
- private void EraseBtn_Click(object sender, RoutedEventArgs e)
- {
- SetEraseCheck(true);
- EraseClickHandler?.Invoke(this, true);
- }
- }
- }
|