123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067 |
- 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;
- 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;
- 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();
- viewerTool.GetCPDFViewer().UndoManager.RemoveRedoHistoryForType(typeof(PDFEditHistory));
- viewerTool.GetCPDFViewer().UndoManager.RemoveUndoHistoryForType(typeof(PDFEditHistory));
- viewerTool.GetCPDFViewer().UpdateVirtualNodes();
- viewerTool.GetCPDFViewer().UpdateRenderFrame();
- }
- else
- {
- 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;
- }
- 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();
- }
- 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(true);
- 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();
- Point point = DpiHelper.StandardPointToPDFPoint(e.MoveOffset);
- 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);
- }
- }
- 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).IsMersured())
- {
- 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.IsMersured())
- {
- 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.IsMersured())
- {
- 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.IsMersured())
- {
- 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);
- viewerTool.GetCPDFViewer().UpdateRenderFrame();
- }
- 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().UpdateRenderFrame();
- 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)
- {
- viewerTool.DrawEndTextEdit(viewerTool.GetLastSelectedRect());
- 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)
- {
- e.IsCreate = viewerTool.DrawEndTest();
- }
- else
- {
- e.IsCreate = true;
- }
- }
- }
- break;
- case ToolType.Customize:
- viewerTool.DrawEndCustomizeTool();
- break;
- default:
- break;
- }
- viewerTool.DrawEndSelectText();
- MouseLeftButtonUpHandler?.Invoke(this, e);
- 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().UpdateRenderFrame();
- 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).IsMersured())
- {
- MeasureSetting measureSetting = viewerTool.GetMeasureSetting();
- if (viewerTool.GetMoveLength() > measureSetting.MoveDetectionLength)
- {
- viewerTool.SetIsCanSave(true);
- }
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- if ((cPDFAnnotation as CPDFPolygonAnnotation).IsMersured())
- {
- 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 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).IsMersured())
- {
- 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 ((annotation as CPDFPolygonAnnotation).IsMersured())
- {
- 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);
- }
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- {
- if ((annotation as CPDFPolylineAnnotation).IsMersured())
- {
- 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);
- }
- }
- 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_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
- {
- 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);
- }
- 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);
- 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 + annotation.GetBorderWidth(), (float)rect.Bottom - annotation.GetBorderWidth(), (float)rect.Right - annotation.GetBorderWidth(), (float)rect.Top + annotation.GetBorderWidth());
- CRect cRect = new CRect(
- (float)rect.Left,
- (float)rect.Bottom,
- (float)rect.Right,
- (float)rect.Top);
- annotation.SetRect(cRect);
- annotation.UpdateAp();
- 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.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
- viewerTool.ClearDrawAnnot();
- viewerTool.GetCPDFViewer().UpdateRenderFrame();
- {
- 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;
- }
- }
- }
- 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.IsMersured() && 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.IsMersured() && 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.IsMersured() && 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().UpdateRenderFrame();
- 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
- 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 = 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;
- 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
- {
- viewerTool.HideDrawSelectedMultiRect();
- cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
- }
- if (cursor == Cursors.Arrow && createContentEditType == CPDFEditType.EditText)
- {
- cursor = Cursors.IBeam;
- }
- viewerTool.Cursor = cursor;
- viewerTool.PDFViewer.Cursor = cursor;
- }
- else
- {
- //viewerTool.Cursor = Cursors.None;
- //viewerTool.PDFViewer.Cursor = Cursors.None;
- }
- }
- MouseMoveHandler?.Invoke(this, e);
- }
- 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)
- {
- viewerTool.CreateTextBox();
- }
- 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_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.IsMersured())
- {
- cansave = false;
- }
- }
- viewerTool.SetIsCanSave(cansave);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
- {
- bool cansave = true;
- CPDFPolygonAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolygonAnnotation);
- PolyAnnotation?.IsMersured();
- if (PolyAnnotation != null)
- {
- if (PolyAnnotation.IsMersured())
- {
- cansave = false;
- }
- }
- viewerTool.SetIsCanSave(cansave);
- }
- break;
- case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
- {
- bool cansave = true;
- CPDFPolylineAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolylineAnnotation);
- PolyAnnotation?.IsMersured();
- if (PolyAnnotation != null)
- {
- if (PolyAnnotation.IsMersured())
- {
- 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);
- }
- 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 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)
- {
- Point point = Mouse.GetPosition(viewerTool);
- PointControlType 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;
- }
- viewerTool.DrawStartTextEdit(viewerTool.GetLastSelectedRect());
- clickEditSelected = false;
- }
- }
- else
- {
- 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)
- {
- viewerTool.DrawTest(pageBound, index);
- }
- 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);
- }
- }
- }
|