123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- using Compdfkit_Tools.Common;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- 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.Measure.Property
- {
- /// <summary>
- /// PolygonalProperty.xaml 的交互逻辑
- /// </summary>
- public partial class PolygonalProperty : UserControl
- {
- public ObservableCollection<int> SizeList { get; set; } = new ObservableCollection<int>
- {
- 6,8,9,10,12,14,18,20,24,26,28,32,30,32,48,72
- };
- bool IsLoadedData = false;
- private AnnotAttribEvent PolygonalEvent { get; set; }
- public PolygonalProperty()
- {
- InitializeComponent();
- }
- private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (IsLoadedData)
- {
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.NoteText, NoteTextBox.Text);
- PolygonalEvent?.UpdateAnnot();
- }
- }
- private void FontStyleCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (IsLoadedData)
- {
- int selectIndex = Math.Max(0, FontStyleCombox.SelectedIndex);
- bool isBold = false;
- bool isItalic = false;
- switch (selectIndex)
- {
- case 0:
- isBold = false;
- isItalic = false;
- break;
- case 1:
- isBold = true;
- isItalic = false;
- break;
- case 2:
- isBold = false;
- isItalic = true;
- break;
- case 3:
- isBold = true;
- isItalic = true;
- break;
- default:
- break;
- }
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.IsBold, isBold);
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.IsItalic, isItalic);
- PolygonalEvent?.UpdateAnnot();
- }
- }
- private void FontSizeCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (IsLoadedData)
- {
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.FontSize, (sender as ComboBox).SelectedItem);
- PolygonalEvent?.UpdateAnnot();
- }
- }
- private void FontCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- ComboBoxItem selectItem = FontCombox.SelectedItem as ComboBoxItem;
- if (selectItem != null && selectItem.Content != null)
- {
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.FontName, selectItem.Content.ToString());
- PolygonalEvent?.UpdateAnnot();
- }
- }
- private void UserControl_Loaded(object sender, RoutedEventArgs e)
- {
- Binding SizeListbinding = new Binding();
- SizeListbinding.Source = this;
- SizeListbinding.Path = new System.Windows.PropertyPath("SizeList");
- FontSizeComboBox.SetBinding(ComboBox.ItemsSourceProperty, SizeListbinding);
- IsLoadedData = true;
- }
- private void UserControl_Unloaded(object sender, RoutedEventArgs e)
- {
- IsLoadedData = false;
- }
- private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- SolidColorBrush checkBrush = BorderColorPickerControl.GetBrush() as SolidColorBrush;
- if (checkBrush != null)
- {
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.Color, checkBrush.Color);
- PolygonalEvent?.UpdateAnnot();
- }
- }
- private void FillColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- SolidColorBrush checkBrush = FillColorPickerControl.GetBrush() as SolidColorBrush;
- if (checkBrush != null)
- {
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.FillColor, checkBrush.Color);
- PolygonalEvent?.UpdateAnnot();
- }
- }
- private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
- {
- if (IsLoadedData)
- {
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.Transparency, CPDFOpacityControl.OpacityValue / 100D);
- PolygonalEvent?.UpdateAnnot();
- }
- }
- private void CPDFLineStyleControl_LineStyleChanged(object sender, EventArgs e)
- {
- if (IsLoadedData)
- {
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.LineStyle, CPDFLineStyleControl.DashStyle);
- PolygonalEvent?.UpdateAnnot();
- }
- }
- private void FontColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- SolidColorBrush checkBrush = FontColorPickerControl.GetBrush() as SolidColorBrush;
- if (checkBrush != null)
- {
- PolygonalEvent?.UpdateAttrib(AnnotAttrib.FontColor, checkBrush.Color);
- PolygonalEvent?.UpdateAnnot();
- }
- }
- public void SetAnnotArgsData(PolygonMeasureArgs annotArgs)
- {
- Dictionary<AnnotAttrib, object> attribDict = new Dictionary<AnnotAttrib, object>();
- attribDict[AnnotAttrib.Color] = annotArgs.LineColor;
- attribDict[AnnotAttrib.Transparency] = annotArgs.Transparency;
- attribDict[AnnotAttrib.Thickness] = annotArgs.LineWidth;
- attribDict[AnnotAttrib.LineStyle] = annotArgs.LineDash;
- attribDict[AnnotAttrib.FontColor] = annotArgs.FontColor;
- attribDict[AnnotAttrib.FillColor] = annotArgs.FillColor;
- attribDict[AnnotAttrib.FontName] = annotArgs.FontName;
- attribDict[AnnotAttrib.IsBold] = annotArgs.IsBold;
- attribDict[AnnotAttrib.IsItalic] = annotArgs.IsItalic;
- attribDict[AnnotAttrib.FontSize] = annotArgs.FontSize;
- attribDict[AnnotAttrib.NoteText] = annotArgs.Content;
- AnnotAttribEvent annotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annotArgs, attribDict);
- SetAnnotEventData(annotEvent);
- }
- public void SetAnnotEventData(AnnotAttribEvent annotEvent)
- {
- PolygonalEvent = null;
- if (annotEvent != null)
- {
- foreach (AnnotAttrib attrib in annotEvent.Attribs.Keys)
- {
- switch (attrib)
- {
- case AnnotAttrib.Color:
- BorderColorPickerControl.SetCheckedForColor((Color)annotEvent.Attribs[attrib]);
- break;
- case AnnotAttrib.FillColor:
- FillColorPickerControl.SetCheckedForColor((Color)annotEvent.Attribs[attrib]);
- break;
- case AnnotAttrib.Transparency:
- double transparennt = Convert.ToDouble(annotEvent.Attribs[attrib]);
- if (transparennt > 1)
- {
- transparennt = (transparennt / 255D);
- }
- CPDFOpacityControl.OpacityValue = (int)(transparennt * 100);
- break;
- case AnnotAttrib.LineStyle:
- CPDFLineStyleControl.DashStyle = (DashStyle)(annotEvent.Attribs[attrib]);
- break;
- case AnnotAttrib.FontColor:
- FontColorPickerControl.SetCheckedForColor((Color)annotEvent.Attribs[attrib]);
- break;
- case AnnotAttrib.FontName:
- {
- string fontName = (string)annotEvent.Attribs[AnnotAttrib.FontName];
- if (fontName.Contains("Courier"))
- {
- FontCombox.SelectedIndex = 1;
- }
- else if (fontName == "Arial" || fontName.Contains("Helvetica"))
- {
- FontCombox.SelectedIndex = 0;
- }
- else if (fontName.Contains("Times"))
- {
- FontCombox.SelectedIndex = 2;
- }
- else
- {
- FontCombox.SelectedIndex = -1;
- }
- }
- break;
- case AnnotAttrib.FontSize:
- SetFontSize(Convert.ToDouble(annotEvent.Attribs[attrib]));
- break;
- case AnnotAttrib.NoteText:
- NoteTextBox.Text = annotEvent.Attribs[attrib].ToString();
- break;
- default:
- break;
- }
- }
- bool isBold = false;
- bool isItalic = false;
- if (annotEvent.Attribs.ContainsKey(AnnotAttrib.IsBold))
- {
- isBold = (bool)annotEvent.Attribs[AnnotAttrib.IsBold];
- }
- if (annotEvent.Attribs.ContainsKey(AnnotAttrib.IsItalic))
- {
- isItalic = (bool)annotEvent.Attribs[AnnotAttrib.IsItalic];
- }
- SetFontStyle(isBold, isItalic);
- }
- PolygonalEvent = annotEvent;
- }
- public void SetFontStyle(bool isBold, bool isItalic)
- {
- if (isBold == false && isItalic == false)
- {
- FontStyleCombox.SelectedIndex = 0;
- return;
- }
- if (isBold && isItalic == false)
- {
- FontStyleCombox.SelectedIndex = 1;
- return;
- }
- if (isBold == false && isItalic)
- {
- FontStyleCombox.SelectedIndex = 2;
- return;
- }
- if (isBold && isItalic)
- {
- FontStyleCombox.SelectedIndex = 3;
- }
- }
- private void SetFontSize(double size)
- {
- int index = SizeList.IndexOf((int)size);
- FontSizeComboBox.SelectedIndex = index;
- }
- }
- }
|