123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using compdfkit_tools.Common;
- using compdfkit_tools.Data;
- 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.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.PDFControlUI
- {
- /// <summary>
- /// CPDFRectUI.xaml 的交互逻辑
- /// </summary>
- public partial class CPDFShapeUI : UserControl
- {
- private AnnotationType currentAnnotationType;
- public event EventHandler<CPDFAnnotationData> PropertyChanged;
- public CPDFShapeUI()
- {
- InitializeComponent();
- BorderColorPickerControl.ColorChanged += BorderColorPickerControl_ColorChanged;
- CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
- CPDFThicknessControl.ThicknessChanged += CPDFThicknessControl_ThicknessChanged;
- }
- private void CPDFThicknessControl_ThicknessChanged(object sender, EventArgs e)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- private void FillColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- PropertyChanged?.Invoke(this, GetShapeData());
- }
- private void CPDFArrowControl_ArrowChanged(object sender, EventArgs e)
- {
- PropertyChanged?.Invoke(PropertyChanged, GetShapeData());
- }
- public DashStyle CalculateDashStyle(CPDFDash pdfDash, int Thickness )
- {
- DashStyle dashStyle = new DashStyle();
- if (pdfDash.IsSolid)
- {
- dashStyle = DashStyles.Solid;
- return dashStyle;
- }
- else
- {
- dashStyle.Dashes.Add(pdfDash.DashSpacing / Thickness);
- dashStyle.Dashes.Add(pdfDash.DashSpacing / Thickness);
- return dashStyle;
- }
- }
- public CPDFAnnotationData GetShapeData()
- {
- if (currentAnnotationType == AnnotationType.Circle || currentAnnotationType == AnnotationType.Square)
- {
- CPDFShapeData pdfShapeData = new CPDFShapeData();
- pdfShapeData.AnnotationType = currentAnnotationType;
- pdfShapeData.BorderColor = ((SolidColorBrush)BorderColorPickerControl.Brush).Color;
- pdfShapeData.FillColor = ((SolidColorBrush)FillColorPickerControl.Brush).Color;
- pdfShapeData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
- pdfShapeData.Thickness = CPDFThicknessControl.Thickness;
- pdfShapeData.DashStyle = CalculateDashStyle(CPDFLineStyleControl.CPDFDash, CPDFThicknessControl.Thickness);
- pdfShapeData.LineType = CPDFArrowControl.LineType;
- pdfShapeData.Note = NoteTextBox.Text;
- return pdfShapeData;
- }
- else
- {
- CPDFLineShapeData pdfLineShapeData = new CPDFLineShapeData();
- pdfLineShapeData.AnnotationType = currentAnnotationType;
- pdfLineShapeData.BorderColor = ((SolidColorBrush)BorderColorPickerControl.Brush).Color;
- pdfLineShapeData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
- pdfLineShapeData.LineType = CPDFArrowControl.LineType;
- pdfLineShapeData.Thickness = CPDFThicknessControl.Thickness;
- pdfLineShapeData.DashStyle = CalculateDashStyle(CPDFLineStyleControl.CPDFDash, CPDFThicknessControl.Thickness);
- pdfLineShapeData.Note = NoteTextBox.Text;
- return pdfLineShapeData;
- }
- }
- public void InitWhenRectAndRound()
- {
- FillColorStackPanel.Visibility = Visibility.Visible;
- ArrowStackPanel.Visibility = Visibility.Collapsed;
- FillColorPickerControl.ColorChanged += FillColorPickerControl_ColorChanged;
- CPDFArrowControl.ArrowChanged -= CPDFArrowControl_ArrowChanged;
- }
- public void InitWhenArrowAndLine()
- {
- FillColorStackPanel.Visibility = Visibility.Collapsed;
- ArrowStackPanel.Visibility = Visibility.Visible;
- CPDFArrowControl.ArrowChanged += CPDFArrowControl_ArrowChanged;
- FillColorPickerControl.ColorChanged -= FillColorPickerControl_ColorChanged;
- }
- public void InitWithAnnotationType(AnnotationType annotationType)
- {
- switch (annotationType)
- {
- case AnnotationType.Square:
- TitleTextBlock.Text = "Square";
- InitWhenRectAndRound();
- break;
- case AnnotationType.Circle:
- TitleTextBlock.Text = "Circle";
- InitWhenRectAndRound();
- break;
- case AnnotationType.Arrow:
- TitleTextBlock.Text = "Arrow";
- InitWhenArrowAndLine();
- break;
- case AnnotationType.Line:
- TitleTextBlock.Text = "Line";
- InitWhenArrowAndLine();
- break;
- default:
- throw new ArgumentException("Not Excepted Argument");
- }
- currentAnnotationType = annotationType;
- }
- }
- }
|