1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587 |
- using ComPDFKit.Import;
- using ComPDFKit.PDFAnnotation;
- using ComPDFKit.Tool.DrawTool;
- using ComPDFKitViewer.Widget;
- using ComPDFKitViewer.Helper;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Input;
- using ComPDFKit.Tool.UndoManger;
- using ComPDFKit.PDFAnnotation.Form;
- using ComPDFKitViewer.BaseObject;
- using ComPDFKit.Tool.SettingParam;
- using ComPDFKit.PDFDocument;
- using ComPDFKit.PDFPage;
- using ComPDFKit.Viewer.Helper;
- using ComPDFKit.PDFPage.Edit;
- using ComPDFKit.Tool.Help;
- using ComPDFKit.Measure;
- using System.Dynamic;
- using System.Globalization;
- using ComPDFKitViewer.Layer;
- using ComPDFKitViewer;
- using ComPDFKitViewer.Annot;
- using System.Windows.Annotations;
- using ComPDFKit.Viewer.Annot;
- using System.Windows.Controls;
- using ComPDFKit.PDFDocument.Action;
- namespace ComPDFKit.Tool
- {
- public class CPDFToolManager
- {
- private CPDFViewerTool viewerTool;
- public event EventHandler<MouseEventObject> MouseLeftButtonDownHandler;
- public event EventHandler<MouseEventObject> MouseLeftButtonUpHandler;
- public event EventHandler<MouseEventObject> MouseMoveHandler;
- public event EventHandler<MouseEventObject> MouseRightButtonDownHandler;
- public event EventHandler<SelectedAnnotData> AnnotDefaultEditedHandler;
- public event EventHandler<MultiSelectedData> MulitDefaultEditedHandler;
- /// <summary>
- /// Current tool type, pay attention to the use of if writing, reserve the subsequent or operation mode switch
- /// </summary>
- private ToolType currentToolType = ToolType.None;
- /// <summary>
- /// Identify whether it is a selected text state or a drag box state for content editing
- /// </summary>
- private bool editSelected = true;
- private bool clickEditSelected = false;
- /// <summary>
- /// Current creation annotation type
- /// </summary>
- private C_ANNOTATION_TYPE createAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE;
- /// <summary>
- /// Current creation Widget type
- /// </summary>
- private C_WIDGET_TYPE createWidgetType = C_WIDGET_TYPE.WIDGET_NONE;
- /// <summary>
- /// Current creation content edit type
- /// </summary>
- private CPDFEditType createContentEditType = CPDFEditType.None;
- /// <summary>
- /// Current creation data layer annotation object (effective after Down, invalid after Up, if you need to modify the creation attributes, you need to do this)
- /// </summary>
- private CPDFAnnotation cPDFAnnotation;
- /// <summary>
- /// Image path cache used for image creation (subject to possible adjustments later)
- /// </summary>
- private string createImagePath = string.Empty;
- private bool isActiveCropping = true;
- /// <summary>
- /// add TextEdit Cursor
- /// </summary>
- private Cursor addTextEditCursor = Cursors.IBeam;
- /// <summary>
- /// add ImageEdit Cursor
- /// </summary>
- private Cursor addImageEditCursor = Cursors.Arrow;
- public bool SaveEmptyStickyAnnot { get; set; } = true;
- public void SetActiveCropping(bool isActiveCropping)
- {
- this.isActiveCropping = isActiveCropping;
- }
- public CPDFToolManager(CPDFViewerTool cPDFTool) : base()
- {
- viewerTool = cPDFTool;
- viewerTool.MouseLeftButtonDownHandler += ViewerTool_MouseLeftButtonDownHandler;
- viewerTool.MouseMoveHandler += ViewerTool_MouseMoveHandler;
- viewerTool.MouseLeftButtonUpHandler += ViewerTool_MouseLeftButtonUpHandler;
- viewerTool.MouseRightButtonDownHandler += ViewerTool_MouseRightButtonDownHandler;
- viewerTool.SelectedDataChanged += ViewerTool_SelectedDataChanged;
- viewerTool.SelectedDataChanging += ViewerTool_SelectedDataChanging;
- viewerTool.MultiDataChanged += ViewerTool_MulitDataChanged;
- viewerTool.MultiDataChanging += ViewerTool_MulitDataChanging;
- viewerTool.DeleteChanged += ViewerTool_DeleteChanged;
- viewerTool.AnnotEditDataChanged += ViewerTool_AnnotEditDataChanged;
- viewerTool.AnnotEditDataChanging += ViewerTool_AnnotEditDataChanging;
- }
- public void Remove()
- {
- viewerTool.MouseLeftButtonDownHandler -= ViewerTool_MouseLeftButtonDownHandler;
- viewerTool.MouseMoveHandler -= ViewerTool_MouseMoveHandler;
- viewerTool.MouseLeftButtonUpHandler -= ViewerTool_MouseLeftButtonUpHandler;
- viewerTool.SelectedDataChanged -= ViewerTool_SelectedDataChanged;
- viewerTool.SelectedDataChanging -= ViewerTool_SelectedDataChanging;
- viewerTool.MultiDataChanged -= ViewerTool_MulitDataChanged;
- viewerTool.MultiDataChanging -= ViewerTool_MulitDataChanging;
- viewerTool.DeleteChanged -= ViewerTool_DeleteChanged;
- viewerTool.AnnotEditDataChanged -= ViewerTool_AnnotEditDataChanged;
- viewerTool.AnnotEditDataChanging -= ViewerTool_AnnotEditDataChanging;
- viewerTool = null;
- }
- public BaseAnnot GetCacheHitTestAnnot()
- {
- return viewerTool.GetCacheHitTestAnnot();
- }
- public BaseWidget GetCacheHitTestWidget()
- {
- return viewerTool.GetCacheHitTestWidget();
- }
- public CPDFViewerTool GetCPDFViewerTool()
- {
- return viewerTool;
- }
- public CPDFDocument GetDocument()
- {
- return viewerTool.GetCPDFViewer().GetDocument();
- }
- public void SetCreateImagePath(string path)
- {
- createImagePath = path;
- }
- public ToolType GetToolType()
- {
- return currentToolType;
- }
- public bool SetCreateAnnotType(C_ANNOTATION_TYPE annotType)
- {
- viewerTool.SetIsHitTestLink(false);
- viewerTool.SetIsOnlyHitTestRedact(false);
- if (currentToolType != ToolType.CreateAnnot)
- {
- return false;
- }
- //MouseEventObject e= new MouseEventObject();
- //if (viewerTool.IsCanSave())
- //{
- // SaveCreateAnnotation(ref cPDFAnnotation, ref e);
- // viewerTool.PDFViewer.EnableZoom(true);
- // viewerTool.PDFViewer.CanHorizontallyScroll = true;
- // viewerTool.PDFViewer.CanVerticallyScroll = true;
- //}
- if (createAnnotType != annotType)
- {
- SaveCurrentAnnot();
- createAnnotType = annotType;
- }
- if (createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_LINK)
- {
- viewerTool.SetIsHitTestLink(true);
- }
- if (createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_REDACT)
- {
- viewerTool.SetIsOnlyHitTestRedact(true);
- }
- switch (annotType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
- case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
- TextSelectInfo textSelectInfo = viewerTool.GetTextSelectInfo();
- if (textSelectInfo.PageSelectPointList.Count > 0)
- {
- GroupHistory historyData = null;
- viewerTool.CreateAnnotForSelectText(textSelectInfo, createAnnotType, out historyData);
- viewerTool.RemoveSelectTextData();
- if (historyData != null && historyData.Histories.Count > 0)
- {
- List<object> dataList = new List<object>();
- if (historyData != null && historyData.Histories.Count > 0)
- {
- foreach (IHistory historyItem in historyData.Histories)
- {
- AnnotHistory checkHistory = historyItem as AnnotHistory;
- if (checkHistory == null || checkHistory.CurrentParam == null)
- {
- continue;
- }
- dynamic expandData = new ExpandoObject();
- expandData.AnnotIndex = checkHistory.CurrentParam.AnnotIndex;
- expandData.PageIndex = checkHistory.CurrentParam.PageIndex;
- expandData.AnnotParam = checkHistory.CurrentParam;
- dataList.Add(expandData);
- }
- }
- if (dataList.Count > 0)
- {
- MouseEventObject eventObject = new MouseEventObject();
- eventObject.annotType = createAnnotType;
- eventObject.IsCreate = true;
- eventObject.Data = dataList.Count > 1 ? dataList : dataList[0];
- MouseLeftButtonUpHandler?.Invoke(this, eventObject);
- }
- }
- }
- break;
- default:
- break;
- }
- return true;
- }
- public C_ANNOTATION_TYPE GetAnnotType()
- {
- return createAnnotType;
- }
- public bool SetCreateWidgetType(C_WIDGET_TYPE widgetType)
- {
- if (currentToolType != ToolType.WidgetEdit)
- {
- return false;
- }
- if (createWidgetType != widgetType)
- {
- SaveCurrentAnnot();
- createWidgetType = widgetType;
- }
- viewerTool.SetDrawWidgetType(createWidgetType);
- return true;
- }
- public C_WIDGET_TYPE GetCreateWidgetType()
- {
- return createWidgetType;
- }
- public bool SetCreateContentEditType(CPDFEditType editType)
- {
- createContentEditType = editType;
- return true;
- }
- public CPDFEditType GetCreateContentEditType()
- {
- return createContentEditType;
- }
- public void ClearSelect()
- {
- /// Clear some UI effects of other modules
- viewerTool.HideWidgetHitPop();
- viewerTool.CleanSelectedRect();
- viewerTool.CleanEditAnnot();
- viewerTool.CleanDrawSelectImage();
- viewerTool.ClearDrawWidget();
- viewerTool.CleanEditView();
- viewerTool.CleanCustomizeTool();
- viewerTool.GetCPDFViewer().SetCacheEditPage(false);
- }
- public void SetToolType(ToolType toolType)
- {
- if (currentToolType == toolType)
- {
- return;
- }
- viewerTool.RemovePopTextUI();
- /// Clear some UI effects of other modules
- viewerTool.HideWidgetHitPop();
- viewerTool.CleanSelectedRect();
- viewerTool.CleanEditAnnot();
- viewerTool.ClearDrawWidget();
- viewerTool.CleanEditView();
- viewerTool.CleanCustomizeTool();
- viewerTool.CleanDrawSelectImage();
- viewerTool.GetCPDFViewer().SetCacheEditPage(false);
- viewerTool.ClearDrawAnnot();
- viewerTool.CleanPageSelectedRect();
- viewerTool.SelectedAnnotForIndex(-1, -1);
- ToolType oldToolType = currentToolType;
- currentToolType = toolType;
- switch (toolType)
- {
- case ToolType.None:
- break;
- case ToolType.Viewer:
- viewerTool.SetToolType(ToolType.Viewer);
- break;
- case ToolType.CreateAnnot:
- viewerTool.SetToolType(ToolType.CreateAnnot);
- break;
- case ToolType.Pan:
- viewerTool.SetToolType(ToolType.Pan);
- break;
- case ToolType.WidgetEdit:
- viewerTool.SetToolType(ToolType.WidgetEdit);
- viewerTool.RemoveSelectTextData();
- break;
- case ToolType.ContentEdit:
- viewerTool.SetToolType(ToolType.ContentEdit);
- viewerTool.GetCPDFViewer().SetCacheEditPage(true);
- viewerTool.RemoveSelectTextData();
- break;
- case ToolType.SelectedPage:
- viewerTool.SetToolType(ToolType.SelectedPage);
- viewerTool.RemoveSelectTextData();
- break;
- case ToolType.Customize:
- viewerTool.SetToolType(ToolType.Customize);
- viewerTool.RemoveSelectTextData();
- break;
- default:
- break;
- }
- if (oldToolType == ToolType.ContentEdit)
- {
- viewerTool.GetCPDFViewer().GetDocument()?.ReleasePages();
- //Undo delete logic
- viewerTool.GetCPDFViewer().UndoManager.ClearHistory();
- // viewerTool.GetCPDFViewer().UndoManager.RemoveRedoHistoryForType(typeof(PDFEditHistory));
- //viewerTool.GetCPDFViewer().UndoManager.RemoveUndoHistoryForType(typeof(PDFEditHistory));
- viewerTool.GetCPDFViewer().UpdateVirtualNodes();
- viewerTool.GetCPDFViewer().UpdateRenderFrame();
- }
- }
- public CPDFEditArea GetSelectedEditAreaObject(ref int pageIndex)
- {
- EditAreaObject editAreaObject = viewerTool.GetEditAreaObjectForRect(viewerTool.GetLastSelectedRect());
- if (editAreaObject == null)
- {
- pageIndex = -1;
- }
- else
- {
- pageIndex = editAreaObject.PageIndex;
- }
- return editAreaObject?.cPDFEditArea;
- }
- /// <summary>
- /// Get the index of the multi choice comment list
- /// </summary>
- /// <param name="pageIndexs"></param>
- /// <returns></returns>
- public List<CPDFEditArea> GetSelectedEditAreaListObject(ref List<int> pageIndexs)
- {
- List<CPDFEditArea> editAreaObjectlist = new List<CPDFEditArea>();
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(viewerTool.PDFViewer.GetViewForTag(viewerTool.MultiSelectedRectViewTag));
- if (multiSelectedRect != null && multiSelectedRect.Children.Count > 0)
- {
- foreach (SelectedRect selectedRect in multiSelectedRect.Children)
- {
- EditAreaObject editAreaObject = viewerTool.GetEditAreaObjectListForRect(selectedRect);
- if (editAreaObject == null)
- {
- //pageIndexs.Add(-1);
- }
- else
- {
- if (!editAreaObjectlist.Contains(editAreaObject?.cPDFEditArea))
- {
- pageIndexs.Add(editAreaObject.PageIndex);
- editAreaObjectlist.Add(editAreaObject?.cPDFEditArea);
- }
- }
- }
- }
- return editAreaObjectlist;
- }
- public CPDFAnnotation GetCPDFAnnotation()
- {
- return cPDFAnnotation;
- }
- public void SetPageSelectText(List<TextSearchItem> pageTextList)
- {
- viewerTool.Dispatcher.Invoke(() =>
- {
- viewerTool.SetPageSelectText(pageTextList);
- viewerTool.ReDrawSelectText();
- });
- }
- public void HighLightSearchText(List<TextSearchItem> pageTextList)
- {
- if (pageTextList.Count < 0)
- {
- return;
- }
- viewerTool.Dispatcher.Invoke(() =>
- {
- viewerTool.HighLightSearchText(pageTextList);
- viewerTool.ReDrawSearchText();
- viewerTool.GetCPDFViewer().GoToPage(pageTextList[0].PageIndex, new Point(pageTextList[0].TextRect.X, pageTextList[0].TextRect.Y));
- });
- }
- private void ViewerTool_DeleteChanged(object sender, List<AnnotParam> e)
- {
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- AnnotDefaultEditedHandler?.Invoke(this, null);
- }
- private void ViewerTool_SelectedDataChanging(object sender, DrawTool.SelectedAnnotData e)
- {
- }
- private void ViewerTool_SelectedDataChanged(object sender, DrawTool.SelectedAnnotData e)
- {
- if (e.annotData == null)
- {
- return;
- }
- AnnotHistory annotHistory = ParamConverter.CreateHistory(e.annotData.Annot);
- if (annotHistory == null)
- {
- return;
- }
- AnnotParam previousParam;
- AnnotParam currentParam;
- switch (e.annotData.AnnotType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
- previousParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
- break;
- default:
- previousParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
- break;
- }
- /// Change operation
- if (e.annotData.AnnotType != C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- Rect rect1 = new Rect(
- (e.Square.Left - e.annotData.PaintOffset.X + (e.annotData.CropLeft * e.annotData.CurrentZoom)) / e.annotData.CurrentZoom,
- (e.Square.Top - e.annotData.PaintOffset.Y + (e.annotData.CropTop * e.annotData.CurrentZoom)) / 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);
- }
- switch (e.annotData.AnnotType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
- {
- currentParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
- (e.annotData.Annot as CPDFWidget).UpdateFormAp();
- break;
- }
- default:
- {
- currentParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
- if (e.annotData.AnnotType != C_ANNOTATION_TYPE.C_ANNOTATION_SOUND)
- {
- e.annotData.Annot.UpdateAp();
- if(e.annotData.Annot is CPDFTextAnnotation)
- {
- CommonHelper.UpdateStickyAP(e.annotData.Annot as CPDFTextAnnotation);
- }
- }
- break;
- }
- }
- annotHistory.PreviousParam = previousParam;
- annotHistory.PDFDoc = viewerTool.GetCPDFViewer().GetDocument();
- annotHistory.CurrentParam = currentParam;
- annotHistory.Action = HistoryAction.Update;
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
- viewerTool.GetCPDFViewer().UpdateRenderFrame();
- AnnotDefaultEditedHandler?.Invoke(this, e);
- }
- private void ViewerTool_MulitDataChanging(object sender, MultiSelectedData e)
- {
- }
- private void ViewerTool_MulitDataChanged(object sender, MultiSelectedData e)
- {
- switch (e.ObjectType)
- {
- case SelectedType.None:
- break;
- case SelectedType.Annot:
- break;
- case SelectedType.PDFEdit:
- SaveToMulitChanged(e);
- break;
- default:
- break;
- }
- MulitDefaultEditedHandler?.Invoke(this, e);
- }
- private void SaveToMulitChanged(MultiSelectedData e)
- {
- GroupHistory groupHistory = new GroupHistory();
- CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(e.PageIndex);
- CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
- //cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
- List<CPDFEditArea> cPDFEditAreas = cPDFEditPage.GetEditAreaList(false);
- float zoom = (float)viewerTool.PDFViewer.GetZoom();
- for (int i = 0; i < e.MultiObjectIndex.Count; i++)
- {
- if (e.MultiObjectIndex[i] < cPDFEditAreas.Count)
- {
- PDFEditHistory pDFEditHistory = new PDFEditHistory();
- pDFEditHistory.PageIndex = e.PageIndex;
- pDFEditHistory.EditPage = cPDFEditPage;
- CRect cRect = cPDFEditAreas[e.MultiObjectIndex[i]].GetFrame();
- if (cPDFEditAreas[e.MultiObjectIndex[i]].Type == CPDFEditType.EditImage)
- {
- cRect = (cPDFEditAreas[e.MultiObjectIndex[i]] as CPDFEditImageArea).GetClipRect();
- }
- Point point = DpiHelper.StandardPointToPDFPoint(e.MoveOffset);
- point.X = point.X / zoom;
- point.Y = point.Y / zoom;
- if (point.X != 0 && point.Y != 0 && e.ZoomX == 1 && e.ZoomY == 1)
- {
- cRect.left += (float)point.X;
- cRect.right += (float)point.X;
- cRect.top += (float)point.Y;
- cRect.bottom += (float)point.Y;
- }
- else
- {
- //Mobile scaling ratio logic
- if ((float)point.X == 0)
- {
- cRect.left += (float)point.X;
- cRect.right = cRect.left + (cRect.right - cRect.left) + (float)DpiHelper.StandardNumToPDFNum(e.ChangeX) / zoom;
- }
- else
- {
- cRect.left += (float)point.X;
- if (e.ZoomX == 1)
- {
- cRect.right += (float)point.X;
- }
- }
- if ((float)point.Y == 0)
- {
- cRect.top += (float)point.Y;
- cRect.bottom = cRect.top + (cRect.bottom - cRect.top) + (float)DpiHelper.StandardNumToPDFNum(e.ChangeY) / zoom;
- }
- else
- {
- cRect.top += (float)point.Y;
- if (e.ZoomY == 1)
- {
- cRect.bottom += (float)point.Y;
- }
- }
- }
- //Original Logic
- //cRect.left += (float)point.X;
- //cRect.right += (float)point.X;
- //cRect.top += (float)point.Y;
- //cRect.bottom += (float)point.Y;
- //cRect.right = cRect.right* e.ZoomX;
- //cRect.bottom = cRect.bottom * e.ZoomY;
- cPDFEditAreas[e.MultiObjectIndex[i]].SetFrame(cRect);
- groupHistory.Histories.Add(pDFEditHistory);
- }
- }
- //Add end edit
- cPDFEditPage.EndEdit();
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(groupHistory);
- viewerTool.GetCPDFViewer().UpdateRenderFrame();
- }
- private void ViewerTool_AnnotEditDataChanging(object sender, SelectedAnnotData e)
- {
- }
- private void ViewerTool_AnnotEditDataChanged(object sender, SelectedAnnotData e)
- {
- if (e.annotData == null)
- {
- return;
- }
- AnnotHistory annotHistory = ParamConverter.CreateHistory(e.annotData.Annot);
- if (annotHistory == null)
- {
- return;
- }
- AnnotParam previousParam;
- AnnotParam currentParam;
- switch (e.annotData.AnnotType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
- previousParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
- break;
- default:
- previousParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
- break;
- }
- switch (e.annotData.AnnotType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- if ((e.annotData.Annot as CPDFLineAnnotation).IsMeasured())
- {
- List<Point> cPoints = new List<Point>();
- for (int i = 0; i < e.Points.Count; i++)
- {
- Point cPoint = new Point((float)((e.Points[i].X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
- (float)((e.Points[i].Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom));
- cPoints.Add(cPoint);
- }
- Vector lineVector = cPoints[0] - cPoints[1];
- Point lineCenterPoint = new Point(
- (cPoints[0].X + cPoints[2].X) / 2,
- (cPoints[0].Y + cPoints[2].Y) / 2
- );
- Point crossCenterPoint = new Point(
- (cPoints[4].X + cPoints[5].X) / 2,
- (cPoints[4].Y + cPoints[5].Y) / 2
- );
- Rect unionRect = new Rect(cPoints[0], cPoints[2]);
- unionRect.Union(cPoints[1]);
- unionRect.Union(cPoints[3]);
- CPDFLineAnnotation annotLine = (e.annotData.Annot as CPDFLineAnnotation);
- annotLine.SetLinePoints(
- new CPoint(
- (float)(cPoints[0].X / 96D * 72D),
- (float)(cPoints[0].Y / 96D * 72D)),
- new CPoint(
- (float)(cPoints[2].X / 96D * 72D),
- (float)(cPoints[2].Y / 96D * 72D)
- ));
- annotLine.SetRect(new CRect(
- (float)(unionRect.Left / 96D * 72D),
- (float)(unionRect.Bottom / 96D * 72D),
- (float)(unionRect.Right / 96D * 72D),
- (float)(unionRect.Top / 96D * 72D)
- ));
- CPDFDistanceMeasure lineMeasure = annotLine.GetDistanceMeasure();
- double saveLength = lineVector.Length / 96D * 72D;
- if (lineCenterPoint.Y < crossCenterPoint.Y)
- {
- lineMeasure.SetLeadLength(-(float)saveLength);
- }
- if (lineCenterPoint.Y > crossCenterPoint.Y)
- {
- lineMeasure.SetLeadLength((float)saveLength);
- }
- if (lineCenterPoint.Y == crossCenterPoint.Y)
- {
- if (lineCenterPoint.X > crossCenterPoint.X)
- {
- lineMeasure.SetLeadLength(-(float)saveLength);
- }
- if (lineCenterPoint.X < crossCenterPoint.X)
- {
- lineMeasure.SetLeadLength((float)saveLength);
- }
- }
- lineMeasure.UpdateAnnotMeasure();
- annotLine.UpdateAp();
- if (annotLine.IsMeasured())
- {
- PostMeasureInfo(this, annotLine);
- }
- }
- else
- {
- Point startPoint = new Point(
- (float)((e.Points.First().X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
- (float)((e.Points.First().Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom)
- );
- Point endPoint = new Point(
- (float)((e.Points.Last().X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
- (float)((e.Points.Last().Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom)
- );
- CPoint cstartPoint = new CPoint((float)DpiHelper.StandardPointToPDFPoint(startPoint).X, (float)DpiHelper.StandardPointToPDFPoint(startPoint).Y);
- CPoint cendPoint = new CPoint((float)DpiHelper.StandardPointToPDFPoint(endPoint).X, (float)DpiHelper.StandardPointToPDFPoint(endPoint).Y);
- DpiHelper.StandardPointToPDFPoint(endPoint);
- CPDFLineAnnotation annotLine = (e.annotData.Annot as CPDFLineAnnotation);
- annotLine.SetLinePoints(cstartPoint, cendPoint);
- annotLine.UpdateAp();
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- {
- List<CPoint> cPoints = new List<CPoint>();
- for (int i = 0; i < e.Points.Count; i++)
- {
- Point cPoint = new Point((float)((e.Points[i].X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
- (float)((e.Points[i].Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom));
- cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(cPoint)));
- }
- CPDFPolygonAnnotation annotLine = (e.annotData.Annot as CPDFPolygonAnnotation);
- annotLine.SetPoints(cPoints);
- double left = cPoints.AsEnumerable().Select(x => x.x).Min();
- double right = cPoints.AsEnumerable().Select(x => x.x).Max();
- double top = cPoints.AsEnumerable().Select(x => x.y).Min();
- double bottom = cPoints.AsEnumerable().Select(x => x.y).Max();
- annotLine.SetRect(new CRect(
- (float)left,
- (float)bottom,
- (float)right,
- (float)top));
- annotLine.GetAreaMeasure().UpdateAnnotMeasure();
- annotLine.UpdateAp();
- if (annotLine.IsMeasured())
- {
- PostMeasureInfo(this, annotLine);
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- {
- List<CPoint> cPoints = new List<CPoint>();
- for (int i = 0; i < e.Points.Count; i++)
- {
- Point cPoint = new Point((float)((e.Points[i].X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
- (float)((e.Points[i].Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom));
- cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(cPoint)));
- }
- CPDFPolylineAnnotation annotLine = (e.annotData.Annot as CPDFPolylineAnnotation);
- annotLine.SetPoints(cPoints);
- double left = cPoints.AsEnumerable().Select(x => x.x).Min();
- double right = cPoints.AsEnumerable().Select(x => x.x).Max();
- double top = cPoints.AsEnumerable().Select(x => x.y).Min();
- double bottom = cPoints.AsEnumerable().Select(x => x.y).Max();
- annotLine.SetRect(new CRect(
- (float)left,
- (float)bottom,
- (float)right,
- (float)top));
- annotLine.GetPerimeterMeasure().UpdateAnnotMeasure();
- annotLine.UpdateAp();
- if (annotLine.IsMeasured())
- {
- PostMeasureInfo(this, annotLine);
- }
- }
- break;
- default:
- break;
- }
- switch (e.annotData.AnnotType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
- {
- currentParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
- (e.annotData.Annot as CPDFWidget).UpdateFormAp();
- break;
- }
- default:
- {
- currentParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
- if (e.annotData.AnnotType != C_ANNOTATION_TYPE.C_ANNOTATION_SOUND)
- {
- e.annotData.Annot.UpdateAp();
- }
- break;
- }
- }
- annotHistory.PreviousParam = previousParam;
- annotHistory.PDFDoc = viewerTool.GetCPDFViewer().GetDocument();
- annotHistory.CurrentParam = currentParam;
- annotHistory.Action = HistoryAction.Update;
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
- if (e.annotData.Annot.IsMeasured())
- {
- viewerTool.GetCPDFViewer().UpdateRenderFrame();
- }
- else
- {
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- }
- }
- private void ViewerTool_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
- {
- if (viewerTool == null)
- return;
- viewerTool.DrawEndSelectedMultiRect();
- viewerTool.DrawEndPageSelectedRect();
- if (currentToolType != ToolType.SelectedPage &&
- viewerTool.IsCanSave() &&
- cPDFAnnotation?.Type != C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT)
- {
- viewerTool.PDFViewer.EnableZoom(true);
- viewerTool.PDFViewer.CanHorizontallyScroll = true;
- viewerTool.PDFViewer.CanVerticallyScroll = true;
- }
- //To be optimized
- if (currentToolType != ToolType.WidgetEdit && currentToolType != ToolType.ContentEdit && viewerTool.IsText())
- {
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.IBeam;
- }
- else if (currentToolType == ToolType.ContentEdit)
- {
- if (createContentEditType == CPDFEditType.EditText)
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.IBeam;
- else
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
- }
- else
- {
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.Arrow;
- }
- if (currentToolType == ToolType.Customize)
- {
- viewerTool.CleanCustomizeTool();
- }
- if (e.hitTestType == MouseHitTestType.SelectRect)
- {
- List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
- {
- C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
- };
- if (list.Contains(e.annotType))
- {
- viewerTool.DrawEndEditAnnot();
- }
- else
- {
- viewerTool.DrawEndSelectedRect();
- }
- }
- switch (currentToolType)
- {
- case ToolType.CreateAnnot:
- CreateAnnotTypeMouseLeftUp(ref e);
- break;
- case ToolType.WidgetEdit:
- {
- if (cPDFAnnotation != null)
- {
- Rect rect = viewerTool.EndDrawWidget();
- CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
- cPDFAnnotation.SetRect(cRect);
- (cPDFAnnotation as CPDFWidget).UpdateFormAp();
- CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
- AnnotHistory annotHistory = ParamConverter.CreateHistory(cPDFAnnotation);
- if (annotHistory == null)
- {
- return;
- }
- WidgetParm annotParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), cPDFAnnotation) as WidgetParm;
- annotHistory.CurrentParam = annotParam;
- annotHistory.PDFDoc = cPDFDocument;
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- e.annotType = cPDFAnnotation.Type;
- e.IsCreate = true;
- dynamic expandData = new ExpandoObject();
- expandData.AnnotIndex = annotParam.AnnotIndex;
- expandData.PageIndex = annotParam.PageIndex;
- expandData.AnnotParam = annotParam;
- e.Data = expandData;
- }
- }
- break;
- case ToolType.ContentEdit:
- {
- if (viewerTool.GetLastSelectedRect() != null)
- {
- //Crop Save Processing
- if (!viewerTool.GetIsCropMode())
- {
- viewerTool.DrawEndTextEdit(viewerTool.GetLastSelectedRect());
- }
- else
- {
- if (isActiveCropping)
- {
- CropSelectRect();
- viewerTool.SetClipThickness();
- }
- //Originally saved cropping logic
- }
- editSelected = false;
- }
- else
- {
- if (createContentEditType == CPDFEditType.EditImage && viewerTool.PDFViewer.GetIsShowStampMouse())
- {
- Rect stampRect = viewerTool.PDFViewer.GetStampRect();
- Point mousePoint = new Point(
- stampRect.X - stampRect.Width / 2 * viewerTool.GetCPDFViewer().GetZoom(),
- stampRect.Y - stampRect.Height / 2 * viewerTool.GetCPDFViewer().GetZoom()
- );
- viewerTool.GetCPDFViewer().GetPointPageInfo(mousePoint, out int pageindex, out Rect paintRect, out Rect pageBound);
- if (pageindex >= 0)
- {
- Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((mousePoint.X - pageBound.X) / viewerTool.GetCPDFViewer().GetZoom(), (mousePoint.Y - pageBound.Y) / viewerTool.GetCPDFViewer().GetZoom(), stampRect.Width, stampRect.Height));
- CRect SaveRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
- CPDFPage docPage = viewerTool.PDFViewer.GetDocument().PageAtIndex(pageindex);
- CPDFEditPage EditPage = docPage.GetEditPage();
- CPDFEditImageArea cPDFEditImageArea = EditPage.CreateNewImageArea(SaveRect, createImagePath, string.Empty);
- if (cPDFEditImageArea == null)
- {
- byte[] imageData = null;
- int imageWidth = 0;
- int imageHeight = 0;
- PDFHelp.ImagePathToByte(createImagePath, ref imageData, ref imageWidth, ref imageHeight);
- if (imageData != null && imageWidth > 0 && imageHeight > 0)
- {
- cPDFEditImageArea = EditPage.CreateNewImageArea(SaveRect, imageData, imageWidth, imageHeight);
- }
- }
- viewerTool.PDFViewer.UpdateRenderFrame();
- PDFEditHistory editHistory = new PDFEditHistory();
- editHistory.EditPage = EditPage;
- editHistory.PageIndex = pageindex;
- EditPage.EndEdit();
- viewerTool.PDFViewer.UndoManager.AddHistory(editHistory);
- e.IsCreate = true;
- }
- }
- else if (createContentEditType == CPDFEditType.EditText)
- {
- if (viewerTool.CanAddTextEdit)
- {
- e.IsCreate = viewerTool.DrawEndTest();
- }
- }
- else
- {
- //Draw a box to select multiple boxes
- Rect rectFrameSelect = viewerTool.DrawEndFrameSelect();
- viewerTool.FrameSelectAddRect(rectFrameSelect);
- e.IsCreate = true;
- }
- }
- }
- break;
- case ToolType.Customize:
- viewerTool.DrawEndCustomizeTool();
- break;
- default:
- break;
- }
- viewerTool.DrawEndSelectText();
- MouseLeftButtonUpHandler?.Invoke(this, e);
- if (viewerTool.IsCanSave())
- {
- cPDFAnnotation = null;
- }
- }
- /// <summary>
- /// Create cropping logic
- /// </summary>
- public void CropSelectRect()
- {
- if (viewerTool.GetLastSelectedRect() != null)
- {
- if (viewerTool.GetIsCropMode())
- {
- viewerTool.DrawEndTextEdit(viewerTool.GetLastSelectedRect());
- }
- }
- viewerTool.DrawEndSelectText();
- if (viewerTool.IsCanSave())
- {
- cPDFAnnotation = null;
- }
- }
- private void SaveCurrentAnnot()
- {
- viewerTool.SetIsCanSave(true);
- MouseEventObject e = new MouseEventObject
- {
- mouseButtonEventArgs = null,
- hitTestType = MouseHitTestType.Unknown,
- annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE,
- IsCreate = false
- };
- switch (currentToolType)
- {
- case ToolType.CreateAnnot:
- CreateAnnotTypeMouseLeftUp(ref e);
- break;
- case ToolType.WidgetEdit:
- {
- if (cPDFAnnotation != null)
- {
- Rect rect = viewerTool.EndDrawWidget();
- CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
- cPDFAnnotation.SetRect(cRect);
- (cPDFAnnotation as CPDFWidget).UpdateFormAp();
- CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
- AnnotHistory annotHistory = ParamConverter.CreateHistory(cPDFAnnotation);
- if (annotHistory == null)
- {
- return;
- }
- WidgetParm annotParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), cPDFAnnotation) as WidgetParm;
- annotHistory.CurrentParam = annotParam;
- annotHistory.PDFDoc = cPDFDocument;
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- e.annotType = cPDFAnnotation.Type;
- e.IsCreate = true;
- dynamic expandData = new ExpandoObject();
- expandData.AnnotIndex = annotParam.AnnotIndex;
- expandData.PageIndex = annotParam.PageIndex;
- expandData.AnnotParam = annotParam;
- e.Data = expandData;
- }
- }
- break;
- case ToolType.Customize:
- viewerTool.DrawEndCustomizeTool();
- break;
- default:
- break;
- }
- if (viewerTool.IsCanSave())
- {
- cPDFAnnotation = null;
- }
- }
- #region MouseLeftButtonUpCreateAnnot
- private void CreateAnnotTypeMouseLeftUp(ref MouseEventObject e)
- {
- //Mersured
- if (cPDFAnnotation != null)
- {
- switch (cPDFAnnotation.Type)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- {
- if ((cPDFAnnotation as CPDFLineAnnotation).IsMeasured())
- {
- MeasureSetting measureSetting = viewerTool.GetMeasureSetting();
- if (viewerTool.GetMoveLength() > measureSetting.MoveDetectionLength)
- {
- viewerTool.SetIsCanSave(true);
- }
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- if ((cPDFAnnotation as CPDFPolygonAnnotation).IsMeasured())
- {
- DefaultSettingParam defSetting = viewerTool.GetDefaultSettingParam();
- if (defSetting.IsCreateSquarePolygonMeasure)
- {
- MeasureSetting measureSetting = viewerTool.GetMeasureSetting();
- if (viewerTool.GetMoveLength() > measureSetting.MoveDetectionLength)
- {
- viewerTool.SetIsCanSave(true);
- }
- }
- }
- break;
- default:
- break;
- }
- }
- if (viewerTool.IsCanSave())
- {
- SaveCreateAnnotation(ref cPDFAnnotation, ref e);
- viewerTool.PDFViewer.EnableZoom(true);
- viewerTool.PDFViewer.CanHorizontallyScroll = true;
- viewerTool.PDFViewer.CanVerticallyScroll = true;
- }
- }
- private bool SaveStampImageData(CPDFAnnotation annotation,CRect stampRect)
- {
- CPDFStampAnnotation stampAnnot=annotation as CPDFStampAnnotation;
- if(viewerTool==null || stampAnnot == null ||stampAnnot.GetStampType()!=C_STAMP_TYPE.IMAGE_STAMP)
- {
- return false;
- }
- try
- {
- DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
- StampParam stampParam = defaultSettingParam.StampParamDef;
- 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)
- {
- stampAnnot.SetRect(stampRect);
- stampAnnot.SetImageStamp(imageData,imageWidth,imageHeight,stampParam.Rotation);
- return true;
- }
- }
- catch (Exception ex)
- {
- }
- return false;
- }
- private void SaveCreateAnnotation(ref CPDFAnnotation annotation, ref MouseEventObject e)
- {
- if (annotation == null)
- {
- return;
- }
- Point StartPoint = viewerTool.GetStartPoint();
- Point EndPoint = viewerTool.GetEndPoint();
- List<Point> points = viewerTool.GetInkDrawPoints();
- List<Point> measurepoints = viewerTool.GetMeasureDrawPoints();
- annotation.SetCreationDate(PDFHelp.GetCurrentPdfTime());
- annotation.SetModifyDate(PDFHelp.GetCurrentPdfTime());
- Rect rect = viewerTool.EndDrawAnnot();
- if (annotation != null)
- {
- switch (annotation.Type)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
- SaveInkCreateAnnotation(ref annotation, points);
- e.IsCreate = true;
- e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
- e.Data = GetAnnotExpandObject(annotation);
- if (e.mouseButtonEventArgs != null)
- {
- MouseLeftButtonUpHandler?.Invoke(this, e);
- }
- annotation = null;
- return;
- case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
- e.IsCreate = true;
- e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT;
- e.Data = GetAnnotExpandObject(annotation);
- if (e.mouseButtonEventArgs != null)
- {
- MouseLeftButtonUpHandler?.Invoke(this, e);
- }
- return;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- {
- if ((annotation as CPDFLineAnnotation).IsMeasured())
- {
- if (measurepoints.Count > 1)
- {
- (annotation as CPDFLineAnnotation).SetLinePoints(new CPoint(
- (float)DpiHelper.StandardNumToPDFNum(measurepoints[0].X),
- (float)DpiHelper.StandardNumToPDFNum(measurepoints[0].Y)),
- new CPoint((float)DpiHelper.StandardNumToPDFNum(measurepoints[1].X),
- (float)DpiHelper.StandardNumToPDFNum(measurepoints[1].Y)));
- (annotation as CPDFLineAnnotation).GetDistanceMeasure().UpdateAnnotMeasure();
- PostMeasureInfo(this, annotation);
- }
- else
- {
- annotation.ReleaseAnnot();
- if (e.mouseButtonEventArgs != null)
- {
- MouseLeftButtonUpHandler?.Invoke(this, e);
- }
- annotation = null;
- return;
- }
- }
- else
- {
- if (EndPoint != new Point(-1, -1))
- {
- (annotation as CPDFLineAnnotation).SetLinePoints(new CPoint((float)StartPoint.X, (float)StartPoint.Y), new CPoint((float)EndPoint.X, (float)EndPoint.Y));
- }
- else
- {
- annotation.ReleaseAnnot();
- if (e.mouseButtonEventArgs != null)
- {
- MouseLeftButtonUpHandler?.Invoke(this, e);
- }
- annotation = null;
- return;
- }
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- {
- if (measurepoints.Count >= 3)
- {
- if ((annotation as CPDFPolygonAnnotation).IsMeasured())
- {
- List<CPoint> cPoints = new List<CPoint>();
- foreach (Point item in measurepoints)
- {
- cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
- }
- (annotation as CPDFPolygonAnnotation).SetPoints(cPoints);
- (annotation as CPDFPolygonAnnotation).GetAreaMeasure().UpdateAnnotMeasure();
- PostMeasureInfo(this, annotation);
- }
- }
- else
- {
- annotation.RemoveAnnot();
- annotation = null;
- viewerTool.ClearDrawAnnot();
- return;
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- {
- if(measurepoints.Count>=3)
- {
- if ((annotation as CPDFPolylineAnnotation).IsMeasured())
- {
- List<CPoint> cPoints = new List<CPoint>();
- foreach (Point item in measurepoints)
- {
- cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
- }
- (annotation as CPDFPolylineAnnotation).SetPoints(cPoints);
- (annotation as CPDFPolylineAnnotation).GetPerimeterMeasure().UpdateAnnotMeasure();
- PostMeasureInfo(this, annotation);
- }
- }
- else
- {
- annotation.RemoveAnnot();
- annotation = null;
- viewerTool.ClearDrawAnnot();
- return;
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
- if (rect.Width > 0 && rect.Height > 0)
- {
- List<CRect> coreRectList = new List<CRect>
- {
- new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top)
- };
- (annotation as CPDFRedactAnnotation).SetQuardRects(coreRectList);
- }
- break;
- default:
- break;
- }
- if (rect.Width <= 0 && rect.Height <= 0)
- {
- switch (createAnnotType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
- case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
- case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
- {
- annotation.RemoveAnnot();
- viewerTool.DrawEndSelectText();
- TextSelectInfo textSelectInfo = viewerTool.GetTextSelectInfo();
- if (textSelectInfo.PageSelectPointList.Count > 0)
- {
- viewerTool.DrawEndSelectText();
- viewerTool.RemoveSelectTextData();
- GroupHistory historyData = null;
- viewerTool.CreateAnnotForSelectText(textSelectInfo, createAnnotType, out historyData);
- List<object> dataList = new List<object>();
- if (historyData != null && historyData.Histories.Count > 0)
- {
- foreach (IHistory historyItem in historyData.Histories)
- {
- AnnotHistory checkHistory = historyItem as AnnotHistory;
- if (checkHistory == null || checkHistory.CurrentParam == null)
- {
- continue;
- }
- dynamic expandData = new ExpandoObject();
- expandData.AnnotIndex = checkHistory.CurrentParam.AnnotIndex;
- expandData.PageIndex = checkHistory.CurrentParam.PageIndex;
- expandData.AnnotParam = checkHistory.CurrentParam;
- dataList.Add(expandData);
- }
- }
- e.annotType = createAnnotType;
- e.IsCreate = true;
- if (dataList.Count > 0)
- {
- e.Data = dataList.Count > 1 ? dataList : dataList[0];
- }
- }
- if (createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_REDACT && textSelectInfo.PageSelectPointList.Count == 0)
- {
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
- {
- if (!viewerTool.PDFViewer.GetIsShowStampMouse())
- {
- break;
- }
- Rect stampRect = viewerTool.PDFViewer.GetStampRect();
- Point mousePoint = new Point(
- stampRect.X - stampRect.Width / 2 * viewerTool.GetCPDFViewer().GetZoom(),
- stampRect.Y - stampRect.Height / 2 * viewerTool.GetCPDFViewer().GetZoom()
- );
- viewerTool.GetCPDFViewer().GetPointPageInfo(mousePoint, out int pageindex, out Rect paintRect, out Rect pageBound);
- if (pageindex < 0)
- {
- annotation.RemoveAnnot();
- annotation = null;
- return;
- }
- else
- {
- if( annotation == null || annotation.IsValid()==false)
- {
- return;
- }
- CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageindex);
- Point cropPoint = new Point();
- if (viewerTool.GetRotateAnnot())
- {
- PageViewData viewData = viewerTool.PDFViewer.GetPageNodeByPageIndex(annotation.Page.PageIndex);
- cropPoint.X = viewData.CropLeft;
- cropPoint.Y = viewData.CropTop;
- }
- else
- {
- if (viewerTool.GetCPDFViewer().GetIsCrop())
- {
- CRect cropRect = cPDFPage.GetCropBounds();
- cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
- cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
- }
- }
-
- Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(
- (mousePoint.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
- (mousePoint.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
- stampRect.Width, stampRect.Height)
- );
- CRect cStampRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
- if (SaveStampImageData(annotation,cStampRect) == false)
- {
- annotation.SetRect(cStampRect);
- }
- annotation.UpdateAp();
- e.IsCreate = true;
- e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
- e.Data = GetAnnotExpandObject(annotation);
- StampAnnotHistory freeTextAnnotHistory = new StampAnnotHistory();
- AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
- annotParam.AnnotIndex = annotation.Page.GetAnnotCount() - 1;
- freeTextAnnotHistory.CurrentParam = (StampParam)annotParam;
- freeTextAnnotHistory.PDFDoc = viewerTool.GetCPDFViewer().GetDocument();
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(freeTextAnnotHistory);
- }
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
- {
- Point point = Mouse.GetPosition(viewerTool.PDFViewer);
- viewerTool.GetCPDFViewer().GetPointPageInfo(point, out int pageindex, out Rect paintRect, out Rect pageBound);
- if (pageindex < 0)
- {
- annotation.RemoveAnnot();
- annotation = null;
- return;
- }
- else
- {
- CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageindex);
- Point cropPoint = new Point();
- if (viewerTool.GetCPDFViewer().GetIsCrop())
- {
- CRect cropRect = cPDFPage.GetCropBounds();
- cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
- cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
- }
- CRect x = annotation.GetRect();
- Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(
- (point.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
- (point.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
- x.width(), x.height())
- );
- PDFRect.X = PDFRect.X - x.width() / 2;
- PDFRect.Y = PDFRect.Y - x.height() / 2;
- CRect cStampRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
- annotation.SetRect(cStampRect);
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- e.IsCreate = true;
- e.annotType = createAnnotType;
- e.Data = GetAnnotExpandObject(annotation);
- }
- }
- break;
- default:
- break;
- }
- //annotation.ReleaseAnnot();
- if (e.mouseButtonEventArgs != null)
- {
- MouseLeftButtonUpHandler?.Invoke(this, e);
- }
- annotation = null;
- return;
- }
- CRect cRect = new CRect(
- (float)rect.Left,
- (float)rect.Bottom,
- (float)rect.Right,
- (float)rect.Top);
- annotation.SetRect(cRect);
- SaveSharpAnnotBoundText(annotation);
- if (annotation.Type!=C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
- {
- annotation.UpdateAp();
- }
- else
- {
- CommonHelper.UpdateStickyAP(annotation as CPDFTextAnnotation);
- }
-
- AnnotHistory annotHistory = ParamConverter.CreateHistory(annotation);
- if (annotHistory == null)
- {
- return;
- }
- AnnotParam currentParam;
- switch (annotation.Type)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
- currentParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
- break;
- default:
- currentParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
- break;
- }
- annotHistory.CurrentParam = currentParam;
- annotHistory.Action = HistoryAction.Add;
- annotHistory.PDFDoc = viewerTool.PDFViewer.GetDocument();
- viewerTool.ClearDrawAnnot();
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
- if (annotation.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT && SaveEmptyStickyAnnot == false)
- {
- BaseLayer baseLayer1 = viewerTool.GetCPDFViewer().GetViewForTag(viewerTool.GetCPDFViewer().GetAnnotViewTag());
- int checkPageIndex = currentParam.PageIndex;
- int checkAnnotIndex = currentParam.AnnotIndex;
- BaseAnnot selectAnnot = (baseLayer1 as AnnotLayer).GetSelectedAnnot(ref checkPageIndex, ref checkAnnotIndex);
- if (selectAnnot != null)
- {
- StickyNoteAnnot stickyAnnot = selectAnnot as StickyNoteAnnot;
- StickyNoteAnnot.StickyPopupClosed -= StickyAnnot_StickyPopupClosed;
- StickyNoteAnnot.StickyPopupClosed += StickyAnnot_StickyPopupClosed;
- stickyAnnot.PopStickyNote();
- }
- }
- {
- e.annotType = annotation.Type;
- e.IsCreate = true;
- dynamic expandData = new ExpandoObject();
- expandData.AnnotIndex = currentParam.AnnotIndex;
- expandData.PageIndex = currentParam.PageIndex;
- expandData.AnnotParam = currentParam;
- e.Data = expandData;
- }
- }
- }
- private void SaveSharpAnnotBoundText(CPDFAnnotation boundAnnot)
- {
- if (boundAnnot == null || boundAnnot.Page == null || boundAnnot.Page.IsValid() == false)
- {
- return;
- }
- if (boundAnnot.Type != C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE && boundAnnot.Type != C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE)
- {
- return;
- }
- CPDFTextPage textPage= boundAnnot.Page.GetTextPage();
- if (textPage == null || textPage.IsValid()==false)
- {
- return;
- }
- string boundText = textPage.GetBoundedText(boundAnnot.GetRect());
- if(string.IsNullOrEmpty(boundText)==false)
- {
- boundAnnot.SetContent(boundText);
- }
- }
- private void StickyAnnot_StickyPopupClosed(object sender, EventArgs e)
- {
- StickyNoteAnnot.StickyPopupClosed -= StickyAnnot_StickyPopupClosed;
- StickyNoteAnnot stickyAnnot = sender as StickyNoteAnnot;
- if (stickyAnnot == null)
- {
- return;
- }
- AnnotData annotData = stickyAnnot.GetAnnotData();
- AnnotParam currentParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annotData.Annot);
- AnnotHistory annotHistory = ParamConverter.CreateHistory(annotData.Annot);
- string content = annotData.Annot.GetContent();
- if (string.IsNullOrEmpty(content))
- {
- if (annotData.Annot.RemoveAnnot())
- {
- viewerTool.ClearDrawAnnot();
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- viewerTool.SelectedAnnotForIndex(-1, -1);
- annotHistory.CurrentParam = currentParam;
- annotHistory.Action = HistoryAction.Remove;
- annotHistory.PDFDoc = viewerTool.PDFViewer.GetDocument();
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
- }
- return;
- }
- AnnotParam previousParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annotData.Annot);
- previousParam.Content = string.Empty;
- annotHistory.PreviousParam = previousParam;
- annotHistory.CurrentParam = currentParam;
- annotHistory.Action = HistoryAction.Update;
- annotHistory.PDFDoc = viewerTool.PDFViewer.GetDocument();
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
- }
- internal void PostMeasureInfo(object sender, CPDFAnnotation rawAnnot)
- {
- if (rawAnnot == null)
- {
- return;
- }
- try
- {
- if (rawAnnot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
- {
- CPDFLineAnnotation lineAnnot = rawAnnot as CPDFLineAnnotation;
- if (lineAnnot.IsMeasured() && lineAnnot.Points != null && lineAnnot.Points.Count() == 2)
- {
- CPDFDistanceMeasure lineMeasure = lineAnnot.GetDistanceMeasure();
- CPDFMeasureInfo measureInfo = lineMeasure.MeasureInfo;
- Vector standVector = new Vector(1, 0);
- Point startPoint = new Point(lineAnnot.Points[0].x, lineAnnot.Points[0].y);
- Point endPoint = new Point(lineAnnot.Points[1].x, lineAnnot.Points[1].y);
- Vector movevector = endPoint - startPoint;
- double showLenght = lineMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_LENGTH);
- MeasureEventArgs measureEvent = new MeasureEventArgs();
- measureEvent.Angle = (int)Math.Abs(Vector.AngleBetween(movevector, standVector));
- measureEvent.RulerTranslateUnit = measureInfo.RulerTranslateUnit;
- measureEvent.RulerTranslate = measureInfo.RulerTranslate;
- measureEvent.RulerBase = measureInfo.RulerBase;
- measureEvent.RulerBaseUnit = measureInfo.RulerBaseUnit;
- measureEvent.MousePos = new Point(
- (int)Math.Abs(movevector.X),
- (int)Math.Abs(movevector.Y));
- measureEvent.Type = CPDFMeasureType.CPDF_DISTANCE_MEASURE;
- NumberFormatInfo formatInfo = new NumberFormatInfo();
- formatInfo.NumberDecimalDigits = Math.Abs(measureInfo.Precision).ToString().Length - 1;
- measureEvent.Distance = showLenght.ToString("N", formatInfo) + " " + measureInfo.RulerTranslateUnit;
- measureEvent.Precision = GetMeasureShowPrecision(measureInfo.Precision);
- viewerTool?.InvokeMeasureChangeEvent(sender, measureEvent);
- }
- }
- if (rawAnnot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE)
- {
- CPDFPolylineAnnotation polylineAnnot = rawAnnot as CPDFPolylineAnnotation;
- if (polylineAnnot.IsMeasured() && polylineAnnot.Points != null && polylineAnnot.Points.Count() >= 2)
- {
- double totalInch = 0;
- for (int i = 0; i < polylineAnnot.Points.Count - 1; i++)
- {
- Point endLinePoint = new Point(
- polylineAnnot.Points[i + 1].x,
- polylineAnnot.Points[i + 1].y
- );
- Point startLinePoint = new Point(
- polylineAnnot.Points[i].x,
- polylineAnnot.Points[i].y
- );
- Vector subVector = endLinePoint - startLinePoint;
- totalInch += subVector.Length;
- }
- totalInch = totalInch / 72D;
- CPDFPerimeterMeasure lineMeasure = polylineAnnot.GetPerimeterMeasure();
- CPDFMeasureInfo measureInfo = lineMeasure.MeasureInfo;
- double showLenght = lineMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_LENGTH);
- MeasureEventArgs measureEvent = new MeasureEventArgs();
- measureEvent.Angle = 0;
- measureEvent.RulerTranslateUnit = measureInfo.RulerTranslateUnit;
- measureEvent.RulerTranslate = measureInfo.RulerTranslate;
- measureEvent.RulerBase = measureInfo.RulerBase;
- measureEvent.RulerBaseUnit = measureInfo.RulerBaseUnit;
- measureEvent.Precision = GetMeasureShowPrecision(measureInfo.Precision);
- measureEvent.Type = CPDFMeasureType.CPDF_PERIMETER_MEASURE;
- NumberFormatInfo formatInfo = new NumberFormatInfo();
- formatInfo.NumberDecimalDigits = Math.Abs(measureInfo.Precision).ToString().Length - 1;
- measureEvent.Distance = showLenght.ToString("N", formatInfo) + " " + measureInfo.RulerTranslateUnit;
- viewerTool?.InvokeMeasureChangeEvent(sender, measureEvent);
- }
- }
- if (rawAnnot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON)
- {
- CPDFPolygonAnnotation polygonAnnot = rawAnnot as CPDFPolygonAnnotation;
- if (polygonAnnot.IsMeasured() && polygonAnnot.Points != null && polygonAnnot.Points.Count() >= 2)
- {
- double totalInch = 0;
- for (int i = 0; i < polygonAnnot.Points.Count - 1; i++)
- {
- Point endLinePoint = new Point(
- polygonAnnot.Points[i + 1].x,
- polygonAnnot.Points[i + 1].y
- );
- Point startLinePoint = new Point(
- polygonAnnot.Points[i].x,
- polygonAnnot.Points[i].y
- );
- Vector subVector = endLinePoint - startLinePoint;
- totalInch += subVector.Length;
- }
- totalInch = totalInch / 72D;
- CPDFAreaMeasure areaMeasure = polygonAnnot.GetAreaMeasure();
- CPDFMeasureInfo measureInfo = areaMeasure.MeasureInfo;
- double showLenght = areaMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_LENGTH);
- MeasureEventArgs measureEvent = new MeasureEventArgs();
- measureEvent.Angle = 0;
- measureEvent.RulerTranslateUnit = measureInfo.RulerTranslateUnit;
- measureEvent.RulerTranslate = measureInfo.RulerTranslate;
- measureEvent.RulerBase = measureInfo.RulerBase;
- measureEvent.RulerBaseUnit = measureInfo.RulerBaseUnit;
- measureEvent.Precision = GetMeasureShowPrecision(measureInfo.Precision);
- measureEvent.Type = CPDFMeasureType.CPDF_AREA_MEASURE;
- NumberFormatInfo formatInfo = new NumberFormatInfo();
- formatInfo.NumberDecimalDigits = Math.Abs(measureInfo.Precision).ToString().Length - 1;
- measureEvent.Distance = showLenght.ToString("N", formatInfo) + " " + measureInfo.RulerTranslateUnit;
- double area = areaMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_AREA);
- measureEvent.Area = string.Format("{0} sq {1}", GetPrecisionData(area, measureEvent.Precision), measureEvent.RulerTranslateUnit);
- viewerTool?.InvokeMeasureChangeEvent(sender, measureEvent);
- }
- }
- }
- catch (Exception e)
- {
- }
- }
- public string GetPrecisionData(double number, double precision)
- {
- NumberFormatInfo formatInfo = new NumberFormatInfo();
- formatInfo.NumberDecimalDigits = 2;
- if (precision == 1)
- {
- formatInfo.NumberDecimalDigits = 0;
- }
- if (precision == 0.1)
- {
- formatInfo.NumberDecimalDigits = 1;
- }
- if (precision == 0.01)
- {
- formatInfo.NumberDecimalDigits = 2;
- }
- if (precision == 0.001)
- {
- formatInfo.NumberDecimalDigits = 3;
- }
- if (precision == 0.0001)
- {
- formatInfo.NumberDecimalDigits = 4;
- }
- if (precision == 0.00001)
- {
- formatInfo.NumberDecimalDigits = 5;
- }
- return number.ToString("N", formatInfo);
- }
- internal double GetMeasureShowPrecision(int precision)
- {
- if (precision == CPDFMeasure.PRECISION_VALUE_ZERO)
- {
- return 1;
- }
- if (CPDFMeasure.PRECISION_VALUE_ONE == precision)
- {
- return 0.1;
- }
- if (CPDFMeasure.PRECISION_VALUE_TWO == precision)
- {
- return 0.01;
- }
- if (CPDFMeasure.PRECISION_VALUE_THREE == precision)
- {
- return 0.001;
- }
- if (CPDFMeasure.PRECISION_VALUE_FOUR == precision)
- {
- return 0.0001;
- }
- return 0;
- }
- private object GetAnnotExpandObject(CPDFAnnotation annot)
- {
- if (annot != null && annot.IsValid())
- {
- try
- {
- AnnotParam annotParam = null;
- if (annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
- {
- annotParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), annot);
- }
- else
- {
- annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annot);
- }
- if (annotParam != null)
- {
- annotParam.AnnotIndex = annot.Page.GetAnnotCount() - 1;
- dynamic expandData = new ExpandoObject();
- expandData.AnnotIndex = annotParam.AnnotIndex;
- expandData.PageIndex = annot.Page.PageIndex;
- expandData.AnnotParam = annotParam;
- return expandData;
- }
- }
- catch (Exception ex)
- {
- }
- }
- return null;
- }
- private void SaveInkCreateAnnotation(ref CPDFAnnotation annotation, List<Point> points)
- {
- // Creation of non-custom stamps
- if (!viewerTool.PDFViewer.GetIsShowStampMouse())
- {
- if (points.Count < 5)
- {
- annotation.RemoveAnnot();
- annotation = null;
- return;
- }
- List<List<CPoint>> inkPathList = new List<List<CPoint>>();
- List<CPoint> inkPath = new List<CPoint>();
- foreach (Point inkNode in points)
- {
- inkPath.Add(new CPoint((float)DpiHelper.StandardNumToPDFNum(inkNode.X), (float)DpiHelper.StandardNumToPDFNum(inkNode.Y)));
- }
- inkPathList.Add(inkPath);
- (annotation as CPDFInkAnnotation).SetInkPath(inkPathList);
- (annotation as CPDFInkAnnotation).UpdateAp();
- }
- else
- {
- Rect stampRect = viewerTool.PDFViewer.GetStampRect();
- Point mousePoint = new Point(
- stampRect.X - stampRect.Width / 2 * viewerTool.GetCPDFViewer().GetZoom(),
- stampRect.Y - stampRect.Height / 2 * viewerTool.GetCPDFViewer().GetZoom()
- );
- viewerTool.GetCPDFViewer().GetPointPageInfo(mousePoint, out int pageindex, out Rect paintRect, out Rect pageBound);
- if (pageindex < 0)
- {
- annotation.RemoveAnnot();
- annotation = null;
- return;
- }
- else
- {
- CPDFPage cPDFPage = viewerTool.GetCPDFViewer().GetDocument().PageAtIndex(pageindex);
- Point cropPoint = new Point();
- if (viewerTool.GetCPDFViewer().GetIsCrop())
- {
- CRect cropRect = cPDFPage.GetCropBounds();
- cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
- cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
- }
- // Move the point
- CPoint cPoint = new CPoint(
- (float)((mousePoint.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom()),
- (float)((mousePoint.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom()));
- List<List<CPoint>> cPoints = (annotation as CPDFInkAnnotation).InkPath;
- List<List<CPoint>> savePointList = new List<List<CPoint>>();
- foreach (List<CPoint> inkNode in cPoints)
- {
- List<CPoint> savePoints = new List<CPoint>();
- foreach (CPoint addPoint in inkNode)
- {
- savePoints.Add(
- new CPoint(
- (addPoint.x + (float)DpiHelper.StandardNumToPDFNum(cPoint.x)),
- (addPoint.y + (float)DpiHelper.StandardNumToPDFNum(cPoint.y))
- ));
- }
- if (savePoints.Count > 0)
- {
- savePointList.Add(savePoints);
- }
- }
- (annotation as CPDFInkAnnotation).SetInkPath(savePointList);
- (annotation as CPDFInkAnnotation).UpdateAp();
- }
- }
- viewerTool.ClearDrawAnnot();
- viewerTool.GetCPDFViewer().UpdateAnnotFrame();
- InkAnnotHistory inkAnnotHistory = new InkAnnotHistory();
- AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.PDFViewer.GetDocument(), cPDFAnnotation);
- annotParam.AnnotIndex = cPDFAnnotation.Page.GetAnnotCount() - 1;
- inkAnnotHistory.CurrentParam = (InkParam)annotParam;
- inkAnnotHistory.PDFDoc = viewerTool.PDFViewer.GetDocument();
- viewerTool.GetCPDFViewer().UndoManager.AddHistory(inkAnnotHistory);
- return;
- }
- #endregion
- /// <summary>
- /// Set mouse pattern when creating content editing
- /// </summary>
- /// <param name="AddTextEditCursor">add text</param>
- /// <param name="AddImageEditCursor">add image</param>
- public void SetAddContentEditCursor(Cursor AddTextEditCursor, Cursor AddImageEditCursor)
- {
- if (AddTextEditCursor == null)
- {
- AddTextEditCursor = Cursors.IBeam;
- }
- if (AddImageEditCursor == null)
- {
- AddImageEditCursor = Cursors.Arrow;
- }
- this.addTextEditCursor = AddTextEditCursor;
- this.addImageEditCursor = AddImageEditCursor;
- }
- private void ViewerTool_MouseMoveHandler(object sender, MouseEventObject e)
- {
- if (viewerTool == null)
- return;
- viewerTool.DrawMoveSelectedMultiRect();
- viewerTool.DrawMovePageSelectedRect();
- if (currentToolType != ToolType.ContentEdit)
- {
- if (e.hitTestType == MouseHitTestType.SelectRect)
- {
- List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
- {
- C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
- };
- Cursor oldCursor = viewerTool.Cursor;
- Cursor newCursor = viewerTool.GetMoveSelectedRectCursor();
- if (oldCursor != newCursor || viewerTool.PDFViewer.Cursor!=newCursor)
- {
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = newCursor;
- }
- //viewerTool.PDFViewer.Cursor = viewerTool.Cursor= viewerTool.GetMoveSelectedRectCursor();
- if (list.Contains(e.annotType))
- {
- viewerTool.DrawMoveEditAnnot();
- }
- else
- {
- if (e.annotType != C_ANNOTATION_TYPE.C_ANNOTATION_LINK)
- {
- bool tag = viewerTool.DrawMoveSelectedRect();
- if (currentToolType == ToolType.WidgetEdit)
- {
- BaseWidget hitWidget = viewerTool?.GetCPDFViewer()?.AnnotHitTest() as BaseWidget;
- if (hitWidget == null)
- {
- viewerTool.MoveDrawWidget(tag);
- }
- else
- {
- viewerTool.MoveDrawWidget(true);
- }
- }
- }
- }
- }
- else
- {
- if (currentToolType == ToolType.CreateAnnot)
- {
- if (!viewerTool.PDFViewer.GetIsShowStampMouse())
- {
- // Annotation drawing only occurs if the mouse is not set to stamp/data application mode.// Annotation drawing only occurs if the mouse is not set to stamp/data application mode.
- viewerTool.MoveDrawAnnot();
- }
- switch (createAnnotType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
- case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
- viewerTool.DrawMoveSelectText(false);
- break;
- default:
- break;
- }
- }
- else if (currentToolType == ToolType.WidgetEdit)
- {
- BaseWidget hitWidget = viewerTool?.GetCPDFViewer()?.AnnotHitTest() as BaseWidget;
- if (hitWidget == null)
- {
- viewerTool.MoveDrawWidget(false);
- }
- else
- {
- viewerTool.MoveDrawWidget(true);
- }
- }
- else if (e.hitTestType == MouseHitTestType.Unknown && currentToolType != ToolType.WidgetEdit)
- {
- if (currentToolType == ToolType.Customize)
- {
- viewerTool.DrawMoveCustomizeTool();
- }
- else
- {
- TextSelectInfo textInfo = viewerTool.GetTextSelectInfo();
- if ((textInfo.StartPage != -1 && e.mouseButtonEventArgs.LeftButton == MouseButtonState.Pressed) || viewerTool.IsText())
- {
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.IBeam;
- }
- else
- {
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.Arrow;
- }
- }
- }
- }
- if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_NONE)
- {
- viewerTool.DrawMoveSelectText(false);
- }
- }
- else
- {
- if (createContentEditType != CPDFEditType.EditImage)
- {
- Cursor cursor = Cursors.Arrow;
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(viewerTool.PDFViewer.GetViewForTag(viewerTool.MultiSelectedRectViewTag));
- if (viewerTool.GetLastSelectedRect() != null)
- {
- if (editSelected)
- {
- viewerTool.DrawMoveTextEdit(viewerTool.GetLastSelectedRect(), clickEditSelected);
- if (clickEditSelected)
- cursor = Cursors.IBeam;
- else
- cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
- }
- else
- {
- cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
- }
- }
- else
- {
- cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
- if (multiSelectedRect == null || multiSelectedRect.Children.Count == 0)
- {
- //Selection of mobile drawing logic
- if (e.mouseButtonEventArgs.LeftButton == MouseButtonState.Pressed && createContentEditType == CPDFEditType.None)
- {
- viewerTool.DrawMoveFrameSelect();
- }
- }
- }
- if (cursor == Cursors.Arrow && createContentEditType == CPDFEditType.EditText)
- {
- cursor = addTextEditCursor;
- }
- viewerTool.Cursor = cursor;
- viewerTool.PDFViewer.Cursor = cursor;
- }
- else
- {
- Cursor cursor = Cursors.Arrow;
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(viewerTool.PDFViewer.GetViewForTag(viewerTool.MultiSelectedRectViewTag));
- if (viewerTool.GetLastSelectedRect() != null)
- {
- if (editSelected)
- {
- viewerTool.DrawMoveTextEdit(viewerTool.GetLastSelectedRect(), clickEditSelected);
- if (clickEditSelected)
- cursor = Cursors.IBeam;
- else
- cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
- }
- else
- {
- cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
- }
- }
- else
- {
- cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
- }
- if (cursor == Cursors.Arrow && createContentEditType == CPDFEditType.EditText)
- {
- cursor = Cursors.IBeam;
- }
- if (cursor == Cursors.Arrow && createContentEditType == CPDFEditType.EditImage)
- {
- cursor = addImageEditCursor;
- }
- viewerTool.Cursor = cursor;
- viewerTool.PDFViewer.Cursor = cursor;
- //viewerTool.Cursor = Cursors.None;
- //viewerTool.PDFViewer.Cursor = Cursors.None;
- }
- }
- MouseMoveHandler?.Invoke(this, e);
- }
- private void MakeTextBoxReadOnly(TextBox textBox)
- {
- try
- {
- DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
- FreeTextParam textParam = defaultSettingParam.FreeTextParamDef;
- if(textParam.IsReadOnly)
- {
- textBox.IsReadOnly = true;
- }
- }
- catch (Exception ex)
- {
- }
- }
- private void ViewerTool_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
- {
- viewerTool.RemoveSelectTextData();
- viewerTool.ReDrawSelectText();
- viewerTool.HideWidgetHitPop();
- switch (e.hitTestType)
- {
- case MouseHitTestType.Unknown:
- {
- if (currentToolType == ToolType.CreateAnnot)
- {
- switch ((e.mouseButtonEventArgs as MouseButtonEventArgs).ClickCount)
- {
- case 1:
- if (viewerTool.IsCanSave())
- {
- cPDFAnnotation = viewerTool.StartDrawAnnot(createAnnotType);
- viewerTool.CreateDefaultAnnot(cPDFAnnotation, createAnnotType, null);
- if (cPDFAnnotation != null && createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT)
- {
- TextBox textui = viewerTool.CreateTextBox();
- MakeTextBoxReadOnly(textui);
- }
- switch (createAnnotType)
- {
- case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
- case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
- case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
- case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
- {
- viewerTool.DrawStartSelectText();
- viewerTool.EndDrawAnnot();
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
- case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
- if (viewerTool.IsText())
- {
- viewerTool.DrawStartSelectText();
- viewerTool.EndDrawAnnot();
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
- {
- bool cansave = true;
- CPDFLineAnnotation LineAnnotation = (cPDFAnnotation as CPDFLineAnnotation);
- if (LineAnnotation != null)
- {
- if (LineAnnotation.IsMeasured())
- {
- cansave = false;
- }
- }
- viewerTool.SetIsCanSave(cansave);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- {
- bool cansave = true;
- CPDFPolygonAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolygonAnnotation);
- PolyAnnotation?.IsMeasured();
- if (PolyAnnotation != null)
- {
- if (PolyAnnotation.IsMeasured())
- {
- cansave = false;
- }
- }
- viewerTool.SetIsCanSave(cansave);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- {
- bool cansave = true;
- CPDFPolylineAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolylineAnnotation);
- PolyAnnotation?.IsMeasured();
- if (PolyAnnotation != null)
- {
- if (PolyAnnotation.IsMeasured())
- {
- cansave = false;
- }
- }
- viewerTool.SetIsCanSave(cansave);
- }
- break;
- default:
- break;
- }
- }
- else
- {
- viewerTool.MultipleClick();
- e.IsDrawing = true;
- }
- break;
- case 2:
- if (currentToolType != ToolType.Customize)
- {
- if (!viewerTool.IsCanSave())
- {
- viewerTool.SetIsCanSave(true);
- }
- }
- break;
- }
- }
- else if (currentToolType == ToolType.WidgetEdit)
- {
- cPDFAnnotation = viewerTool.StartDrawWidget(createWidgetType);
- viewerTool.CreateDefaultWidget(cPDFAnnotation, createWidgetType, null);
- viewerTool?.InvokeWidgetCreated(cPDFAnnotation);
- }
- else if (currentToolType == ToolType.Pan || currentToolType == ToolType.Viewer)
- {
- if (viewerTool.IsText())
- {
- viewerTool.DrawStartSelectText();
- e.hitTestType = MouseHitTestType.Text;
- }
- }
- else if (currentToolType == ToolType.Customize)
- {
- viewerTool.DrawStartCustomizeTool(CustomizeToolType.kErase);
- }
- viewerTool.CleanSelectedRect();
- viewerTool.CleanEditAnnot();
- }
- break;
- case MouseHitTestType.Widget:
- {
- viewerTool.CleanSelectedRect();
- viewerTool.CleanEditAnnot();
- BaseWidget hitWidget = viewerTool?.GetCPDFViewer()?.AnnotHitTest() as BaseWidget;
- if (hitWidget != null)
- {
- viewerTool.ShowFormHitPop(hitWidget);
- }
- }
- break;
- case MouseHitTestType.MultiTextEdit:
- viewerTool.DrawStartSelectedMultiRect();
- break;
- case MouseHitTestType.SelectedPageRect:
- viewerTool.DrawStartPageSelectedRect();
- break;
- default:
- {
- List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
- {
- C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
- C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
- };
- if (list.Contains(e.annotType))
- {
- viewerTool.CleanSelectedRect();
- if (!e.IsMersured || !list.Contains(createAnnotType))
- {
- viewerTool.StartDrawEditAnnot();
- }
- }
- else
- {
- viewerTool.CleanEditAnnot();
- viewerTool.DrawStartSelectedRect();
- if (currentToolType == ToolType.WidgetEdit)
- {
- viewerTool.MoveDrawWidget(true);
- }
- }
- }
- break;
- }
- switch (currentToolType)
- {
- case ToolType.Pan:
- {
- if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_NONE)
- {
- switch ((e.mouseButtonEventArgs as MouseButtonEventArgs).ClickCount)
- {
- case 2:
- viewerTool.DrawMoveSelectText(true);
- break;
- }
- }
- }
- break;
- case ToolType.ContentEdit:
- {
- editSelected = true;
- clickEditSelected = true;
- switch ((e.mouseButtonEventArgs as MouseButtonEventArgs).ClickCount)
- {
- case 1:
- if (viewerTool.GetIsCropMode())
- {
- //Preconditions for determining crop acquisition points
- viewerTool.HandleTextSelectClick(viewerTool.GetLastSelectedRect(), true);
- clickEditSelected = false;
- MouseLeftButtonDownHandler?.Invoke(this, e);
- }
- break;
- case 2:
- viewerTool.HandleTextSelectClick(viewerTool.GetLastSelectedRect(), true);
- clickEditSelected = false;
- MouseLeftButtonDownHandler?.Invoke(this, e);
- return;
- case 3:
- viewerTool.HandleTextSelectClick(viewerTool.GetLastSelectedRect(), false);
- clickEditSelected = false;
- MouseLeftButtonDownHandler?.Invoke(this, e);
- return;
- }
- if (createContentEditType != CPDFEditType.EditImage)
- {
- viewerTool.DrawTextEditDownEvent(true);
- }
- viewerTool.HideDrawSelectedMultiRect();
- if (viewerTool.GetLastSelectedRect() != null)
- {
- viewerTool.DrawEndFrameSelect();
- Point point = Mouse.GetPosition(viewerTool);
- PointControlType pointControlType = PointControlType.None;
- if (viewerTool.GetIsCropMode())
- {
- //Crop acquisition point judgment
- pointControlType = viewerTool.GetLastSelectedRect().GetHitCropControlIndex(point);
- }
- else
- {
- pointControlType = viewerTool.GetLastSelectedRect().GetHitControlIndex(point);
- }
- EditAreaObject editAreaObject = viewerTool.GetEditAreaObjectForRect(viewerTool.GetLastSelectedRect());
- if (pointControlType != PointControlType.None &&
- (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage || pointControlType != PointControlType.Body))
- {
- switch (pointControlType)
- {
- case PointControlType.LeftTop:
- case PointControlType.RightBottom:
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeNWSE;
- break;
- case PointControlType.LeftMiddle:
- case PointControlType.RightMiddle:
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeWE;
- break;
- case PointControlType.LeftBottom:
- case PointControlType.RightTop:
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeNESW;
- break;
- case PointControlType.MiddlBottom:
- case PointControlType.MiddleTop:
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeNS;
- break;
- case PointControlType.Line:
- case PointControlType.Body:
- viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeAll;
- break;
- default:
- break;
- }
- if (e.mouseButtonEventArgs.LeftButton == MouseButtonState.Pressed)
- {
- viewerTool.DrawStartTextEdit(viewerTool.GetLastSelectedRect(), editAreaObject);
- }
- clickEditSelected = false;
- }
- }
- else
- {
- //If it is multiple selection, do not create a new input box
- MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(viewerTool.PDFViewer.GetViewForTag(viewerTool.MultiSelectedRectViewTag));
- if (multiSelectedRect != null && multiSelectedRect.Children.Count > 0)
- {
- viewerTool.PDFViewer.UpdateRenderFrame();
- return;
- }
- Point point = Mouse.GetPosition(viewerTool);
- viewerTool.GetCPDFViewer().GetPointPageInfo(point, out int index, out Rect paintRect, out Rect pageBound);
- if (index < 0)
- {
- MouseLeftButtonDownHandler?.Invoke(this, e);
- return;
- }
- if (createContentEditType == CPDFEditType.EditText)
- {
- if (viewerTool.CanAddTextEdit)
- {
- viewerTool.DrawTest(pageBound, index);
- }
- }
- if (createContentEditType == CPDFEditType.None)
- {
- viewerTool.DrawFrameSelect();
- }
- else
- {
- viewerTool.DrawEndFrameSelect();
- }
- clickEditSelected = false;
- }
- }
- break;
- default:
- break;
- }
- MouseLeftButtonDownHandler?.Invoke(this, e);
- }
- private void ViewerTool_MouseRightButtonDownHandler(object sender, MouseEventObject e)
- {
- if (e.mouseButtonEventArgs != null)
- {
- viewerTool?.SetPastePoint(e.mouseButtonEventArgs.GetPosition(viewerTool));
- }
- MouseRightButtonDownHandler?.Invoke(sender, e);
- }
- public void CreateLinkAnnotWithImage(int pageIndex, CRect rawImageRect)
- {
- if(viewerTool == null)
- {
- return;
- }
-
- viewerTool.RemoveSelectTextData();
- viewerTool.ReDrawSelectText();
- viewerTool.HideWidgetHitPop();
- CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
- CPDFDocument cPDFDocument = pdfViewer.GetDocument();
- CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageIndex);
- CPDFLinkAnnotation linkAnnot = cPDFPage.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_LINK) as CPDFLinkAnnotation;
- if (linkAnnot != null)
- {
- linkAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
- linkAnnot.SetModifyDate(PDFHelp.GetCurrentPdfTime());
- List<CPDFAnnotation> annotList = cPDFPage.GetAnnotations();
- int newIndex = cPDFPage.GetAnnotCount();
- linkAnnot.SetRect(rawImageRect);
- DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
- LinkParam linkParam = defaultSettingParam.LinkParamDef;
- switch (linkParam.Action)
- {
- case C_ACTION_TYPE.ACTION_TYPE_GOTO:
- CPDFGoToAction gotoAction = new CPDFGoToAction();
- CPDFDestination destination = new CPDFDestination();
- destination.Position_X = linkParam.DestinationPosition.x;
- destination.Position_Y = linkParam.DestinationPosition.y;
- destination.PageIndex = linkParam.DestinationPageIndex;
- gotoAction.SetDestination(cPDFDocument, destination);
- linkAnnot.SetLinkAction(gotoAction);
- break;
- case C_ACTION_TYPE.ACTION_TYPE_URI:
- CPDFUriAction uriAction = new CPDFUriAction();
- if (!string.IsNullOrEmpty(linkParam.Uri))
- {
- uriAction.SetUri(linkParam.Uri);
- }
- linkAnnot.SetLinkAction(uriAction);
- break;
- default:
- break;
- }
- if (!string.IsNullOrEmpty(linkParam.Content))
- {
- linkAnnot.SetContent(linkParam.Content);
- }
- if (!string.IsNullOrEmpty(linkParam.Author))
- {
- linkAnnot.SetAuthor(linkParam.Author);
- }
- if (!string.IsNullOrEmpty(linkParam.CreateTime))
- {
- linkAnnot.SetCreationDate(linkParam.CreateTime);
- }
- if (!string.IsNullOrEmpty(linkParam.UpdateTime))
- {
- linkAnnot.SetModifyDate(linkParam.UpdateTime);
- }
- linkAnnot.SetIsLocked(linkParam.Locked);
- linkAnnot.SetTransparency(linkParam.Transparency);
- MouseEventObject e= new MouseEventObject();
- e.hitTestType = MouseHitTestType.Annot;
- e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_LINK;
- e.IsCreate = true;
- AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), linkAnnot);
- dynamic expandData = new ExpandoObject();
- expandData.AnnotIndex = newIndex;
- expandData.PageIndex=pageIndex;
- expandData.AnnotParam= annotParam;
- e.Data = expandData;
- MouseLeftButtonUpHandler?.Invoke(this, e);
- }
- }
- }
- }
|