1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291 |
- using Compdfkit_Tools.Data;
- using Compdfkit_Tools.PDFControlUI;
- using System;
- using System.Collections.Generic;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media.Imaging;
- using Compdfkit_Tools.Annotation.PDFAnnotationPanel.PDFAnnotationUI;
- using System.IO;
- using System.Windows.Ink;
- using Compdfkit_Tools.Annotation.PDFAnnotationUI;
- using Microsoft.Win32;
- using System.Windows.Media;
- using Compdfkit_Tools.Properties;
- using static ComPDFKit.Tool.CPDFToolManager;
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.Tool;
- using ComPDFKit.Tool.Help;
- using ComPDFKit.Tool.SettingParam;
- using ComPDFKit.Import;
- using ComPDFKitViewer.BaseObject;
- using ComPDFKitViewer.Helper;
- using ComPDFKit.Viewer.Helper;
- namespace Compdfkit_Tools.PDFControl
- {
- public partial class CPDFAnnotationControl : UserControl
- {
- private bool isTempPanel = false;
- private CPDFAnnotationType currentAnnotationType = CPDFAnnotationType.Unknown;
- private PDFViewControl pdfViewerControl;
- private UIElement annotationPanel = null;
- private UIElement tempAnnotationPanel = null;
- private CPDFMarkupUI pdfHighlightUI;
- private CPDFMarkupUI pdfUnderlineUI;
- private CPDFMarkupUI pdfSquigglyUI;
- private CPDFMarkupUI pdfStrikeoutUI;
- private CPDFShapeUI pdfSquareUI;
- private CPDFShapeUI pdfCircleUI;
- private CPDFShapeUI pdfLineUI;
- private CPDFShapeUI pdfArrowUI;
- private CPDFFreehandUI pdfFreehandUI;
- private CPDFFreeTextUI pdfFreeTextUI;
- private CPDFNoteUI pdfNoteUI;
- private CPDFStampUI pdfStampUI;
- private CPDFSignatureUI pdfSignatureUI;
- private CPDFLinkUI pdfLinkUI;
- private bool disableClean;
- public event EventHandler ClearAnnotationBar;
- public CPDFAnnotationControl()
- {
- InitializeComponent();
- }
- public void SetPDFViewer(PDFViewControl pdfViewer)
- {
- if (this.pdfViewerControl != null)
- {
- UnLoadPDFViewHandler();
- }
- this.pdfViewerControl = pdfViewer;
- LoadPDFViewHandler();
- }
- public void LoadPDFViewHandler()
- {
- if (this.pdfViewerControl != null)
- {
- pdfViewerControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
- pdfViewerControl.MouseLeftButtonDownHandler += PDFToolManager_MouseLeftButtonDownHandler;
- pdfViewerControl.MouseLeftButtonUpHandler -= PdfViewerControl_MouseLeftButtonUpHandler;
- pdfViewerControl.MouseLeftButtonUpHandler += PdfViewerControl_MouseLeftButtonUpHandler;
- //this.pdfViewerControl.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
- //this.pdfViewerControl.AnnotEditHandler -= PdfViewer_AnnotEditHandler;
- //this.pdfViewerControl.AnnotEditHandler += PdfViewer_AnnotEditHandler;
- pdfViewerControl.MouseRightButtonDownHandler -= PDFViewControl_MouseRightButtonDownHandler;
- pdfViewerControl.MouseRightButtonDownHandler += PDFViewControl_MouseRightButtonDownHandler;
- }
- }
- private void PDFViewControl_MouseRightButtonDownHandler(object sender, MouseEventObject e)
- {
- //throw new NotImplementedException();
- }
- private void PdfViewerControl_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
- {
- if (e.IsCreate)
- {
- pdfViewerControl.UpdateAnnotFrame();
- if (currentAnnotationType == CPDFAnnotationType.Image || currentAnnotationType == CPDFAnnotationType.Stamp || currentAnnotationType == CPDFAnnotationType.Signature)
- {
- pdfViewerControl.SetToolType(ToolType.Pan);
- pdfViewerControl.SetIsVisibleCustomMouse(false);
- pdfViewerControl.SetIsShowStampMouse(false);
- }
- }
- }
- //private void PdfViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
- //{
- // if (e != null && e.Count > 0)
- // {
- // if (e[0].EditAction == ActionType.Del)
- // {
- // if (pdfViewerControl.MouseMode == MouseModes.AnnotCreate && pdfViewerControl.ToolManager.CurrentAnnotArgs is EraseArgs)
- // {
- // return;
- // }
- // SetAnnotEventData(null);
- // }
- // if (e[0].EditAction == ActionType.Modify && e[0].EditAnnotArgs != null && e[0].EditAnnotArgs.EventType == AnnotArgsType.AnnotSticky)
- // {
- // CPDFNoteUI tempUI = annotationPanel as CPDFNoteUI;
- // if (tempUI == null || tempUI.annotAttribEvent == null)
- // {
- // tempUI = tempAnnotationPanel as CPDFNoteUI;
- // }
- // if (tempUI == null || tempUI.annotAttribEvent == null)
- // {
- // tempUI = pdfNoteUI;
- // }
- // if (tempUI != null && tempUI.annotAttribEvent != null)
- // {
- // AnnotAttribEvent oldEvent = tempUI.annotAttribEvent;
- // oldEvent.Attribs[AnnotAttrib.NoteText] = e[0].EditAnnotArgs.Content;
- // tempUI.SetPresentAnnotAttrib(oldEvent);
- // }
- // }
- // if (e[0].EditAction == ActionType.Add && e[0].EditAnnotArgs.EventType == AnnotArgsType.AnnotStamp)
- // {
- // pdfViewerControl.SetMouseMode(MouseModes.PanTool);
- // }
- // }
- //}
- public void UnLoadPDFViewHandler()
- {
- if (this.pdfViewerControl != null)
- {
- pdfViewerControl.MouseLeftButtonDownHandler -= PDFToolManager_MouseLeftButtonDownHandler;
- }
- }
- private void AnnotationControl_Loaded(object sender, RoutedEventArgs e)
- {
- LoadPDFViewHandler();
- }
- private void AnnotationControl_Unloaded(object sender, RoutedEventArgs e)
- {
- UnLoadPDFViewHandler();
- }
- private UIElement GetAnnotationPanel()
- {
- return AnnotationPanelContainer.Child;
- }
- private void SetAnnotationPanel(UIElement newChild)
- {
- AnnotationPanelContainer.Child = newChild;
- }
- private void ExpandPanel()
- {
- AnnotationPanelContainer.Visibility = Visibility.Visible;
- }
- private void ChangeAnnotationData()
- {
- switch (currentAnnotationType)
- {
- case CPDFAnnotationType.Highlight:
- case CPDFAnnotationType.Underline:
- case CPDFAnnotationType.Squiggly:
- case CPDFAnnotationType.Strikeout:
- (annotationPanel as CPDFMarkupUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
- (annotationPanel as CPDFMarkupUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
- SetAnnotationProperty((annotationPanel as CPDFMarkupUI).GetMarkupData());
- break;
- case CPDFAnnotationType.Square:
- case CPDFAnnotationType.Circle:
- case CPDFAnnotationType.Line:
- case CPDFAnnotationType.Arrow:
- (annotationPanel as CPDFShapeUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
- (annotationPanel as CPDFShapeUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
- SetAnnotationProperty((annotationPanel as CPDFShapeUI).GetShapeData());
- break;
- case CPDFAnnotationType.Note:
- (annotationPanel as CPDFNoteUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
- (annotationPanel as CPDFNoteUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
- SetAnnotationProperty((annotationPanel as CPDFNoteUI).GetNoteData());
- break;
- case CPDFAnnotationType.Freehand:
- (annotationPanel as CPDFFreehandUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
- (annotationPanel as CPDFFreehandUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
- SetAnnotationProperty((annotationPanel as CPDFFreehandUI).GetFreehandData());
- break;
- case CPDFAnnotationType.FreeText:
- (annotationPanel as CPDFFreeTextUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
- (annotationPanel as CPDFFreeTextUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
- SetAnnotationProperty((annotationPanel as CPDFFreeTextUI).GetFreeTextData());
- break;
- case CPDFAnnotationType.Stamp:
- (annotationPanel as CPDFStampUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
- (annotationPanel as CPDFStampUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
- break;
- case CPDFAnnotationType.Signature:
- (annotationPanel as CPDFSignatureUI).PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
- (annotationPanel as CPDFSignatureUI).PropertyChanged += CPDFAnnotationControl_PropertyChanged;
- break;
- default:
- break;
- }
- }
- private void SetAnnotationProperty(CPDFAnnotationData pdfAnnotationData = null)
- {
- if (pdfAnnotationData == null)
- {
- pdfViewerControl.SetToolType(ToolType.Pan);
- pdfViewerControl.SetIsShowStampMouse(false);
- pdfViewerControl.SetIsVisibleCustomMouse(false);
- return;
- }
- CPDFAnnotationType annotationType = pdfAnnotationData.AnnotationType;
- AnnotParam annotHandlerEventArgs = null;
- pdfViewerControl.SetToolType(ToolType.CreateAnnot);
- switch (annotationType)
- {
- case CPDFAnnotationType.Highlight:
- {
- CPDFMarkupData highlightData = pdfAnnotationData as CPDFMarkupData;
- annotHandlerEventArgs = new HighlightParam();
- byte[] Color = new byte[] { highlightData.Color.R, highlightData.Color.G, highlightData.Color.B };
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT;
- (annotHandlerEventArgs as HighlightParam).HighlightColor = Color;
- (annotHandlerEventArgs as HighlightParam).Transparency = Convert.ToByte(highlightData.Opacity * 255);
- (annotHandlerEventArgs as HighlightParam).Content = highlightData.Note;
- (annotHandlerEventArgs as HighlightParam).Author = CPDFMarkupData.Author;
- (annotHandlerEventArgs as HighlightParam).Locked = highlightData.IsLocked;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT);
- }
- break;
- case CPDFAnnotationType.Underline:
- {
- CPDFMarkupData underlineData = pdfAnnotationData as CPDFMarkupData;
- annotHandlerEventArgs = new UnderlineParam();
- byte[] Color = new byte[] { underlineData.Color.R, underlineData.Color.G, underlineData.Color.B };
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE;
- (annotHandlerEventArgs as UnderlineParam).UnderlineColor = Color;
- (annotHandlerEventArgs as UnderlineParam).Transparency = Convert.ToByte(underlineData.Opacity * 255);
- (annotHandlerEventArgs as UnderlineParam).Author = CPDFMarkupData.Author;
- (annotHandlerEventArgs as UnderlineParam).Content = underlineData.Note;
- (annotHandlerEventArgs as UnderlineParam).Locked = underlineData.IsLocked;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE);
- }
- break;
- case CPDFAnnotationType.Strikeout:
- {
- CPDFMarkupData strikeoutData = pdfAnnotationData as CPDFMarkupData;
- annotHandlerEventArgs = new StrikeoutParam();
- byte[] Color = new byte[] { strikeoutData.Color.R, strikeoutData.Color.G, strikeoutData.Color.B };
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT;
- (annotHandlerEventArgs as StrikeoutParam).StrikeoutColor = Color;
- (annotHandlerEventArgs as StrikeoutParam).Transparency = Convert.ToByte(strikeoutData.Opacity * 255);
- (annotHandlerEventArgs as StrikeoutParam).Locked = strikeoutData.IsLocked;
- (annotHandlerEventArgs as StrikeoutParam).Author = CPDFMarkupData.Author;
- (annotHandlerEventArgs as StrikeoutParam).Content = strikeoutData.Note;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT);
- }
- break;
- case CPDFAnnotationType.Squiggly:
- {
- CPDFMarkupData squigglyData = pdfAnnotationData as CPDFMarkupData;
- annotHandlerEventArgs = new SquigglyParam();
- byte[] Color = new byte[] { squigglyData.Color.R, squigglyData.Color.G, squigglyData.Color.B };
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY;
- (annotHandlerEventArgs as SquigglyParam).SquigglyColor = Color;
- (annotHandlerEventArgs as SquigglyParam).Transparency = Convert.ToByte(squigglyData.Opacity * 255);
- (annotHandlerEventArgs as SquigglyParam).Locked = squigglyData.IsLocked;
- (annotHandlerEventArgs as SquigglyParam).Author = CPDFMarkupData.Author;
- (annotHandlerEventArgs as SquigglyParam).Content = squigglyData.Note;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY);
- }
- break;
- case CPDFAnnotationType.Square:
- {
- CPDFShapeData squareData = pdfAnnotationData as CPDFShapeData;
- annotHandlerEventArgs = new SquareParam();
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE;
- byte[] LineColor = new byte[] { squareData.BorderColor.R, squareData.BorderColor.G, squareData.BorderColor.B };
- (annotHandlerEventArgs as SquareParam).LineColor = LineColor;
- if (squareData.FillColor != Colors.Transparent)
- {
- byte[] FillColor = new byte[] { squareData.FillColor.R, squareData.FillColor.G, squareData.FillColor.B };
- (annotHandlerEventArgs as SquareParam).BgColor = FillColor;
- (annotHandlerEventArgs as SquareParam).HasBgColor = true;
- }
- (annotHandlerEventArgs as SquareParam).LineWidth = squareData.Thickness;
- (annotHandlerEventArgs as SquareParam).Transparency = Convert.ToByte(squareData.Opacity * 255);
- ParamConverter.ParseDashStyle(squareData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
- (annotHandlerEventArgs as SquareParam).LineDash = LineDash;
- (annotHandlerEventArgs as SquareParam).BorderStyle = BorderStyle;
- (annotHandlerEventArgs as SquareParam).Author = CPDFMarkupData.Author;
- (annotHandlerEventArgs as SquareParam).Content = squareData.Note;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE);
- }
- break;
- case CPDFAnnotationType.Circle:
- {
- CPDFShapeData cicleData = pdfAnnotationData as CPDFShapeData;
- annotHandlerEventArgs = new CircleParam();
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE;
- byte[] LineColor = new byte[] { cicleData.BorderColor.R, cicleData.BorderColor.G, cicleData.BorderColor.B };
- (annotHandlerEventArgs as CircleParam).LineColor = LineColor;
- if (cicleData.FillColor != Colors.Transparent)
- {
- byte[] BgColor = new byte[] { cicleData.FillColor.R, cicleData.FillColor.G, cicleData.FillColor.B };
- (annotHandlerEventArgs as CircleParam).BgColor = BgColor;
- (annotHandlerEventArgs as CircleParam).HasBgColor = true;
- }
- (annotHandlerEventArgs as CircleParam).LineWidth = cicleData.Thickness;
- (annotHandlerEventArgs as CircleParam).Transparency = Convert.ToByte(cicleData.Opacity * 255);
- ParamConverter.ParseDashStyle(cicleData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
- (annotHandlerEventArgs as CircleParam).LineDash = LineDash;
- (annotHandlerEventArgs as CircleParam).BorderStyle = BorderStyle;
- (annotHandlerEventArgs as CircleParam).Author = CPDFMarkupData.Author;
- (annotHandlerEventArgs as CircleParam).Content = cicleData.Note;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE);
- }
- break;
- case CPDFAnnotationType.Arrow:
- case CPDFAnnotationType.Line:
- {
- CPDFLineShapeData lineData = pdfAnnotationData as CPDFLineShapeData;
- annotHandlerEventArgs = new LineParam();
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINE;
- byte[] LineColor = new byte[] { lineData.BorderColor.R, lineData.BorderColor.G, lineData.BorderColor.B };
- (annotHandlerEventArgs as LineParam).LineColor = LineColor;
- (annotHandlerEventArgs as LineParam).LineWidth = lineData.Thickness;
- (annotHandlerEventArgs as LineParam).Transparency = Convert.ToByte(lineData.Opacity * 255);
- ParamConverter.ParseDashStyle(lineData.DashStyle, out float[] LineDash, out C_BORDER_STYLE BorderStyle);
- (annotHandlerEventArgs as LineParam).LineDash = LineDash;
- (annotHandlerEventArgs as LineParam).BorderStyle = BorderStyle;
- (annotHandlerEventArgs as LineParam).HeadLineType = lineData.LineType.HeadLineType;
- (annotHandlerEventArgs as LineParam).TailLineType = lineData.LineType.TailLineType;
- (annotHandlerEventArgs as LineParam).Author = CPDFMarkupData.Author;
- (annotHandlerEventArgs as LineParam).Content = lineData.Note;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINE);
- }
- break;
- case CPDFAnnotationType.Note:
- {
- CPDFNoteData noteData = pdfAnnotationData as CPDFNoteData;
- annotHandlerEventArgs = new StickyNoteParam();
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_TEXT;
- byte[] StickyNoteColor = new byte[] { noteData.BorderColor.R, noteData.BorderColor.G, noteData.BorderColor.B };
- (annotHandlerEventArgs as StickyNoteParam).StickyNoteColor = StickyNoteColor;
- (annotHandlerEventArgs as StickyNoteParam).Content = noteData.Note;
- (annotHandlerEventArgs as StickyNoteParam).Transparency = 255;
- (annotHandlerEventArgs as StickyNoteParam).Author = CPDFMarkupData.Author;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_TEXT);
- }
- break;
- case CPDFAnnotationType.Freehand:
- {
- CPDFFreehandData freehandData = pdfAnnotationData as CPDFFreehandData;
- annotHandlerEventArgs = new InkParam();
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
- byte[] LineColor = new byte[] { freehandData.BorderColor.R, freehandData.BorderColor.G, freehandData.BorderColor.B };
- (annotHandlerEventArgs as InkParam).InkColor = LineColor;
- (annotHandlerEventArgs as InkParam).Thickness = freehandData.Thickness;
- (annotHandlerEventArgs as InkParam).Transparency = Convert.ToByte(freehandData.Opacity * 255);
- (annotHandlerEventArgs as InkParam).Content = freehandData.Note;
- (annotHandlerEventArgs as InkParam).Author = CPDFMarkupData.Author;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
- }
- break;
- case CPDFAnnotationType.FreeText:
- {
- CPDFFreeTextData freeTextData = pdfAnnotationData as CPDFFreeTextData;
- annotHandlerEventArgs = new FreeTextParam();
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT;
- (annotHandlerEventArgs as FreeTextParam).Transparency = Convert.ToByte(freeTextData.Opacity * 255);
- (annotHandlerEventArgs as FreeTextParam).FontName = freeTextData.FontFamily.ToString();
- byte[] FontColor = new byte[] { freeTextData.BorderColor.R, freeTextData.BorderColor.G, freeTextData.BorderColor.B };
- (annotHandlerEventArgs as FreeTextParam).FontColor = FontColor;
- (annotHandlerEventArgs as FreeTextParam).IsBold = freeTextData.IsBold;
- (annotHandlerEventArgs as FreeTextParam).IsItalic = freeTextData.IsItalic;
- (annotHandlerEventArgs as FreeTextParam).FontSize = freeTextData.FontSize;
- switch (freeTextData.TextAlignment)
- {
- case TextAlignment.Left:
- (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_LEFT;
- break;
- case TextAlignment.Right:
- (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_RIGHT;
- break;
- case TextAlignment.Center:
- (annotHandlerEventArgs as FreeTextParam).Alignment = C_TEXT_ALIGNMENT.ALIGNMENT_CENTER;
- break;
- default:
- break;
- }
- (annotHandlerEventArgs as FreeTextParam).Content = freeTextData.Note;
- (annotHandlerEventArgs as FreeTextParam).Author = CPDFMarkupData.Author;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT);
- }
- break;
- case CPDFAnnotationType.Stamp:
- {
- StampParam stampParam = new StampParam();
- stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
- CPDFStampData stampData = pdfAnnotationData as CPDFStampData;
- SetStamp(ref stampParam, stampData);
- annotHandlerEventArgs = stampParam;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
- byte[] imageData = null;
- int imageWidth = 0;
- int imageHeight = 0;
- PDFHelp.ImageStreamToByte(stampParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
- if (imageData != null && imageWidth > 0 && imageHeight > 0)
- {
- pdfViewerControl.SetStampMouseImage(imageData, imageWidth, imageHeight);
- }
- pdfViewerControl.SetIsVisibleCustomMouse(true);
- pdfViewerControl.SetIsShowStampMouse(true);
- }
- break;
- case CPDFAnnotationType.Signature:
- {
- AnnotParam signatureParam = new AnnotParam();
- CPDFSignatureData SignatureData = pdfAnnotationData as CPDFSignatureData;
- SetSignature(ref signatureParam, SignatureData);
- switch (signatureParam.CurrentType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
- {
- StampParam stampParam = (StampParam)signatureParam;
- stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
- byte[] imageData = null;
- int imageWidth = 0;
- int imageHeight = 0;
- PDFHelp.ImageStreamToByte(stampParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
- if (imageData != null && imageWidth > 0 && imageHeight > 0)
- {
- pdfViewerControl.SetStampMouseImage(imageData, imageWidth, imageHeight);
- pdfViewerControl.SetIsVisibleCustomMouse(true);
- pdfViewerControl.SetIsShowStampMouse(true);
- annotHandlerEventArgs = signatureParam;
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
- {
- WriteableBitmap writeableBitmap = CreateInkImaget(signatureParam as InkParam);
- byte[] imageArray = new byte[writeableBitmap.PixelWidth * writeableBitmap.PixelHeight * 4];
- writeableBitmap.CopyPixels(imageArray, writeableBitmap.PixelWidth * 4, 0);
- pdfViewerControl.SetStampMouseImage(imageArray, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight);
- pdfViewerControl.SetIsVisibleCustomMouse(true);
- pdfViewerControl.SetIsShowStampMouse(true);
- annotHandlerEventArgs = signatureParam;
- }
- break;
- default:
- return;
- }
- }
- break;
- case CPDFAnnotationType.Link:
- if (annotHandlerEventArgs != null)
- {
- annotHandlerEventArgs.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINK;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
- }
- break;
- case CPDFAnnotationType.Unknown:
- pdfViewerControl.SetToolType(ToolType.Pan);
- return;
- default:
- break;
- }
- pdfViewerControl.SetToolType(ToolType.CreateAnnot);
- if (annotationType != CPDFAnnotationType.Stamp && annotationType != CPDFAnnotationType.Signature && annotationType != CPDFAnnotationType.Image)
- {
- pdfViewerControl.SetIsShowStampMouse(false);
- }
- pdfViewerControl.SetAnnotParam(annotHandlerEventArgs);
- }
- private WriteableBitmap CreateInkImaget(InkParam inkParam)
- {
- if (inkParam == null)
- {
- return null;
- }
- if (inkParam.InkPath != null && inkParam.InkPath.Count > 0)
- {
- GeometryGroup PaintGeomtry = new GeometryGroup();
- int minLeft = -1;
- int minTop = -1;
- int maxLeft = -1;
- int maxTop = -1;
- foreach (List<CPoint> Item in inkParam.InkPath)
- {
- for (int i = 0; i < Item.Count; i++)
- {
- CPoint paintPoint = Item[i];
- if (minLeft == -1)
- {
- minLeft = (int)paintPoint.x;
- maxLeft = (int)paintPoint.x;
- minTop = (int)paintPoint.y;
- maxTop = (int)paintPoint.y;
- }
- else
- {
- minLeft = (int)Math.Min(minLeft, paintPoint.x);
- maxLeft = (int)Math.Max(maxLeft, paintPoint.x);
- minTop = (int)Math.Min(minTop, paintPoint.y);
- maxTop = (int)Math.Max(maxTop, paintPoint.y);
- }
- }
- }
- if (minLeft >= 0 && maxLeft > minLeft && minTop >= 0 && maxTop > minTop)
- {
- List<List<CPoint>> points = new List<List<CPoint>>();
- foreach (List<CPoint> Item in inkParam.InkPath)
- {
- PathGeometry PaintPath = new PathGeometry();
- PathFigureCollection Figures = new PathFigureCollection();
- PathFigure AddFigure = new PathFigure();
- Figures.Add(AddFigure);
- PaintPath.Figures = Figures;
- PaintGeomtry.Children.Add(PaintPath);
- List<CPoint> changeList = new List<CPoint>();
- for (int i = 0; i < Item.Count; i++)
- {
- Point paintPoint = new Point(DpiHelper.PDFNumToStandardNum(Item[i].x - minLeft), DpiHelper.PDFNumToStandardNum(Item[i].y - minTop));
- changeList.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(paintPoint)));
- if (i == 0)
- {
- AddFigure.StartPoint = paintPoint;
- }
- else
- {
- LineSegment AddSegment = new LineSegment();
- AddSegment.Point = paintPoint;
- AddFigure.Segments.Add(AddSegment);
- }
- }
- if (changeList.Count > 0)
- {
- points.Add(changeList);
- }
- }
- int drawWidth = (int)DpiHelper.PDFNumToStandardNum(maxLeft - minLeft);
- int drawHeight = (int)DpiHelper.PDFNumToStandardNum(maxTop - minTop);
- inkParam.InkPath = points;
- DefaultSettingParam defaultSettingParam = pdfViewerControl.PDFViewTool.GetDefaultSettingParam();
- defaultSettingParam.SetAnnotParam(inkParam);
- DrawingVisual copyVisual = new DrawingVisual();
- DrawingContext copyContext = copyVisual.RenderOpen();
- Color color = ParamConverter.ConverterByteForColor(inkParam.InkColor);
- color.A = inkParam.Transparency;
- Pen drawPen = new Pen(new SolidColorBrush(color), inkParam.Thickness);
- copyContext?.DrawGeometry(null, drawPen, PaintGeomtry);
- copyContext.Close();
- RenderTargetBitmap targetBitmap = new RenderTargetBitmap(drawWidth, drawHeight, 96, 96, PixelFormats.Pbgra32);
- targetBitmap.Render(copyVisual);
- byte[] ImageArray = new byte[targetBitmap.PixelWidth * targetBitmap.PixelHeight * 4];
- targetBitmap.CopyPixels(new Int32Rect(0, 0, (int)targetBitmap.PixelWidth, (int)targetBitmap.PixelHeight), ImageArray, targetBitmap.PixelWidth * 4, 0);
- WriteableBitmap writeBitmap = new WriteableBitmap(targetBitmap.PixelWidth, targetBitmap.PixelHeight, 96, 96, PixelFormats.Bgra32, null);
- writeBitmap.WritePixels(new Int32Rect(0, 0, targetBitmap.PixelWidth, targetBitmap.PixelHeight), ImageArray, targetBitmap.PixelWidth * 4, 0);
- return writeBitmap;
- }
- }
- return null;
- }
- public void SetSignature(ref AnnotParam annotParam, CPDFSignatureData stamp)
- {
- switch (stamp.Type)
- {
- case SignatureType.TextType:
- case SignatureType.ImageType:
- {
- annotParam = new StampParam();
- annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
- (annotParam as StampParam).Transparency = 255;
- (annotParam as StampParam).StampType = C_STAMP_TYPE.IMAGE_STAMP;
- if (!string.IsNullOrEmpty(stamp.SourcePath))
- {
- BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
- PngBitmapEncoder encoder = new PngBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(image));
- MemoryStream memoryStream = new MemoryStream();
- encoder.Save(memoryStream);
- (annotParam as StampParam).ImageStream = memoryStream;
- }
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
- }
- break;
- case SignatureType.Drawing:
- {
- annotParam = new InkParam();
- (annotParam as InkParam).Transparency = stamp.inkColor.A;
- annotParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
- List<List<Point>> RawPointList = GetPoints(stamp.DrawingPath);
- if (RawPointList != null && RawPointList.Count > 0)
- {
- List<List<CPoint>> inkPath = new List<List<CPoint>>();
- foreach (List<Point> inkPoints in RawPointList)
- {
- List<CPoint> ink = new List<CPoint>();
- foreach (Point point in inkPoints)
- {
- ink.Add(new CPoint((float)DpiHelper.StandardNumToPDFNum(point.X), (float)DpiHelper.StandardNumToPDFNum(point.Y)));
- }
- if (ink.Count > 0)
- {
- inkPath.Add(ink);
- }
- }
- if (inkPath.Count > 0)
- {
- (annotParam as InkParam).InkPath = inkPath;
- }
- }
- (annotParam as InkParam).Thickness = stamp.inkThickness;
- byte[] InkColor = new byte[] { stamp.inkColor.R, stamp.inkColor.G, stamp.inkColor.B };
- (annotParam as InkParam).InkColor = InkColor;
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
- }
- break;
- default:
- break;
- }
- }
- private List<List<Point>> GetPoints(string Path)
- {
- StrokeCollection Strokes;
- List<List<Point>> RawPointList = new List<List<Point>>();
- using (FileStream strokeStream = File.OpenRead(Path))
- {
- Strokes = new StrokeCollection(strokeStream);
- }
- for (int kk = 0; kk < Strokes.Count; kk++)
- {
- List<Point> p = new List<Point>();
- RawPointList.Add(p);
- for (int gg = 0; gg < Strokes[kk].StylusPoints.Count; gg++)
- {
- var point = Strokes[kk].StylusPoints[gg].ToPoint();
- if (point.X >= 0 && point.Y >= 0)
- RawPointList[kk].Add(point);
- }
- }
- return RawPointList;
- }
- private void SetStamp(ref StampParam stampParam, CPDFStampData stamp)
- {
- stampParam.StampText = stamp.StampText;
- stampParam.Author = CPDFMarkupData.Author;
- stampParam.Transparency = Convert.ToByte(stamp.Opacity * 255);
- stampParam.DateText = stamp.StampTextDate;
- stampParam.TextStampColor = stamp.TextColor;
- stampParam.TextStampShape = stamp.TextSharp;
- if (!string.IsNullOrEmpty(stamp.SourcePath))
- {
- BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
- PngBitmapEncoder encoder = new PngBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(image));
- MemoryStream memoryStream = new MemoryStream();
- encoder.Save(memoryStream);
- stampParam.ImageStream = memoryStream;
- }
- else
- {
- var i = pdfStampUI.CustomStampList.IndexOf(stamp);
- Settings.Default.CustomStampList.RemoveAt(i);
- Settings.Default.Save();
- pdfStampUI.LoadSettings();
- return;
- }
- stampParam.StampType = stamp.Type;
- }
- public void AnnotationCancel()
- {
- this.pdfViewerControl.SetToolType(ToolType.Pan);
- pdfViewerControl.SetIsShowStampMouse(false);
- ClearPanel();
- }
- private void CPDFAnnotationControl_PropertyChanged(object sender, CPDFAnnotationData e)
- {
- SetAnnotationProperty(e);
- }
- public void InitAnnotationPanel(CPDFAnnotationType annotationType)
- {
- switch (annotationType)
- {
- case CPDFAnnotationType.Highlight:
- if (pdfHighlightUI == null)
- {
- pdfHighlightUI = new CPDFMarkupUI();
- }
- annotationPanel = pdfHighlightUI;
- (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
- break;
- case CPDFAnnotationType.Underline:
- if (pdfUnderlineUI == null)
- {
- pdfUnderlineUI = new CPDFMarkupUI();
- }
- annotationPanel = pdfUnderlineUI;
- (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
- break;
- case CPDFAnnotationType.Strikeout:
- if (pdfStrikeoutUI == null)
- {
- pdfStrikeoutUI = new CPDFMarkupUI();
- }
- annotationPanel = pdfStrikeoutUI;
- (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
- break;
- case CPDFAnnotationType.Squiggly:
- if (pdfSquigglyUI == null)
- {
- pdfSquigglyUI = new CPDFMarkupUI();
- }
- annotationPanel = pdfSquigglyUI;
- (annotationPanel as CPDFMarkupUI).InitWithAnnotationType(annotationType);
- break;
- case CPDFAnnotationType.Square:
- if (pdfSquareUI == null)
- {
- pdfSquareUI = new CPDFShapeUI();
- }
- annotationPanel = pdfSquareUI;
- (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
- break;
- case CPDFAnnotationType.Circle:
- if (pdfCircleUI == null)
- {
- pdfCircleUI = new CPDFShapeUI();
- }
- annotationPanel = pdfCircleUI;
- (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
- break;
- case CPDFAnnotationType.Arrow:
- if (pdfArrowUI == null)
- {
- pdfArrowUI = new CPDFShapeUI();
- }
- annotationPanel = pdfArrowUI;
- (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
- break;
- case CPDFAnnotationType.Line:
- if (pdfLineUI == null)
- {
- pdfLineUI = new CPDFShapeUI();
- }
- annotationPanel = pdfLineUI;
- (annotationPanel as CPDFShapeUI).InitWithAnnotationType(annotationType);
- break;
- case CPDFAnnotationType.Freehand:
- if (pdfFreehandUI == null)
- {
- pdfFreehandUI = new CPDFFreehandUI();
- pdfFreehandUI.EraseClickHandler -= PdfFreehandUI_EraseClickHandler;
- pdfFreehandUI.EraseChangeHandler -= PdfFreehandUI_EraseChangeHandler;
- pdfFreehandUI.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
- pdfFreehandUI.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
- }
- annotationPanel = pdfFreehandUI;
- break;
- case CPDFAnnotationType.FreeText:
- if (pdfFreeTextUI == null)
- {
- pdfFreeTextUI = new CPDFFreeTextUI();
- }
- annotationPanel = pdfFreeTextUI;
- break;
- case CPDFAnnotationType.Note:
- if (pdfNoteUI == null)
- {
- pdfNoteUI = new CPDFNoteUI();
- }
- annotationPanel = pdfNoteUI;
- break;
- case CPDFAnnotationType.Stamp:
- if (pdfStampUI == null)
- {
- pdfStampUI = new CPDFStampUI();
- }
- annotationPanel = pdfStampUI;
- break;
- case CPDFAnnotationType.Signature:
- if (pdfSignatureUI == null)
- {
- pdfSignatureUI = new CPDFSignatureUI();
- }
- annotationPanel = pdfSignatureUI;
- break;
- case CPDFAnnotationType.Link:
- if (pdfLinkUI == null)
- {
- pdfLinkUI = new CPDFLinkUI();
- }
- LinkParam linkAnnotArgs = new LinkParam();
- if (this.pdfViewerControl != null && pdfViewerControl.PDFViewTool != null && pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument() != null)
- {
- pdfViewerControl.SetToolType(ToolType.CreateAnnot);
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINK);
- pdfLinkUI.InitLinkAnnotArgs(linkAnnotArgs, pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument().PageCount);
- }
- annotationPanel = pdfLinkUI;
- break;
- case CPDFAnnotationType.Audio:
- SoundParam soundParam = new SoundParam();
- soundParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_SOUND;
- OpenFileDialog openAudioDialog = new OpenFileDialog();
- openAudioDialog.Filter = "Wave Files(*.wav)|*.wav|All Files(*.*;)|*.*;";
- if (openAudioDialog.ShowDialog() == true)
- {
- BitmapImage img = new BitmapImage(new Uri("pack://application:,,,/Compdfkit_Tools;component/Asset/Resource/SoundAnnot.png"));
- PngBitmapEncoder encoder = new PngBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(img));
- MemoryStream memoryStream = new MemoryStream();
- encoder.Save(memoryStream);
- soundParam.ImageStream = memoryStream;
- soundParam.SoundFilePath = openAudioDialog.FileName;
- pdfViewerControl.SetToolType(ToolType.CreateAnnot);
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_SOUND);
- pdfViewerControl.SetAnnotParam(soundParam);
- }
- else
- {
- pdfViewerControl.SetToolType(ToolType.Pan);
- ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
- }
- ClearPanel();
- break;
- case CPDFAnnotationType.Image:
- StampParam stampParam = new StampParam();
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
- if (openFileDialog.ShowDialog() == true)
- {
- try
- {
- using (FileStream stream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
- {
- PngBitmapEncoder encoder = new PngBitmapEncoder();
- encoder.Frames.Add(BitmapFrame.Create(stream, BitmapCreateOptions.DelayCreation, BitmapCacheOption.None));
- MemoryStream memoryStream = new MemoryStream();
- encoder.Save(memoryStream);
- stampParam.ImageStream = memoryStream;
- stampParam.Transparency = 255;
- stampParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
- stampParam.StampType = C_STAMP_TYPE.IMAGE_STAMP;
- BitmapFrame frame = null;
- if (encoder != null && encoder.Frames.Count > 0)
- {
- frame = encoder.Frames[0];
- }
- if (frame != null)
- {
- byte[] imageArray = new byte[frame.PixelWidth * frame.PixelHeight * 4];
- if (frame.Format != PixelFormats.Bgra32)
- {
- FormatConvertedBitmap covert = new FormatConvertedBitmap(
- frame,
- PixelFormats.Bgra32,
- frame.Palette,
- 0);
- covert.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
- }
- else
- {
- frame.CopyPixels(imageArray, frame.PixelWidth * 4, 0);
- }
- pdfViewerControl.SetStampMouseImage(imageArray, frame.PixelWidth, frame.PixelHeight);
- }
- pdfViewerControl.SetToolType(ToolType.CreateAnnot);
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_STAMP);
- pdfViewerControl.SetIsVisibleCustomMouse(true);
- pdfViewerControl.SetIsShowStampMouse(true);
- pdfViewerControl.SetAnnotParam(stampParam);
- }
- }
- catch
- {
- }
- }
- else
- {
- pdfViewerControl.SetToolType(ToolType.Pan);
- ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
- }
- ClearPanel();
- break;
- default:
- break;
- }
- }
- private void PdfFreehandUI_EraseChangeHandler(object sender, double e)
- {
- if (pdfViewerControl != null)
- {
- pdfViewerControl.PDFViewTool.SetEraseZoom(e);
- }
- }
- private void PdfFreehandUI_EraseClickHandler(object sender, bool e)
- {
- if (e)
- {
- //pdfViewerControl.PDFToolManager.ClearSelect();
- pdfViewerControl.PDFViewTool.SetViewerModel(MouseModes.CustomizeTool);
- }
- else
- {
- pdfViewerControl.SetToolType(ToolType.CreateAnnot);
- pdfViewerControl.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_INK);
- }
- //if (pdfViewerControl != null)
- //{
- // CPDFFreehandUI freehandUI = sender as CPDFFreehandUI;
- // if (e)
- // {
- // annotArgs = pdfViewerControl.ToolManager.CurrentAnnotArgs;
- // eraseArgs = new EraseArgs();
- // eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
- // eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
- // if (freehandUI != null)
- // {
- // eraseArgs.Thickness = freehandUI.GetEraseThickness();
- // }
- // else
- // {
- // eraseArgs.Thickness = 1;
- // }
- // disableClean = true;
- // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
- // pdfViewerControl.SetToolParam(eraseArgs);
- // disableClean = false;
- // EmptyMessage.Visibility = Visibility.Collapsed;
- // }
- // else
- // {
- // pdfViewerControl.PDFToolManager.SetToolType(ToolType.CreateAnnot);
- // FreehandAnnotArgs freehandAnnotArgs = annotArgs as FreehandAnnotArgs;
- // if (freehandAnnotArgs == null)
- // {
- // freehandAnnotArgs = new FreehandAnnotArgs();
- // freehandAnnotArgs.InkColor = Colors.Red;
- // freehandAnnotArgs.Transparency = 1;
- // freehandAnnotArgs.LineWidth = 1;
- // annotArgs = freehandAnnotArgs;
- // }
- // if (freehandUI != null)
- // {
- // freehandUI.PropertyChanged -= CPDFAnnotationControl_PropertyChanged;
- // Dictionary<AnnotAttrib, object> attribDict = new Dictionary<AnnotAttrib, object>();
- // attribDict[AnnotAttrib.Color] = freehandAnnotArgs.InkColor;
- // attribDict[AnnotAttrib.Transparency] = freehandAnnotArgs.Transparency;
- // attribDict[AnnotAttrib.Thickness] = freehandAnnotArgs.LineWidth;
- // attribDict[AnnotAttrib.NoteText] = freehandAnnotArgs.Content;
- // AnnotAttribEvent annotEvent = AnnotAttribEvent.GetAnnotAttribEvent(freehandAnnotArgs, attribDict);
- // freehandUI.SetPresentAnnotAttrib(annotEvent);
- // freehandUI.PropertyChanged += CPDFAnnotationControl_PropertyChanged;
- // freehandUI.ClearAnnotAttribEvent();
- // }
- // pdfViewerControl.SetToolParam(freehandAnnotArgs);
- // }
- //}
- }
- public void CreatTempAnnotationPanel(BaseAnnot baseAnnot)
- {
- switch (baseAnnot.CurrentType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
- {
- tempAnnotationPanel = new CPDFMarkupUI();
- (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Highlight);
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
- {
- tempAnnotationPanel = new CPDFMarkupUI();
- (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Underline);
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
- {
- tempAnnotationPanel = new CPDFMarkupUI();
- (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Strikeout);
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
- {
- tempAnnotationPanel = new CPDFMarkupUI();
- (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationType.Squiggly);
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot as CPDFMarkupAnnotation, pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
- {
- tempAnnotationPanel = new CPDFShapeUI();
- (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Square);
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
- {
- tempAnnotationPanel = new CPDFShapeUI();
- (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Circle);
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- {
- tempAnnotationPanel = new CPDFShapeUI();
- (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationType.Line);
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
- {
- CPDFFreehandUI tempFreehandPanel = new CPDFFreehandUI();
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- tempFreehandPanel.SetPresentAnnotAttrib(annotParam, baseAnnot.GetAnnotData().Annot, pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
- tempFreehandPanel.EraseClickHandler -= PdfFreehandUI_EraseClickHandler;
- tempFreehandPanel.EraseChangeHandler -= PdfFreehandUI_EraseChangeHandler;
- tempFreehandPanel.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
- tempFreehandPanel.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
- tempAnnotationPanel = tempFreehandPanel;
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
- {
- tempAnnotationPanel = new CPDFFreeTextUI();
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFFreeTextUI).SetPresentAnnotAttrib(annotParam as FreeTextParam, baseAnnot.GetAnnotData().Annot as CPDFFreeTextAnnotation, pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
- {
- tempAnnotationPanel = new CPDFNoteUI();
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFNoteUI).SetPresentAnnotAttrib(annotParam as StickyNoteParam, baseAnnot.GetAnnotData().Annot as CPDFTextAnnotation, pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
- {
- tempAnnotationPanel = new CPDFTempStampUI();
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFTempStampUI).SetPresentAnnotAttrib(annotParam as StampParam, baseAnnot.GetAnnotData().Annot as CPDFStampAnnotation, pdfViewerControl.PDFToolManager.GetDocument(), pdfViewerControl);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
- {
- tempAnnotationPanel = new CPDFLinkUI();
- AnnotParam annotParam = ParamConverter.CPDFDataConverterToAnnotParam(
- pdfViewerControl.PDFViewTool.GetCPDFViewer().GetDocument(),
- baseAnnot.GetAnnotData().PageIndex,
- baseAnnot.GetAnnotData().Annot);
- (tempAnnotationPanel as CPDFLinkUI).SetPresentAnnotAttrib(annotParam as LinkParam, baseAnnot.GetAnnotData().Annot as CPDFLinkAnnotation, pdfViewerControl, pdfViewerControl.PDFToolManager.GetDocument().PageCount);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
- tempAnnotationPanel = null;
- break;
- default:
- break;
- }
- }
- public void LoadAnnotationPanel(CPDFAnnotationType annotationType)
- {
- this.pdfViewerControl.SetToolType(ToolType.Pan);
- currentAnnotationType = annotationType;
- annotationPanel = GetAnnotationPanel();
- InitAnnotationPanel(annotationType);
- ShowCurrentAnnotPanel();
- }
- private void ShowCurrentAnnotPanel()
- {
- if (annotationPanel != null)
- {
- if (annotationPanel is CPDFFreehandUI)
- {
- (annotationPanel as CPDFFreehandUI)?.SetEraseCheck(false);
- }
- SetAnnotationPanel(annotationPanel);
- ExpandPanel();
- ChangeAnnotationData();
- EmptyMessage.Visibility = Visibility.Collapsed;
- }
- else
- {
- EmptyMessage.Visibility = Visibility.Visible;
- SetAnnotationPanel(null);
- if (pdfViewerControl != null)
- {
- EmptyMessage.Visibility = Visibility.Collapsed;
- }
- }
- }
- private void ShowTempAnnotPanel()
- {
- BaseAnnot baseAnnot = pdfViewerControl.GetCacheHitTestAnnot();
- if (baseAnnot != null)
- {
- CreatTempAnnotationPanel(baseAnnot);
- SetAnnotationPanel(tempAnnotationPanel);
- ExpandPanel();
- if (tempAnnotationPanel != null)
- {
- EmptyMessage.Visibility = Visibility.Collapsed;
- }
- else
- {
- EmptyMessage.Visibility = Visibility.Visible;
- }
- }
- }
- private void PDFToolManager_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
- {
- SetAnnotEventData();
- }
- public void ClearPanel()
- {
- annotationPanel = null;
- SetAnnotationPanel(annotationPanel);
- EmptyMessage.Visibility = Visibility.Visible;
- }
- public void SetAnnotEventData()
- {
- if (pdfViewerControl.GetCacheHitTestAnnot()!= null)
- {
- if (pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot && isTempPanel)
- {
- ShowCurrentAnnotPanel();
- isTempPanel = false;
- }
- else
- {
- ShowTempAnnotPanel();
- isTempPanel = true;
- }
- }
- else
- {
- if (pdfViewerControl != null && pdfViewerControl.PDFToolManager.GetToolType() == ToolType.CreateAnnot)
- {
- ShowCurrentAnnotPanel();
- isTempPanel = false;
- }
- else if (annotationPanel is CPDFStampUI && currentAnnotationType == CPDFAnnotationType.Stamp)
- {
- ShowCurrentAnnotPanel();
- }
- else if (annotationPanel is CPDFSignatureUI && currentAnnotationType == CPDFAnnotationType.Signature)
- {
- ShowCurrentAnnotPanel();
- }
- else if (disableClean == false)
- {
- ClearPanel();
- }
- }
- }
- }
- }
|