123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- using ComPDFKit.Controls.Common;
- using ComPDFKitViewer;
- 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;
- using ComPDFKit.Controls.PDFControl;
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.Tool;
- using CFontNameHelper = ComPDFKit.PDFAnnotation.CTextAttribute.CFontNameHelper;
- namespace ComPDFKit.Controls.Measure.Property
- {
- 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 PolygonMeasureParam polygonMeasureParam;
-
- public CPDFPolygonAnnotation Annotation{ get; set; }
-
- public PDFViewControl ViewControl{ get; set; }
-
- //private AnnotAttribEvent PolygonalEvent { get; set; }
- public PolygonalProperty()
- {
- InitializeComponent();
- }
- private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (IsLoadedData)
- {
- if (Annotation != null && ViewControl != null)
- {
- Annotation.SetContent(NoteTextBox.Text);
- Annotation.UpdateAp();
- ViewControl?.UpdateAnnotFrame();
- }
- }
- }
- private void FontStyleCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!IsLoadedData) return;
- 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;
- }
- if(Annotation != null)
- {
- CTextAttribute textAttribute = Annotation.GetTextAttribute();
- var fontType = CFontNameHelper.GetFontType((FontCombox.SelectedItem as ComboBoxItem).Content.ToString());
- var newName = CFontNameHelper.ObtainFontName(fontType, isBold, isItalic);
- textAttribute.FontName = newName;
- Annotation.SetTextAttribute(textAttribute);
- Annotation.UpdateAp();
- ViewControl?.UpdateAnnotFrame();
- }
- }
- private void FontSizeCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (IsLoadedData)
- {
- if (FontSizeComboBox.SelectedItem != null)
- {
- if (Annotation != null && ViewControl != null)
- {
- CTextAttribute textAttribute = Annotation.GetTextAttribute();
- textAttribute.FontSize = (float)Convert.ToDouble(FontSizeComboBox.SelectedItem);
- Annotation.SetTextAttribute(textAttribute);
- Annotation.UpdateAp();
- ViewControl?.UpdateAnnotFrame();
- }
- }
- }
- }
- private void FontCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (IsLoadedData)
- {
- if (Annotation != null && ViewControl != null)
- {
- ComboBoxItem selectItem = FontCombox.SelectedItem as ComboBoxItem;
- if (selectItem != null && selectItem.Content != null)
- {
- CTextAttribute textAttr = Annotation.GetTextAttribute();
- bool isBold = CFontNameHelper.IsBold(textAttr.FontName);
- bool isItalic = CFontNameHelper.IsItalic(textAttr.FontName);
- var fontType = CFontNameHelper.GetFontType(selectItem.Content.ToString());
- textAttr.FontName = CFontNameHelper.ObtainFontName(fontType, isBold, isItalic);
- Annotation.SetTextAttribute(textAttr);
- Annotation.UpdateAp();
- ViewControl.UpdateAnnotFrame();
- }
- }
- }
- }
- 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)
- {
- if (IsLoadedData)
- {
- if (Annotation != null && ViewControl != null)
- {
- if (BorderColorPickerControl.GetBrush() is SolidColorBrush checkBrush)
- {
- byte[] color = { checkBrush.Color.R, checkBrush.Color.G, checkBrush.Color.B };
- Annotation.SetLineColor(color);
- Annotation.UpdateAp();
- ViewControl.UpdateAnnotFrame();
- }
- }
- }
- }
- private void FillColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- if (IsLoadedData)
- {
- if (Annotation != null && ViewControl != null)
- {
- SolidColorBrush checkBrush = FillColorPickerControl.GetBrush() as SolidColorBrush;
- if (checkBrush != null)
- {
- byte[] color = { checkBrush.Color.R, checkBrush.Color.G, checkBrush.Color.B };
- Annotation.SetBgColor(color);
- Annotation.UpdateAp();
- ViewControl.UpdateAnnotFrame();
- }
- }
- }
- }
- private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
- {
- if (IsLoadedData)
- {
- if (Annotation != null && ViewControl != null)
- {
- double opacity = CPDFOpacityControl.OpacityValue / 100.0;
- if (opacity > 0 && opacity <= 1)
- {
- opacity = opacity * 255;
- }
- if (Math.Abs(opacity - Annotation.GetTransparency()) > 0.01)
- {
- Annotation.SetTransparency((byte)opacity);
- Annotation.UpdateAp();
- ViewControl.UpdateAnnotFrame();
- }
- }
- }
- }
- private void CPDFLineStyleControl_LineStyleChanged(object sender, EventArgs e)
- {
- if (!IsLoadedData) return;
- if (Annotation != null && ViewControl != null)
- {
- float[] dashArray = null;
- C_BORDER_STYLE borderStyle;
- if (CPDFLineStyleControl.DashStyle == DashStyles.Solid || CPDFLineStyleControl.DashStyle == null)
- {
- dashArray = new float[0];
- borderStyle = C_BORDER_STYLE.BS_SOLID;
- }
- else
- {
- List<float> floatArray = new List<float>();
- foreach (double num in CPDFLineStyleControl.DashStyle.Dashes)
- {
- floatArray.Add((float)num);
- }
- dashArray = floatArray.ToArray();
- borderStyle = C_BORDER_STYLE.BS_DASHDED;
- }
- Annotation.SetBorderStyle(borderStyle, dashArray);
- Annotation.UpdateAp();
- ViewControl.UpdateAnnotFrame();
- }
- }
- private void FontColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- if (!IsLoadedData) return;
- SolidColorBrush checkBrush = FontColorPickerControl.GetBrush() as SolidColorBrush;
- if (checkBrush != null && Annotation != null && ViewControl != null)
- {
- byte[] color = { checkBrush.Color.R, checkBrush.Color.G, checkBrush.Color.B };
- if (Annotation != null)
- {
- CTextAttribute textAttribute = Annotation.GetTextAttribute();
- textAttribute.FontColor = color;
- Annotation.SetTextAttribute(textAttribute);
- Annotation.UpdateAp();
- ViewControl.UpdateAnnotFrame();
- }
- }
- }
- 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;
- }
-
- public void SetFontName(string fontName)
- {
- foreach (ComboBoxItem item in FontCombox.Items)
- {
- if (item.Content.ToString() == fontName)
- {
- FontCombox.SelectedItem = item;
- break;
- }
- }
- }
- public void SetAnnotParam(PolygonMeasureParam param, CPDFAnnotation annot, PDFViewControl viewControl)
- {
- Annotation = annot as CPDFPolygonAnnotation;
- ViewControl = viewControl;
- polygonMeasureParam = param;
- if (param == null)
- {
- return;
- }
-
- Color lineColor = Color.FromRgb(param.LineColor[0], param.LineColor[1], param.LineColor[2]);
- BorderColorPickerControl.SetCheckedForColor(lineColor);
- if (polygonMeasureParam.BorderStyle == C_BORDER_STYLE.BS_SOLID)
- {
- CPDFLineStyleControl.DashStyle = DashStyles.Solid;
- }
- else
- {
- List<double> dashArray = new List<double>();
- foreach (double num in param.LineDash)
- {
- dashArray.Add(num);
- }
- CPDFLineStyleControl.DashStyle = new DashStyle(dashArray, 0);
- }
- double opacity = param.Transparency / 255.0 * 100.0;
- CPDFOpacityControl.OpacityValue = (int)Math.Ceiling(opacity);
- NoteTextBox.Text = param.Content;
- SetFontSize(param.FontSize);
- SetFontStyle(param.IsBold,param.IsItalic);
- SetFontName(param.FontName);
- }
- }
- }
|