123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- using Compdfkit_Tools.Common;
- using Compdfkit_Tools.Data;
- using ComPDFKitViewer;
- using ComPDFKitViewer.AnnotEvent;
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace Compdfkit_Tools.PDFControlUI
- {
- public partial class CPDFFreeTextUI : UserControl
- {
- public event EventHandler<CPDFAnnotationData> PropertyChanged;
- private AnnotAttribEvent annotAttribEvent;
- public CPDFFreeTextUI()
- {
- InitializeComponent();
- ColorPickerControl.ColorChanged += ColorPickerControl_ColorChanged;
- CPDFOpacityControl.OpacityChanged += CPDFOpacityControl_OpacityChanged;
- CPDFFontControl.FontFamilyChanged += CPDFFontControl_FontFamilyChanged;
- CPDFFontControl.FontStyleChanged += CPDFFontControl_FontStyleChanged;
- CPDFFontControl.FontAlignChanged += CPDFFontControl_FontAlignChanged;
- CPDFFontControl.FontSizeChanged += CPDFFontControl_FontSizeChanged;
- CPDFAnnotationPreviewerControl.DrawFreeTextPreview(GetFreeTextData());
- }
- private void CPDFFontControl_FontSizeChanged(object sender, EventArgs e)
- {
- if (annotAttribEvent == null)
- {
- PropertyChanged?.Invoke(this, GetFreeTextData());
- }
- else
- {
- annotAttribEvent.UpdateAttrib(AnnotAttrib.FontSize, CPDFFontControl.FontSizeValue);
- annotAttribEvent.UpdateAnnot();
- }
- CPDFAnnotationPreviewerControl.DrawFreeTextPreview(GetFreeTextData());
- }
- private void CPDFFontControl_FontAlignChanged(object sender, EventArgs e)
- {
- if (annotAttribEvent == null)
- {
- PropertyChanged?.Invoke(this, GetFreeTextData());
- }
- else
- {
- annotAttribEvent.UpdateAttrib(AnnotAttrib.TextAlign, CPDFFontControl.TextAlignment);
- annotAttribEvent.UpdateAnnot();
- }
- CPDFAnnotationPreviewerControl.DrawFreeTextPreview(GetFreeTextData());
- }
- private void CPDFFontControl_FontStyleChanged(object sender, EventArgs e)
- {
- if (annotAttribEvent == null)
- {
- PropertyChanged?.Invoke(this, GetFreeTextData());
- }
- else
- {
- annotAttribEvent.UpdateAttrib(AnnotAttrib.IsBold, CPDFFontControl.IsBold);
- annotAttribEvent.UpdateAttrib(AnnotAttrib.IsItalic, CPDFFontControl.IsItalic);
- annotAttribEvent.UpdateAnnot();
- }
- CPDFAnnotationPreviewerControl.DrawFreeTextPreview(GetFreeTextData());
- }
- private void CPDFFontControl_FontFamilyChanged(object sender, EventArgs e)
- {
- if (annotAttribEvent == null)
- {
- PropertyChanged?.Invoke(this, GetFreeTextData());
- }
- else
- {
- annotAttribEvent.UpdateAttrib(AnnotAttrib.FontName, CPDFFontControl.FontFamilyValue);
- annotAttribEvent.UpdateAnnot();
- }
- CPDFAnnotationPreviewerControl.DrawFreeTextPreview(GetFreeTextData());
- }
- private void CPDFOpacityControl_OpacityChanged(object sender, EventArgs e)
- {
- if (annotAttribEvent == null)
- {
- PropertyChanged?.Invoke(this, GetFreeTextData());
- }
- else
- {
- annotAttribEvent.UpdateAttrib(AnnotAttrib.Transparency, CPDFOpacityControl.OpacityValue / 100.0);
- annotAttribEvent.UpdateAnnot();
- }
- CPDFAnnotationPreviewerControl.DrawFreeTextPreview(GetFreeTextData());
- }
- private void ColorPickerControl_ColorChanged(object sender, EventArgs e)
- {
- if (annotAttribEvent == null)
- {
- PropertyChanged?.Invoke(this, GetFreeTextData());
- }
- else
- {
- annotAttribEvent.UpdateAttrib(AnnotAttrib.FontColor, ((SolidColorBrush)ColorPickerControl.Brush).Color);
- annotAttribEvent.UpdateAnnot();
- }
- CPDFAnnotationPreviewerControl.DrawFreeTextPreview(GetFreeTextData());
- }
- private void NoteTextBox_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (annotAttribEvent == null)
- {
- PropertyChanged?.Invoke(this, GetFreeTextData());
- }
- else
- {
- annotAttribEvent.UpdateAttrib(AnnotAttrib.NoteText, NoteTextBox.Text);
- annotAttribEvent.UpdateAnnot();
- }
- }
- public void SetPresentAnnotAttrib(AnnotAttribEvent annotAttribEvent)
- {
- this.annotAttribEvent = null;
- ColorPickerControl.Brush = new SolidColorBrush((Color)annotAttribEvent.Attribs[AnnotAttrib.FontColor]);
- CPDFOpacityControl.OpacityValue = (int)((double)annotAttribEvent.Attribs[AnnotAttrib.Transparency] * 100);
- CPDFFontControl.FontFamilyValue = (string)annotAttribEvent.Attribs[AnnotAttrib.FontName];
- CPDFFontControl.FontSizeValue = Convert.ToInt16(annotAttribEvent.Attribs[AnnotAttrib.FontSize]);
- CPDFFontControl.IsBold = (bool)annotAttribEvent.Attribs[AnnotAttrib.IsBold];
- CPDFFontControl.IsItalic = (bool)annotAttribEvent.Attribs[AnnotAttrib.IsItalic];
- CPDFFontControl.TextAlignment = (TextAlignment)annotAttribEvent.Attribs[AnnotAttrib.TextAlign];
- NoteTextBox.Text = (string)annotAttribEvent.Attribs[AnnotAttrib.NoteText];
- this.annotAttribEvent = annotAttribEvent;
- if (annotAttribEvent.Attribs != null && annotAttribEvent.Attribs.ContainsKey(AnnotAttrib.FontColor))
- {
- ColorPickerControl.SetCheckedForColor((Color)annotAttribEvent.Attribs[AnnotAttrib.FontColor]);
- }
- }
- public CPDFFreeTextData GetFreeTextData()
- {
- CPDFFreeTextData pdfFreeTextData = new CPDFFreeTextData();
- pdfFreeTextData.AnnotationType = CPDFAnnotationType.FreeText;
- pdfFreeTextData.BorderColor = ((SolidColorBrush)ColorPickerControl.Brush).Color;
- pdfFreeTextData.Opacity = CPDFOpacityControl.OpacityValue / 100.0;
- pdfFreeTextData.FontFamily = CPDFFontControl.FontFamilyValue;
- pdfFreeTextData.FontSize = CPDFFontControl.FontSizeValue;
- pdfFreeTextData.IsBold = CPDFFontControl.IsBold;
- pdfFreeTextData.IsItalic = CPDFFontControl.IsItalic;
- pdfFreeTextData.TextAlignment = CPDFFontControl.TextAlignment;
- pdfFreeTextData.Note = NoteTextBox.Text;
- return pdfFreeTextData;
- }
- }
- }
|