1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318 |
- using Compdfkit_Tools.Data;
- using Compdfkit_Tools.PDFControlUI;
- using ComPDFKitViewer.AnnotEvent;
- using ComPDFKitViewer;
- using ComPDFKitViewer.PdfViewer;
- 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 CPDFViewer = ComPDFKitViewer.PdfViewer.CPDFViewer;
- using ComPDFKit.Tool;
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.Import;
- using ComPDFKitViewer.Helper;
- using ComPDFKitViewer.Annot;
- using System.Windows.Input;
- using System.Linq;
- namespace Compdfkit_Tools.PDFControl
- {
- public partial class CPDFAnnotationControl : UserControl
- {
- private bool isTempPanel = false;
- private CPDFAnnotationType currentAnnotationType = CPDFAnnotationType.Unknow;
- private CPDFViewer pdfViewer;
- 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 AnnotHandlerEventArgs annotArgs;
- private EraseArgs eraseArgs;
- private bool disableClean;
- public event EventHandler ClearAnnotationBar;
- #region Rebuild
- private CPDFViewerTool cPDFViewerTool;
- CPDFAnnotation cPDFAnnotation;
- bool openCreateAnnot = false;
- bool selectedAnnot = false;
- CPDFAnnotationData pdfAnnotationData = null;
- C_ANNOTATION_TYPE CreateAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_UNKOWN;
- public void LoadPDFViewToolHandler()
- {
- cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kViewer);
- cPDFViewerTool.MouseLeftButtonDownHandler += CPDFViewerTool_MouseLeftButtonDownHandler;
- cPDFViewerTool.MouseLeftButtonUpHandler += CPDFViewerTool_MouseLeftButtonUpHandler;
- cPDFViewerTool.MouseMoveHandler += CPDFViewerTool_MouseMoveHandler;
- cPDFViewerTool.SelectedDataChanging += CPDFViewerTool_SelectedDataChanging;
- cPDFViewerTool.SelectedDataChanged += CPDFViewerTool_SelectedDataChanged;
- }
- private void CPDFViewerTool_SelectedDataChanged(object sender, ComPDFKit.Tool.DrawRect.SelectedRectData e)
- {
- if (e.annotData.AnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- CPDFLineAnnotation annotLine = (e.annotData.Annot as CPDFLineAnnotation);
- //annotLine.SetLinePoints(startPoint, endPoint);
- //annotLine.UpdateAp();
- }
- else
- {
- Rect rect1 = new Rect(
- (e.Square.Left - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom,
- (e.Square.Top - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom,
- e.Square.Width / e.annotData.CurrentZoom,
- e.Square.Height / e.annotData.CurrentZoom
- );
- Rect rect = DpiHelper.StandardRectToPDFRect(rect1);
- CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
- e.annotData.Annot.SetRect(cRect);
- }
- cPDFViewerTool.GetCPDFViewer().UpDataRenderFrame();
- }
- private void CPDFViewerTool_SelectedDataChanging(object sender, ComPDFKit.Tool.DrawRect.SelectedRectData e)
- {
- }
- private void CPDFViewerTool_MouseMoveHandler(object sender, MouseHitTeseType e)
- {
- if (e == ComPDFKit.Tool.MouseHitTeseType.kSelectRect)
- {
- if (selectedAnnot)
- {
- cPDFViewerTool.DrawMoveSelectedRect();
- }
- }
- else
- {
- if (!openCreateAnnot)
- {
- if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
- {
- cPDFViewerTool.SetAnnotIsProportionalScaling(true);
- }
- else
- {
- cPDFViewerTool.SetAnnotIsProportionalScaling(false);
- }
- cPDFViewerTool.MoveDrawAnnot();
- }
- }
- }
- private void CPDFViewerTool_MouseLeftButtonUpHandler(object sender, MouseHitTeseType e)
- {
- if (e == ComPDFKit.Tool.MouseHitTeseType.kSelectRect)
- {
- if (selectedAnnot)
- {
- cPDFViewerTool.DrawEndSelectedRect();
- }
- }
- else
- {
- if (!openCreateAnnot)
- {
- Point StartPoint = cPDFViewerTool.GetStartPoint();
- Point EndPoint = cPDFViewerTool.GetEndPoint();
- List<Point> points = cPDFViewerTool.GetInkDrawPoints();
- Rect rect = cPDFViewerTool.EndDrawAnnot();
- if (cPDFAnnotation != null)
- {
- if (cPDFAnnotation.Type == C_ANNOTATION_TYPE.C_ANNOTATION_INK)
- {
- List<List<CPoint>> inkPathList = new List<List<CPoint>>();
- List<CPoint> inkPath = new List<CPoint>();
- float Left = -1;
- float Right = -1;
- float Top = -1;
- float Bottom = -1;
- foreach (Point inkNode in points)
- {
- inkPath.Add(new CPoint((float)DpiHelper.StandardNumToPDFNum(inkNode.X), (float)DpiHelper.StandardNumToPDFNum(inkNode.Y)));
- if (Left == -1)
- {
- Left = inkPath.Min(x => x.x);
- }
- else
- {
- Left = Math.Min(Left, inkPath.Min(x => x.x));
- }
- if (Right == -1)
- {
- Right = inkPath.Max(x => x.x);
- }
- else
- {
- Right = Math.Max(Right, inkPath.Max(x => x.x));
- }
- if (Top == -1)
- {
- Top = inkPath.Min(x => x.y);
- }
- else
- {
- Top = Math.Min(Top, inkPath.Min(x => x.y));
- }
- if (Bottom == -1)
- {
- Bottom = inkPath.Max(x => x.y);
- }
- else
- {
- Bottom = Math.Max(Bottom, inkPath.Max(x => x.y));
- }
- }
- inkPathList.Add(inkPath);
- (cPDFAnnotation as CPDFInkAnnotation).SetInkPath(inkPathList);
- (cPDFAnnotation as CPDFInkAnnotation).SetInkRect(new CRect(Left, Bottom, Right, Top));
- cPDFAnnotation.UpdateAp();
- cPDFViewerTool.ClearDrawAnnot();
- cPDFViewerTool.GetCPDFViewer().UpDataRenderFrame();
- cPDFAnnotation = null;
- return;
- }
- if (rect.Width <= 0 && rect.Width <= 0)
- {
- cPDFAnnotation.RemoveAnnot();
- cPDFAnnotation = null;
- return;
- }
- if (cPDFAnnotation.Type== C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- (cPDFAnnotation as CPDFLineAnnotation).SetLinePoints(new CPoint((float)StartPoint.X, (float)StartPoint.Y), new CPoint((float)EndPoint.X, (float)EndPoint.Y));
- }
- CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
- cPDFAnnotation.SetRect(cRect);
- cPDFAnnotation.UpdateAp();
- cPDFViewerTool.ClearDrawAnnot();
- cPDFViewerTool.GetCPDFViewer().UpDataRenderFrame();
- }
- }
- }
- }
- private void CPDFViewerTool_MouseLeftButtonDownHandler(object sender, MouseHitTeseType e)
- {
- if (e == ComPDFKit.Tool.MouseHitTeseType.kUnknown)
- {
- if (!openCreateAnnot)
- {
- if (CreateAnnotType!= C_ANNOTATION_TYPE.C_ANNOTATION_UNKOWN)
- {
- cPDFAnnotation = cPDFViewerTool.StartDrawAnnot(CreateAnnotType);
- if (cPDFAnnotation != null)
- {
- cPDFViewerTool.CleanSelectedRect();
- selectedAnnot = false;
- SetAnnotAttributes(cPDFAnnotation, pdfAnnotationData);
- return;
- }
- }
- }
- else
- {
- cPDFViewerTool.CleanSelectedRect();
- selectedAnnot = false;
- }
- }
- else
- {
- cPDFViewerTool.DrawStartSelectedSaRect();
- selectedAnnot = true;
- }
- }
- public void SetAnnotAttributes(CPDFAnnotation cPDFAnnotation, CPDFAnnotationData data)
- {
- if (pdfAnnotationData==null)
- {
- return;
- }
- switch (cPDFAnnotation.Type)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_UNKOWN:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- if (data.AnnotationType == CPDFAnnotationType.Line|| data.AnnotationType == CPDFAnnotationType.Arrow)
- {
- CPDFLineShapeData lineData = data as CPDFLineShapeData;
- CPDFLineAnnotation lineAnnot = cPDFAnnotation as CPDFLineAnnotation;
- lineAnnot.SetLineWidth(lineData.Thickness);
- byte[] lineColor = { lineData.BorderColor.R, lineData.BorderColor.G, lineData.BorderColor.B };
- lineAnnot.SetLineColor(lineColor);
- byte transparency = (byte)Math.Round(lineData.Opacity * 255);
- lineAnnot.SetTransparency(transparency);
- if (lineData.DashStyle != null)
- {
- if (lineData.DashStyle.Dashes.Count == 0)
- {
- lineAnnot.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
- }
- else
- {
- List<float> floatArray = new List<float>();
- foreach (var num in lineData.DashStyle.Dashes)
- {
- floatArray.Add((float)num);
- }
- lineAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, floatArray.ToArray());
- }
- }
- lineAnnot.SetLineType(lineData.LineType.HeadLineType, lineData.LineType.TailLineType);
- lineAnnot.SetAuthor(lineData.Author);
- lineAnnot.SetContent(lineData.Note);
- lineAnnot.UpdateAp();
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
- if (data.AnnotationType == CPDFAnnotationType.Square)
- {
- CPDFShapeData squareData = data as CPDFShapeData;
- CPDFSquareAnnotation squareAnnot = cPDFAnnotation as CPDFSquareAnnotation;
- squareAnnot.SetLineWidth(squareData.Thickness);
- byte[] bgColor = { squareData.FillColor.R, squareData.FillColor.G, squareData.FillColor.B };
- if (squareData.FillColor != Colors.Transparent)
- {
- squareAnnot.SetBgColor(bgColor);
- }
- else
- {
- squareAnnot.ClearBgColor();
- }
- byte[] lineColor = { squareData.BorderColor.R, squareData.BorderColor.G, squareData.BorderColor.B };
- squareAnnot.SetLineColor(lineColor);
- byte transparency = (byte)Math.Round(squareData.Opacity * 255);
- squareAnnot.SetTransparency(transparency);
- if (squareData.DashStyle != null)
- {
- if (squareData.DashStyle.Dashes.Count == 0)
- {
- squareAnnot.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
- }
- else
- {
- List<float> floatArray = new List<float>();
- foreach (var num in squareData.DashStyle.Dashes)
- {
- floatArray.Add((float)num);
- }
- squareAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, floatArray.ToArray());
- }
- }
- squareAnnot.SetAuthor(squareData.Author);
- squareAnnot.SetContent(squareData.Note);
- squareAnnot.UpdateAp();
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
- if (data.AnnotationType == CPDFAnnotationType.Circle)
- {
- CPDFShapeData circleData = data as CPDFShapeData;
- CPDFCircleAnnotation circleAnnot = cPDFAnnotation as CPDFCircleAnnotation;
- circleAnnot.SetLineWidth(circleData.Thickness);
- byte[] bgColor = { circleData.FillColor.R, circleData.FillColor.G, circleData.FillColor.B };
- if (circleData.FillColor!= Colors.Transparent)
- {
- circleAnnot.SetBgColor(bgColor);
- }
- else
- {
- circleAnnot.ClearBgColor();
- }
- byte[] lineColor = { circleData.BorderColor.R, circleData.BorderColor.G, circleData.BorderColor.B };
- circleAnnot.SetLineColor(lineColor);
- byte transparency = (byte)Math.Round(circleData.Opacity * 255);
- circleAnnot.SetTransparency(transparency);
- if (circleData.DashStyle != null)
- {
- if (circleData.DashStyle.Dashes.Count == 0)
- {
- circleAnnot.SetBorderStyle(C_BORDER_STYLE.BS_SOLID, new float[0]);
- }
- else
- {
- List<float> floatArray = new List<float>();
- foreach (var num in circleData.DashStyle.Dashes)
- {
- floatArray.Add((float)num);
- }
- circleAnnot.SetBorderStyle(C_BORDER_STYLE.BS_DASHDED, floatArray.ToArray());
- }
- }
- circleAnnot.SetAuthor(circleData.Author);
- circleAnnot.SetContent(circleData.Note);
- circleAnnot.UpdateAp();
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_CARET:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
- if (data.AnnotationType == CPDFAnnotationType.Freehand)
- {
- CPDFFreehandData inkData = data as CPDFFreehandData;
- CPDFInkAnnotation inkAnnot = cPDFAnnotation as CPDFInkAnnotation;
- inkAnnot.SetThickness((float)inkData.Thickness);
- byte[] lineColor = { inkData.BorderColor.R, inkData.BorderColor.G, inkData.BorderColor.B };
- inkAnnot.SetInkColor(lineColor);
- byte transparency = (byte)Math.Round(inkData.Opacity * 255);
- inkAnnot.SetTransparency(transparency);
- inkAnnot.SetAuthor(inkData.Author);
- inkAnnot.SetContent(inkData.Note);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POPUP:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_FILEATTACHMENT:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SCREEN:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_PRINTERMARK:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_TRAPNET:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_WATERMARK:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_3D:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_INTERCHANGE:
- break;
- default:
- break;
- }
- }
- public void SetCreateAnnot(CPDFAnnotationData data)
- {
- CPDFAnnotationType annotationType = data.AnnotationType;
- pdfAnnotationData = data;
- switch (annotationType)
- {
- case CPDFAnnotationType.Unknow:
- cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kViewer);
- return;
- case CPDFAnnotationType.Highlight:
- break;
- case CPDFAnnotationType.Underline:
- break;
- case CPDFAnnotationType.Strikeout:
- break;
- case CPDFAnnotationType.Squiggly:
- break;
- case CPDFAnnotationType.FreeText:
- break;
- case CPDFAnnotationType.Freehand:
- CreateAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
- cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kCreateAnnot);
- break;
- case CPDFAnnotationType.Note:
- break;
- case CPDFAnnotationType.Circle:
- CreateAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE;
- cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kCreateAnnot);
- break;
- case CPDFAnnotationType.Square:
- CreateAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE;
- cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kCreateAnnot);
- break;
- case CPDFAnnotationType.Arrow:
- case CPDFAnnotationType.Line:
- CreateAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_LINE;
- cPDFViewerTool.SetViewerModel(ComPDFKit.Tool.MouseModess.kCreateAnnot);
- break;
- case CPDFAnnotationType.Stamp:
- break;
- case CPDFAnnotationType.Signature:
- break;
- case CPDFAnnotationType.Link:
- break;
- case CPDFAnnotationType.Audio:
- break;
- case CPDFAnnotationType.Image:
- break;
- default:
- break;
- }
- }
- #endregion
- public CPDFAnnotationControl()
- {
- InitializeComponent();
- }
- public void SetPDFViewer(CPDFViewer pdfViewer, CPDFViewerTool tool)
- {
- cPDFViewerTool = tool;
- if (cPDFViewerTool != null)
- {
- LoadPDFViewToolHandler();
- }
- if (this.pdfViewer != null)
- {
- UnLoadPDFViewHandler();
- }
- this.pdfViewer = pdfViewer;
- LoadPDFViewHandler();
- }
- public void LoadPDFViewHandler()
- {
- if (this.pdfViewer != null)
- {
- this.pdfViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- this.pdfViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
- this.pdfViewer.AnnotEditHandler -= PdfViewer_AnnotEditHandler;
- this.pdfViewer.AnnotEditHandler += PdfViewer_AnnotEditHandler;
- }
- }
- private void PdfViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
- {
- if (e != null && e.Count > 0)
- {
- if (e[0].EditAction == ActionType.Del)
- {
- if (pdfViewer.MouseMode == MouseModes.AnnotCreate && pdfViewer.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)
- {
- pdfViewer.SetMouseMode(MouseModes.PanTool);
- }
- }
- }
- public void UnLoadPDFViewHandler()
- {
- if (this.pdfViewer != null)
- {
- this.pdfViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
- }
- }
- 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)
- {
- pdfViewer.SetMouseMode(MouseModes.PanTool);
- return;
- }
- SetCreateAnnot(pdfAnnotationData);
- CPDFAnnotationType annotationType = pdfAnnotationData.AnnotationType;
- AnnotHandlerEventArgs annotHandlerEventArgs = null;
- Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
- switch (annotationType)
- {
- case CPDFAnnotationType.Highlight:
- CPDFMarkupData highlightData = pdfAnnotationData as CPDFMarkupData;
- annotHandlerEventArgs = new TextHighlightAnnotArgs();
- (annotHandlerEventArgs as TextHighlightAnnotArgs).Color = highlightData.Color;
- (annotHandlerEventArgs as TextHighlightAnnotArgs).Transparency = highlightData.Opacity;
- (annotHandlerEventArgs as TextHighlightAnnotArgs).Content = highlightData.Note;
- (annotHandlerEventArgs as TextHighlightAnnotArgs).Author = highlightData.Author;
- (annotHandlerEventArgs as TextHighlightAnnotArgs).Locked = highlightData.IsLocked;
- break;
- case CPDFAnnotationType.Underline:
- CPDFMarkupData underlineData = pdfAnnotationData as CPDFMarkupData;
- annotHandlerEventArgs = new TextUnderlineAnnotArgs();
- (annotHandlerEventArgs as TextUnderlineAnnotArgs).Color = underlineData.Color;
- (annotHandlerEventArgs as TextUnderlineAnnotArgs).Transparency = underlineData.Opacity;
- (annotHandlerEventArgs as TextUnderlineAnnotArgs).Author = underlineData.Author;
- (annotHandlerEventArgs as TextUnderlineAnnotArgs).Content = underlineData.Note;
- (annotHandlerEventArgs as TextUnderlineAnnotArgs).Locked = underlineData.IsLocked;
- break;
- case CPDFAnnotationType.Strikeout:
- CPDFMarkupData strikeoutData = pdfAnnotationData as CPDFMarkupData;
- annotHandlerEventArgs = new TextStrikeoutAnnotArgs();
- (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Color = strikeoutData.Color;
- (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Transparency = strikeoutData.Opacity;
- (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Locked = strikeoutData.IsLocked;
- (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Author = strikeoutData.Author;
- (annotHandlerEventArgs as TextStrikeoutAnnotArgs).Content = strikeoutData.Note;
- break;
- case CPDFAnnotationType.Squiggly:
- CPDFMarkupData squigglyData = pdfAnnotationData as CPDFMarkupData;
- annotHandlerEventArgs = new TextSquigglyAnnotArgs();
- (annotHandlerEventArgs as TextSquigglyAnnotArgs).Color = squigglyData.Color;
- (annotHandlerEventArgs as TextSquigglyAnnotArgs).Transparency = squigglyData.Opacity;
- (annotHandlerEventArgs as TextSquigglyAnnotArgs).Locked = squigglyData.IsLocked;
- (annotHandlerEventArgs as TextSquigglyAnnotArgs).Author = squigglyData.Author;
- (annotHandlerEventArgs as TextSquigglyAnnotArgs).Content = squigglyData.Note;
- break;
- case CPDFAnnotationType.Square:
- CPDFShapeData squareData = pdfAnnotationData as CPDFShapeData;
- annotHandlerEventArgs = new SquareAnnotArgs();
- (annotHandlerEventArgs as SquareAnnotArgs).LineColor = squareData.BorderColor;
- (annotHandlerEventArgs as SquareAnnotArgs).BgColor = squareData.FillColor;
- (annotHandlerEventArgs as SquareAnnotArgs).LineWidth = squareData.Thickness;
- (annotHandlerEventArgs as SquareAnnotArgs).Transparency = squareData.Opacity;
- (annotHandlerEventArgs as SquareAnnotArgs).LineDash = squareData.DashStyle;
- (annotHandlerEventArgs as SquareAnnotArgs).Author = squareData.Author;
- (annotHandlerEventArgs as SquareAnnotArgs).Content = squareData.Note;
- break;
- case CPDFAnnotationType.Circle:
- CPDFShapeData cicleData = pdfAnnotationData as CPDFShapeData;
- annotHandlerEventArgs = new CircleAnnotArgs();
- (annotHandlerEventArgs as CircleAnnotArgs).LineColor = cicleData.BorderColor;
- (annotHandlerEventArgs as CircleAnnotArgs).BgColor = cicleData.FillColor;
- (annotHandlerEventArgs as CircleAnnotArgs).LineWidth = cicleData.Thickness;
- (annotHandlerEventArgs as CircleAnnotArgs).Transparency = cicleData.Opacity;
- (annotHandlerEventArgs as CircleAnnotArgs).LineDash = cicleData.DashStyle;
- (annotHandlerEventArgs as CircleAnnotArgs).Author = cicleData.Author;
- (annotHandlerEventArgs as CircleAnnotArgs).Content = cicleData.Note;
- break;
- case CPDFAnnotationType.Arrow:
- case CPDFAnnotationType.Line:
- CPDFLineShapeData lineData = pdfAnnotationData as CPDFLineShapeData;
- annotHandlerEventArgs = new LineAnnotArgs();
- (annotHandlerEventArgs as LineAnnotArgs).LineColor = lineData.BorderColor;
- (annotHandlerEventArgs as LineAnnotArgs).LineWidth = lineData.Thickness;
- (annotHandlerEventArgs as LineAnnotArgs).Transparency = lineData.Opacity;
- (annotHandlerEventArgs as LineAnnotArgs).LineDash = lineData.DashStyle;
- (annotHandlerEventArgs as LineAnnotArgs).HeadLineType = lineData.LineType.HeadLineType;
- (annotHandlerEventArgs as LineAnnotArgs).TailLineType = lineData.LineType.TailLineType;
- (annotHandlerEventArgs as LineAnnotArgs).Author = lineData.Author;
- (annotHandlerEventArgs as LineAnnotArgs).Content = lineData.Note;
- break;
- case CPDFAnnotationType.Note:
- CPDFNoteData noteData = pdfAnnotationData as CPDFNoteData;
- annotHandlerEventArgs = new StickyAnnotArgs();
- (annotHandlerEventArgs as StickyAnnotArgs).Color = noteData.BorderColor;
- (annotHandlerEventArgs as StickyAnnotArgs).StickyNote = noteData.Note;
- (annotHandlerEventArgs as StickyAnnotArgs).Transparency = 1;
- (annotHandlerEventArgs as StickyAnnotArgs).Author = noteData.Author;
- break;
- case CPDFAnnotationType.Freehand:
- CPDFFreehandData freehandData = pdfAnnotationData as CPDFFreehandData;
- annotHandlerEventArgs = new FreehandAnnotArgs();
- (annotHandlerEventArgs as FreehandAnnotArgs).InkColor = freehandData.BorderColor;
- (annotHandlerEventArgs as FreehandAnnotArgs).LineWidth = freehandData.Thickness;
- (annotHandlerEventArgs as FreehandAnnotArgs).Transparency = freehandData.Opacity;
- (annotHandlerEventArgs as FreehandAnnotArgs).Content = freehandData.Note;
- (annotHandlerEventArgs as FreehandAnnotArgs).Author = freehandData.Author;
- break;
- case CPDFAnnotationType.FreeText:
- CPDFFreeTextData freeTextData = pdfAnnotationData as CPDFFreeTextData;
- annotHandlerEventArgs = new FreeTextAnnotArgs();
- (annotHandlerEventArgs as FreeTextAnnotArgs).Transparency = freeTextData.Opacity;
- (annotHandlerEventArgs as FreeTextAnnotArgs).FontName = freeTextData.FontFamily.ToString();
- (annotHandlerEventArgs as FreeTextAnnotArgs).FontColor = freeTextData.BorderColor;
- (annotHandlerEventArgs as FreeTextAnnotArgs).IsBold = freeTextData.IsBold;
- (annotHandlerEventArgs as FreeTextAnnotArgs).IsItalic = freeTextData.IsItalic;
- (annotHandlerEventArgs as FreeTextAnnotArgs).FontSize = freeTextData.FontSize;
- (annotHandlerEventArgs as FreeTextAnnotArgs).Align = freeTextData.TextAlignment;
- (annotHandlerEventArgs as FreeTextAnnotArgs).Content = freeTextData.Note;
- (annotHandlerEventArgs as FreeTextAnnotArgs).Author = freeTextData.Author;
- break;
- case CPDFAnnotationType.Stamp:
- annotHandlerEventArgs = new StampAnnotArgs();
- StampAnnotArgs stampAnnot = annotHandlerEventArgs as StampAnnotArgs;
- CPDFStampData stampData = pdfAnnotationData as CPDFStampData;
- SetStamp(ref stampAnnot, stampData);
- break;
- case CPDFAnnotationType.Signature:
- annotHandlerEventArgs = new StampAnnotArgs();
- StampAnnotArgs SignatureAnnot = annotHandlerEventArgs as StampAnnotArgs;
- CPDFSignatureData SignatureData = pdfAnnotationData as CPDFSignatureData;
- SetSignature(ref SignatureAnnot, SignatureData);
- break;
- case CPDFAnnotationType.Link:
- if (annotHandlerEventArgs != null)
- {
- pdfViewer.SetToolParam(annotHandlerEventArgs);
- }
- break;
- case CPDFAnnotationType.Unknow:
- pdfViewer.SetMouseMode(MouseModes.PanTool);
- return;
- default:
- break;
- }
- this.pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
- pdfViewer.SetToolParam(annotHandlerEventArgs);
- }
- public void SetSignature(ref StampAnnotArgs Args, CPDFSignatureData stamp)
- {
- switch (stamp.Type)
- {
- case SignatureType.TextType:
- case SignatureType.ImageType:
- {
- Args.Opacity = 1;
- Args.Type = StampType.IMAGE_STAMP;
- Args.ImagePath = stamp.SourcePath;
- }
- break;
- case SignatureType.Drawing:
- {
- Args.SetInkData(GetPoints(stamp.DrawingPath), stamp.inkThickness, stamp.inkColor);
- }
- 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 StampAnnotArgs Args, CPDFStampData stamp)
- {
- Args.StampText = stamp.StampText;
- Args.Author = stamp.Author;
- Args.Opacity = stamp.Opacity;
- if (stamp.Type == StampType.IMAGE_STAMP)
- {
- Args.ImageWidth = stamp.MaxWidth;
- Args.ImageHeight = stamp.MaxHeight;
- }
- else
- {
- Args.MaxWidth = stamp.MaxWidth;
- Args.MaxHeight = stamp.MaxHeight;
- }
- Args.StampTextDate = stamp.StampTextDate;
- Args.TextColor = stamp.TextColor;
- Args.TextSharp = stamp.TextSharp;
- if (!string.IsNullOrEmpty(stamp.SourcePath))
- {
- BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
- Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
- image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
- Args.ImageHeight = image.PixelHeight;
- Args.ImageWidth = image.PixelWidth;
- }
- else
- {
- try
- {
- Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
- stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
- Args.ImageHeight = stamp.ImageSource.PixelHeight;
- Args.ImageWidth = stamp.ImageSource.PixelWidth;
- }
- catch
- {
- var i = pdfStampUI.CustomStampList.IndexOf(stamp);
- Settings.Default.CustomStampList.RemoveAt(i);
- Settings.Default.Save();
- pdfStampUI.LoadSettings();
- return;
- }
- }
- Args.Type = stamp.Type;
- }
- public void AnnotationCancel()
- {
- this.pdfViewer.SetMouseMode(MouseModes.PanTool);
- ClearPanel();
- }
- private void CPDFAnnotationControl_PropertyChanged(object sender, CPDFAnnotationData e)
- {
- SetAnnotationProperty(e);
- if (pdfViewer != null && pdfViewer.MouseMode == MouseModes.AnnotCreate && pdfViewer.ToolManager.CurrentAnnotArgs is FreehandAnnotArgs)
- {
- FreehandAnnotArgs freehandArgs = pdfViewer.ToolManager.CurrentAnnotArgs as FreehandAnnotArgs;
- CPDFFreehandData freehandData = e as CPDFFreehandData;
- if (freehandData != null)
- {
- freehandArgs.InkColor = freehandData.BorderColor;
- freehandArgs.LineWidth = freehandData.Thickness;
- freehandArgs.Transparency = freehandData.Opacity;
- freehandArgs.Content = freehandData.Note;
- freehandArgs.Author = freehandData.Author;
- }
- }
- }
- 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;
- }
- 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();
- }
- LinkAnnotArgs linkAnnotArgs = new LinkAnnotArgs();
- if (this.pdfViewer != null && this.pdfViewer.Document != null)
- {
- this.pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
- pdfViewer.SetToolParam(linkAnnotArgs);
- pdfLinkUI.InitLinkAnnotArgs(linkAnnotArgs, pdfViewer.Document.PageCount);
- }
- annotationPanel = pdfLinkUI;
- break;
- case CPDFAnnotationType.Audio:
- SoundAnnotArgs soundArgs = new SoundAnnotArgs();
- OpenFileDialog openAudioDialog = new OpenFileDialog();
- openAudioDialog.Filter = "Wave Files(*.wav)|*.wav|All Files(*.*;)|*.*;";
- if (openAudioDialog.ShowDialog() == true)
- {
- soundArgs.SoundFilePath = openAudioDialog.FileName;
- this.pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
- pdfViewer.SetToolParam(soundArgs);
- }
- else
- {
- this.pdfViewer.SetMouseMode(MouseModes.PanTool);
- ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
- }
- ClearPanel();
- break;
- case CPDFAnnotationType.Image:
- StampAnnotArgs stampArgs = new StampAnnotArgs();
- stampArgs.Opacity = 1;
- stampArgs.Type = StampType.IMAGE_STAMP;
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
- if (openFileDialog.ShowDialog() == true)
- {
- stampArgs.ImagePath = openFileDialog.FileName;
- this.pdfViewer?.SetMouseMode(MouseModes.AnnotCreate);
- this.pdfViewer?.SetToolParam(stampArgs);
- }
- else
- {
- this.pdfViewer.SetMouseMode(MouseModes.PanTool);
- }
- ClearAnnotationBar?.Invoke(this, EventArgs.Empty);
- ClearPanel();
- break;
- default:
- break;
- }
- }
- private void PdfFreehandUI_EraseChangeHandler(object sender, double e)
- {
- if (pdfViewer != null && eraseArgs != null)
- {
- eraseArgs.Thickness = e;
- }
- }
- private void PdfFreehandUI_EraseClickHandler(object sender, bool e)
- {
- if (pdfViewer != null)
- {
- CPDFFreehandUI freehandUI = sender as CPDFFreehandUI;
- if (e)
- {
- annotArgs = pdfViewer.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;
- pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
- pdfViewer.SetToolParam(eraseArgs);
- disableClean = false;
- EmptyMessage.Visibility = Visibility.Collapsed;
- }
- else
- {
- pdfViewer.SetMouseMode(MouseModes.AnnotCreate);
- 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();
- }
- pdfViewer.SetToolParam(freehandAnnotArgs);
- }
- }
- }
- public void CreatTempAnnotationPanel(AnnotAttribEvent annotAttribEvent)
- {
- AnnotArgsType annotArgsType = annotAttribEvent.GetAnnotTypes();
- switch (annotArgsType)
- {
- case AnnotArgsType.AnnotHighlight:
- case AnnotArgsType.AnnotUnderline:
- case AnnotArgsType.AnnotStrikeout:
- case AnnotArgsType.AnnotSquiggly:
- tempAnnotationPanel = new CPDFMarkupUI();
- (tempAnnotationPanel as CPDFMarkupUI).InitWithAnnotationType(CPDFAnnotationDictionary.GetAnnotArgsTypeFromAnnotationType[annotArgsType]);
- (tempAnnotationPanel as CPDFMarkupUI).SetPresentAnnotAttrib(annotAttribEvent);
- break;
- case AnnotArgsType.AnnotSquare:
- case AnnotArgsType.AnnotCircle:
- case AnnotArgsType.AnnotLine:
- tempAnnotationPanel = new CPDFShapeUI();
- (tempAnnotationPanel as CPDFShapeUI).InitWithAnnotationType(CPDFAnnotationDictionary.GetAnnotArgsTypeFromAnnotationType[annotArgsType]);
- (tempAnnotationPanel as CPDFShapeUI).SetPresentAnnotAttrib(annotAttribEvent);
- break;
- case AnnotArgsType.AnnotFreehand:
- CPDFFreehandUI tempFreehandPanel = new CPDFFreehandUI();
- tempFreehandPanel.SetPresentAnnotAttrib(annotAttribEvent);
- tempFreehandPanel.EraseClickHandler += PdfFreehandUI_EraseClickHandler;
- tempFreehandPanel.EraseChangeHandler += PdfFreehandUI_EraseChangeHandler;
- tempAnnotationPanel = tempFreehandPanel;
- break;
- case AnnotArgsType.AnnotFreeText:
- tempAnnotationPanel = new CPDFFreeTextUI();
- (tempAnnotationPanel as CPDFFreeTextUI).SetPresentAnnotAttrib(annotAttribEvent);
- break;
- case AnnotArgsType.AnnotSticky:
- tempAnnotationPanel = new CPDFNoteUI();
- (tempAnnotationPanel as CPDFNoteUI).SetPresentAnnotAttrib(annotAttribEvent);
- break;
- case AnnotArgsType.AnnotStamp:
- tempAnnotationPanel = new CPDFTempStampUI();
- (tempAnnotationPanel as CPDFTempStampUI).SetPresentAnnotAttrib(annotAttribEvent);
- break;
- case AnnotArgsType.AnnotLink:
- tempAnnotationPanel = new CPDFLinkUI();
- (tempAnnotationPanel as CPDFLinkUI).SetPresentAnnotAttrib(annotAttribEvent, pdfViewer.Document.PageCount);
- break;
- case AnnotArgsType.AnnotSound:
- tempAnnotationPanel = null;
- break;
- default:
- break;
- }
- }
- public void LoadAnnotationPanel(CPDFAnnotationType annotationType)
- {
- this.pdfViewer.SetMouseMode(MouseModes.PanTool);
- 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 (pdfViewer != null && pdfViewer.ToolManager.CurrentAnnotArgs is EraseArgs)
- {
- EmptyMessage.Visibility = Visibility.Collapsed;
- }
- }
- }
- private void ShowTempAnnotPanel(AnnotAttribEvent annotAttribEvent)
- {
- if (annotAttribEvent != null)
- {
- CreatTempAnnotationPanel(annotAttribEvent);
- SetAnnotationPanel(tempAnnotationPanel);
- ExpandPanel();
- if (tempAnnotationPanel != null)
- {
- EmptyMessage.Visibility = Visibility.Collapsed;
- }
- else
- {
- EmptyMessage.Visibility = Visibility.Visible;
- }
- }
- }
- private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
- {
- SetAnnotEventData(e);
- }
- public void ClearPanel()
- {
- annotationPanel = null;
- SetAnnotationPanel(annotationPanel);
- EmptyMessage.Visibility = Visibility.Visible;
- }
- public void SetAnnotEventData(AnnotAttribEvent newData)
- {
- if (newData != null)
- {
- if (newData.IsAnnotCreateReset && isTempPanel)
- {
- ShowCurrentAnnotPanel();
- isTempPanel = false;
- }
- else if (!newData.IsAnnotCreateReset)
- {
- AnnotArgsType annotArgsType = newData.GetAnnotTypes();
- ShowTempAnnotPanel(newData);
- isTempPanel = true;
- }
- }
- else
- {
- if (pdfViewer != null && pdfViewer.MouseMode == MouseModes.AnnotCreate)
- {
- 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();
- }
- }
- }
- }
- }
|