CPDFToolManager.cs 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.Tool.DrawTool;
  4. using ComPDFKitViewer.Widget;
  5. using ComPDFKitViewer.Helper;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Windows;
  10. using System.Windows.Input;
  11. using ComPDFKit.Tool.UndoManger;
  12. using ComPDFKit.PDFAnnotation.Form;
  13. using ComPDFKitViewer.BaseObject;
  14. using ComPDFKit.Tool.SettingParam;
  15. using ComPDFKit.PDFDocument;
  16. using ComPDFKit.PDFPage;
  17. using ComPDFKit.Viewer.Helper;
  18. using ComPDFKit.PDFPage.Edit;
  19. using ComPDFKit.Tool.Help;
  20. using ComPDFKit.Measure;
  21. using System.Dynamic;
  22. using System.Globalization;
  23. using System.Windows.Controls;
  24. using ComPDFKitViewer;
  25. using System.Reflection;
  26. using ComPDFKit.PDFDocument.Action;
  27. namespace ComPDFKit.Tool
  28. {
  29. public class CPDFToolManager
  30. {
  31. private CPDFViewerTool viewerTool;
  32. public event EventHandler<MouseEventObject> MouseLeftButtonDownHandler;
  33. public event EventHandler<MouseEventObject> MouseLeftButtonUpHandler;
  34. public event EventHandler<MouseEventObject> MouseMoveHandler;
  35. public event EventHandler<MouseEventObject> MouseRightButtonDownHandler;
  36. public event EventHandler<SelectedAnnotData> AnnotDefaultEditedHandler;
  37. public event EventHandler<MultiSelectedData> MulitDefaultEditedHandler;
  38. /// <summary>
  39. /// Current tool type, pay attention to the use of if writing, reserve the subsequent or operation mode switch
  40. /// </summary>
  41. private ToolType currentToolType = ToolType.None;
  42. /// <summary>
  43. /// Identify whether it is a selected text state or a drag box state for content editing
  44. /// </summary>
  45. private bool editSelected = true;
  46. private bool clickEditSelected = false;
  47. /// <summary>
  48. /// Current creation annotation type
  49. /// </summary>
  50. private C_ANNOTATION_TYPE createAnnotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE;
  51. /// <summary>
  52. /// Current creation Widget type
  53. /// </summary>
  54. private C_WIDGET_TYPE createWidgetType = C_WIDGET_TYPE.WIDGET_NONE;
  55. /// <summary>
  56. /// Current creation content edit type
  57. /// </summary>
  58. private CPDFEditType createContentEditType = CPDFEditType.None;
  59. /// <summary>
  60. /// 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)
  61. /// </summary>
  62. private CPDFAnnotation cPDFAnnotation;
  63. /// <summary>
  64. /// Image path cache used for image creation (subject to possible adjustments later)
  65. /// </summary>
  66. private string createImagePath = string.Empty;
  67. public CPDFToolManager(CPDFViewerTool cPDFTool) : base()
  68. {
  69. viewerTool = cPDFTool;
  70. viewerTool.MouseLeftButtonDownHandler += ViewerTool_MouseLeftButtonDownHandler;
  71. viewerTool.MouseMoveHandler += ViewerTool_MouseMoveHandler;
  72. viewerTool.MouseLeftButtonUpHandler += ViewerTool_MouseLeftButtonUpHandler;
  73. viewerTool.MouseRightButtonDownHandler += ViewerTool_MouseRightButtonDownHandler;
  74. viewerTool.SelectedDataChanged += ViewerTool_SelectedDataChanged;
  75. viewerTool.SelectedDataChanging += ViewerTool_SelectedDataChanging;
  76. viewerTool.MultiDataChanged += ViewerTool_MulitDataChanged;
  77. viewerTool.MultiDataChanging += ViewerTool_MulitDataChanging;
  78. viewerTool.DeleteChanged += ViewerTool_DeleteChanged;
  79. viewerTool.AnnotEditDataChanged += ViewerTool_AnnotEditDataChanged;
  80. viewerTool.AnnotEditDataChanging += ViewerTool_AnnotEditDataChanging;
  81. }
  82. public void Remove()
  83. {
  84. viewerTool.MouseLeftButtonDownHandler -= ViewerTool_MouseLeftButtonDownHandler;
  85. viewerTool.MouseMoveHandler -= ViewerTool_MouseMoveHandler;
  86. viewerTool.MouseLeftButtonUpHandler -= ViewerTool_MouseLeftButtonUpHandler;
  87. viewerTool.SelectedDataChanged -= ViewerTool_SelectedDataChanged;
  88. viewerTool.SelectedDataChanging -= ViewerTool_SelectedDataChanging;
  89. viewerTool.MultiDataChanged -= ViewerTool_MulitDataChanged;
  90. viewerTool.MultiDataChanging -= ViewerTool_MulitDataChanging;
  91. viewerTool.DeleteChanged -= ViewerTool_DeleteChanged;
  92. viewerTool.AnnotEditDataChanged -= ViewerTool_AnnotEditDataChanged;
  93. viewerTool.AnnotEditDataChanging -= ViewerTool_AnnotEditDataChanging;
  94. viewerTool = null;
  95. }
  96. public BaseAnnot GetCacheHitTestAnnot()
  97. {
  98. return viewerTool.GetCacheHitTestAnnot();
  99. }
  100. public BaseWidget GetCacheHitTestWidget()
  101. {
  102. return viewerTool.GetCacheHitTestWidget();
  103. }
  104. public CPDFViewerTool GetCPDFViewerTool()
  105. {
  106. return viewerTool;
  107. }
  108. public CPDFDocument GetDocument()
  109. {
  110. return viewerTool.GetCPDFViewer().GetDocument();
  111. }
  112. public void SetCreateImagePath(string path)
  113. {
  114. createImagePath = path;
  115. }
  116. public ToolType GetToolType()
  117. {
  118. return currentToolType;
  119. }
  120. public bool SetCreateAnnotType(C_ANNOTATION_TYPE annotType)
  121. {
  122. viewerTool.SetIsHitTestLink(false);
  123. viewerTool.SetIsOnlyHitTestRedact(false);
  124. if (currentToolType != ToolType.CreateAnnot)
  125. {
  126. return false;
  127. }
  128. //MouseEventObject e= new MouseEventObject();
  129. //if (viewerTool.IsCanSave())
  130. //{
  131. // SaveCreateAnnotation(ref cPDFAnnotation, ref e);
  132. // viewerTool.PDFViewer.EnableZoom(true);
  133. // viewerTool.PDFViewer.CanHorizontallyScroll = true;
  134. // viewerTool.PDFViewer.CanVerticallyScroll = true;
  135. //}
  136. if (createAnnotType != annotType)
  137. {
  138. SaveCurrentAnnot();
  139. createAnnotType = annotType;
  140. }
  141. if (createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_LINK)
  142. {
  143. viewerTool.SetIsHitTestLink(true);
  144. }
  145. if (createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_REDACT)
  146. {
  147. viewerTool.SetIsOnlyHitTestRedact(true);
  148. }
  149. switch (annotType)
  150. {
  151. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  152. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  153. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  154. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  155. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  156. TextSelectInfo textSelectInfo = viewerTool.GetTextSelectInfo();
  157. if (textSelectInfo.PageSelectPointList.Count > 0)
  158. {
  159. GroupHistory historyData = null;
  160. viewerTool.CreateAnnotForSelectText(textSelectInfo, createAnnotType, out historyData);
  161. viewerTool.RemoveSelectTextData();
  162. if (historyData != null && historyData.Histories.Count > 0)
  163. {
  164. List<object> dataList = new List<object>();
  165. if (historyData != null && historyData.Histories.Count > 0)
  166. {
  167. foreach (IHistory historyItem in historyData.Histories)
  168. {
  169. AnnotHistory checkHistory = historyItem as AnnotHistory;
  170. if (checkHistory == null || checkHistory.CurrentParam == null)
  171. {
  172. continue;
  173. }
  174. dynamic expandData = new ExpandoObject();
  175. expandData.AnnotIndex = checkHistory.CurrentParam.AnnotIndex;
  176. expandData.PageIndex = checkHistory.CurrentParam.PageIndex;
  177. expandData.AnnotParam = checkHistory.CurrentParam;
  178. dataList.Add(expandData);
  179. }
  180. }
  181. if (dataList.Count > 0)
  182. {
  183. MouseEventObject eventObject = new MouseEventObject();
  184. eventObject.annotType = createAnnotType;
  185. eventObject.IsCreate = true;
  186. eventObject.Data = dataList.Count > 1 ? dataList : dataList[0];
  187. MouseLeftButtonUpHandler?.Invoke(this, eventObject);
  188. }
  189. }
  190. }
  191. break;
  192. default:
  193. break;
  194. }
  195. return true;
  196. }
  197. public C_ANNOTATION_TYPE GetAnnotType()
  198. {
  199. return createAnnotType;
  200. }
  201. public bool SetCreateWidgetType(C_WIDGET_TYPE widgetType)
  202. {
  203. if (currentToolType != ToolType.WidgetEdit)
  204. {
  205. return false;
  206. }
  207. if (createWidgetType != widgetType)
  208. {
  209. SaveCurrentAnnot();
  210. createWidgetType = widgetType;
  211. }
  212. viewerTool.SetDrawWidgetType(createWidgetType);
  213. return true;
  214. }
  215. public C_WIDGET_TYPE GetCreateWidgetType()
  216. {
  217. return createWidgetType;
  218. }
  219. public bool SetCreateContentEditType(CPDFEditType editType)
  220. {
  221. createContentEditType = editType;
  222. return true;
  223. }
  224. public CPDFEditType GetCreateContentEditType()
  225. {
  226. return createContentEditType;
  227. }
  228. public void ClearSelect()
  229. {
  230. /// Clear some UI effects of other modules
  231. viewerTool.HideWidgetHitPop();
  232. viewerTool.CleanSelectedRect();
  233. viewerTool.CleanEditAnnot();
  234. viewerTool.CleanDrawSelectImage();
  235. viewerTool.ClearDrawWidget();
  236. viewerTool.CleanEditView();
  237. viewerTool.CleanCustomizeTool();
  238. viewerTool.GetCPDFViewer().SetCacheEditPage(false);
  239. }
  240. public void SetToolType(ToolType toolType)
  241. {
  242. if (currentToolType == toolType)
  243. {
  244. return;
  245. }
  246. viewerTool.RemovePopTextUI();
  247. /// Clear some UI effects of other modules
  248. viewerTool.HideWidgetHitPop();
  249. viewerTool.CleanSelectedRect();
  250. viewerTool.CleanEditAnnot();
  251. viewerTool.ClearDrawWidget();
  252. viewerTool.CleanEditView();
  253. viewerTool.CleanCustomizeTool();
  254. viewerTool.CleanDrawSelectImage();
  255. viewerTool.GetCPDFViewer().SetCacheEditPage(false);
  256. viewerTool.ClearDrawAnnot();
  257. viewerTool.CleanPageSelectedRect();
  258. viewerTool.SelectedAnnotForIndex(-1, -1);
  259. ToolType oldToolType = currentToolType;
  260. currentToolType = toolType;
  261. switch (toolType)
  262. {
  263. case ToolType.None:
  264. break;
  265. case ToolType.Viewer:
  266. viewerTool.SetToolType(ToolType.Viewer);
  267. break;
  268. case ToolType.CreateAnnot:
  269. viewerTool.SetToolType(ToolType.CreateAnnot);
  270. break;
  271. case ToolType.Pan:
  272. viewerTool.SetToolType(ToolType.Pan);
  273. break;
  274. case ToolType.WidgetEdit:
  275. viewerTool.SetToolType(ToolType.WidgetEdit);
  276. viewerTool.RemoveSelectTextData();
  277. break;
  278. case ToolType.ContentEdit:
  279. viewerTool.SetToolType(ToolType.ContentEdit);
  280. viewerTool.GetCPDFViewer().SetCacheEditPage(true);
  281. viewerTool.RemoveSelectTextData();
  282. break;
  283. case ToolType.SelectedPage:
  284. viewerTool.SetToolType(ToolType.SelectedPage);
  285. viewerTool.RemoveSelectTextData();
  286. break;
  287. case ToolType.Customize:
  288. viewerTool.SetToolType(ToolType.Customize);
  289. viewerTool.RemoveSelectTextData();
  290. break;
  291. default:
  292. break;
  293. }
  294. if (oldToolType == ToolType.ContentEdit)
  295. {
  296. viewerTool.GetCPDFViewer().GetDocument().ReleasePages();
  297. viewerTool.GetCPDFViewer().UndoManager.RemoveRedoHistoryForType(typeof(PDFEditHistory));
  298. viewerTool.GetCPDFViewer().UndoManager.RemoveUndoHistoryForType(typeof(PDFEditHistory));
  299. viewerTool.GetCPDFViewer().UpdateVirtualNodes();
  300. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  301. }
  302. else
  303. {
  304. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  305. }
  306. }
  307. public CPDFEditArea GetSelectedEditAreaObject(ref int pageIndex)
  308. {
  309. EditAreaObject editAreaObject = viewerTool.GetEditAreaObjectForRect(viewerTool.GetLastSelectedRect());
  310. if (editAreaObject == null)
  311. {
  312. pageIndex = -1;
  313. }
  314. else
  315. {
  316. pageIndex = editAreaObject.PageIndex;
  317. }
  318. return editAreaObject?.cPDFEditArea;
  319. }
  320. public CPDFAnnotation GetCPDFAnnotation()
  321. {
  322. return cPDFAnnotation;
  323. }
  324. public void SetPageSelectText(List<TextSearchItem> pageTextList)
  325. {
  326. viewerTool.Dispatcher.Invoke(() =>
  327. {
  328. viewerTool.SetPageSelectText(pageTextList);
  329. viewerTool.ReDrawSelectText();
  330. });
  331. }
  332. public void HighLightSearchText(List<TextSearchItem> pageTextList)
  333. {
  334. if (pageTextList.Count < 0)
  335. {
  336. return;
  337. }
  338. viewerTool.Dispatcher.Invoke(() =>
  339. {
  340. viewerTool.HighLightSearchText(pageTextList);
  341. viewerTool.ReDrawSearchText();
  342. viewerTool.GetCPDFViewer().GoToPage(pageTextList[0].PageIndex, new Point(pageTextList[0].TextRect.X, pageTextList[0].TextRect.Y));
  343. });
  344. }
  345. private void ViewerTool_DeleteChanged(object sender, List<AnnotParam> e)
  346. {
  347. viewerTool.GetCPDFViewer().UpdateAnnotFrame();
  348. AnnotDefaultEditedHandler?.Invoke(this, null);
  349. }
  350. private void ViewerTool_SelectedDataChanging(object sender, DrawTool.SelectedAnnotData e)
  351. {
  352. }
  353. private void ViewerTool_SelectedDataChanged(object sender, DrawTool.SelectedAnnotData e)
  354. {
  355. if (e.annotData == null)
  356. {
  357. return;
  358. }
  359. AnnotHistory annotHistory = ParamConverter.CreateHistory(e.annotData.Annot);
  360. if (annotHistory == null)
  361. {
  362. return;
  363. }
  364. AnnotParam previousParam;
  365. AnnotParam currentParam;
  366. switch (e.annotData.AnnotType)
  367. {
  368. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  369. previousParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
  370. break;
  371. default:
  372. previousParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
  373. break;
  374. }
  375. /// Change operation
  376. if (e.annotData.AnnotType != C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
  377. {
  378. Rect rect1 = new Rect(
  379. (e.Square.Left - e.annotData.PaintOffset.X + (e.annotData.CropLeft * e.annotData.CurrentZoom)) / e.annotData.CurrentZoom,
  380. (e.Square.Top - e.annotData.PaintOffset.Y + (e.annotData.CropTop * e.annotData.CurrentZoom)) / e.annotData.CurrentZoom,
  381. e.Square.Width / e.annotData.CurrentZoom,
  382. e.Square.Height / e.annotData.CurrentZoom
  383. );
  384. Rect rect = DpiHelper.StandardRectToPDFRect(rect1);
  385. CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
  386. e.annotData.Annot.SetRect(cRect);
  387. }
  388. switch (e.annotData.AnnotType)
  389. {
  390. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  391. {
  392. currentParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
  393. (e.annotData.Annot as CPDFWidget).UpdateFormAp();
  394. break;
  395. }
  396. default:
  397. {
  398. currentParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
  399. if (e.annotData.AnnotType != C_ANNOTATION_TYPE.C_ANNOTATION_SOUND)
  400. {
  401. e.annotData.Annot.UpdateAp();
  402. }
  403. break;
  404. }
  405. }
  406. annotHistory.PreviousParam = previousParam;
  407. annotHistory.PDFDoc = viewerTool.GetCPDFViewer().GetDocument();
  408. annotHistory.CurrentParam = currentParam;
  409. annotHistory.Action = HistoryAction.Update;
  410. viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
  411. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  412. AnnotDefaultEditedHandler?.Invoke(this, e);
  413. }
  414. private void ViewerTool_MulitDataChanging(object sender, MultiSelectedData e)
  415. {
  416. }
  417. private void ViewerTool_MulitDataChanged(object sender, MultiSelectedData e)
  418. {
  419. switch (e.ObjectType)
  420. {
  421. case SelectedType.None:
  422. break;
  423. case SelectedType.Annot:
  424. break;
  425. case SelectedType.PDFEdit:
  426. SaveToMulitChanged(e);
  427. break;
  428. default:
  429. break;
  430. }
  431. MulitDefaultEditedHandler?.Invoke(this, e);
  432. }
  433. private void SaveToMulitChanged(MultiSelectedData e)
  434. {
  435. GroupHistory groupHistory = new GroupHistory();
  436. CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
  437. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(e.PageIndex);
  438. CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
  439. cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
  440. List<CPDFEditArea> cPDFEditAreas = cPDFEditPage.GetEditAreaList(true);
  441. for (int i = 0; i < e.MultiObjectIndex.Count; i++)
  442. {
  443. if (e.MultiObjectIndex[i] < cPDFEditAreas.Count)
  444. {
  445. PDFEditHistory pDFEditHistory = new PDFEditHistory();
  446. pDFEditHistory.PageIndex = e.PageIndex;
  447. pDFEditHistory.EditPage = cPDFEditPage;
  448. CRect cRect = cPDFEditAreas[e.MultiObjectIndex[i]].GetFrame();
  449. Point point = DpiHelper.StandardPointToPDFPoint(e.MoveOffset);
  450. cRect.left += (float)point.X;
  451. cRect.right += (float)point.X;
  452. cRect.top += (float)point.Y;
  453. cRect.bottom += (float)point.Y;
  454. cRect.right = cRect.right * e.ZoomX;
  455. cRect.bottom = cRect.bottom * e.ZoomY;
  456. cPDFEditAreas[e.MultiObjectIndex[i]].SetFrame(cRect);
  457. groupHistory.Histories.Add(pDFEditHistory);
  458. }
  459. }
  460. viewerTool.GetCPDFViewer().UndoManager.AddHistory(groupHistory);
  461. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  462. }
  463. private void ViewerTool_AnnotEditDataChanging(object sender, SelectedAnnotData e)
  464. {
  465. }
  466. private void ViewerTool_AnnotEditDataChanged(object sender, SelectedAnnotData e)
  467. {
  468. if (e.annotData == null)
  469. {
  470. return;
  471. }
  472. AnnotHistory annotHistory = ParamConverter.CreateHistory(e.annotData.Annot);
  473. if (annotHistory == null)
  474. {
  475. return;
  476. }
  477. AnnotParam previousParam;
  478. AnnotParam currentParam;
  479. switch (e.annotData.AnnotType)
  480. {
  481. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  482. previousParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
  483. break;
  484. default:
  485. previousParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
  486. break;
  487. }
  488. switch (e.annotData.AnnotType)
  489. {
  490. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  491. if ((e.annotData.Annot as CPDFLineAnnotation).IsMersured())
  492. {
  493. List<Point> cPoints = new List<Point>();
  494. for (int i = 0; i < e.Points.Count; i++)
  495. {
  496. Point cPoint = new Point((float)((e.Points[i].X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
  497. (float)((e.Points[i].Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom));
  498. cPoints.Add(cPoint);
  499. }
  500. Vector lineVector = cPoints[0] - cPoints[1];
  501. Point lineCenterPoint = new Point(
  502. (cPoints[0].X + cPoints[2].X) / 2,
  503. (cPoints[0].Y + cPoints[2].Y) / 2
  504. );
  505. Point crossCenterPoint = new Point(
  506. (cPoints[4].X + cPoints[5].X) / 2,
  507. (cPoints[4].Y + cPoints[5].Y) / 2
  508. );
  509. Rect unionRect = new Rect(cPoints[0], cPoints[2]);
  510. unionRect.Union(cPoints[1]);
  511. unionRect.Union(cPoints[3]);
  512. CPDFLineAnnotation annotLine = (e.annotData.Annot as CPDFLineAnnotation);
  513. annotLine.SetLinePoints(
  514. new CPoint(
  515. (float)(cPoints[0].X / 96D * 72D),
  516. (float)(cPoints[0].Y / 96D * 72D)),
  517. new CPoint(
  518. (float)(cPoints[2].X / 96D * 72D),
  519. (float)(cPoints[2].Y / 96D * 72D)
  520. ));
  521. annotLine.SetRect(new CRect(
  522. (float)(unionRect.Left / 96D * 72D),
  523. (float)(unionRect.Bottom / 96D * 72D),
  524. (float)(unionRect.Right / 96D * 72D),
  525. (float)(unionRect.Top / 96D * 72D)
  526. ));
  527. CPDFDistanceMeasure lineMeasure = annotLine.GetDistanceMeasure();
  528. double saveLength = lineVector.Length / 96D * 72D;
  529. if (lineCenterPoint.Y < crossCenterPoint.Y)
  530. {
  531. lineMeasure.SetLeadLength(-(float)saveLength);
  532. }
  533. if (lineCenterPoint.Y > crossCenterPoint.Y)
  534. {
  535. lineMeasure.SetLeadLength((float)saveLength);
  536. }
  537. if (lineCenterPoint.Y == crossCenterPoint.Y)
  538. {
  539. if (lineCenterPoint.X > crossCenterPoint.X)
  540. {
  541. lineMeasure.SetLeadLength(-(float)saveLength);
  542. }
  543. if (lineCenterPoint.X < crossCenterPoint.X)
  544. {
  545. lineMeasure.SetLeadLength((float)saveLength);
  546. }
  547. }
  548. lineMeasure.UpdateAnnotMeasure();
  549. annotLine.UpdateAp();
  550. if (annotLine.IsMersured())
  551. {
  552. PostMeasureInfo(this, annotLine);
  553. }
  554. }
  555. else
  556. {
  557. Point startPoint = new Point(
  558. (float)((e.Points.First().X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
  559. (float)((e.Points.First().Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom)
  560. );
  561. Point endPoint = new Point(
  562. (float)((e.Points.Last().X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
  563. (float)((e.Points.Last().Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom)
  564. );
  565. CPoint cstartPoint = new CPoint((float)DpiHelper.StandardPointToPDFPoint(startPoint).X, (float)DpiHelper.StandardPointToPDFPoint(startPoint).Y);
  566. CPoint cendPoint = new CPoint((float)DpiHelper.StandardPointToPDFPoint(endPoint).X, (float)DpiHelper.StandardPointToPDFPoint(endPoint).Y);
  567. DpiHelper.StandardPointToPDFPoint(endPoint);
  568. CPDFLineAnnotation annotLine = (e.annotData.Annot as CPDFLineAnnotation);
  569. annotLine.SetLinePoints(cstartPoint, cendPoint);
  570. annotLine.UpdateAp();
  571. }
  572. break;
  573. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  574. {
  575. List<CPoint> cPoints = new List<CPoint>();
  576. for (int i = 0; i < e.Points.Count; i++)
  577. {
  578. Point cPoint = new Point((float)((e.Points[i].X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
  579. (float)((e.Points[i].Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom));
  580. cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(cPoint)));
  581. }
  582. CPDFPolygonAnnotation annotLine = (e.annotData.Annot as CPDFPolygonAnnotation);
  583. annotLine.SetPoints(cPoints);
  584. double left = cPoints.AsEnumerable().Select(x => x.x).Min();
  585. double right = cPoints.AsEnumerable().Select(x => x.x).Max();
  586. double top = cPoints.AsEnumerable().Select(x => x.y).Min();
  587. double bottom = cPoints.AsEnumerable().Select(x => x.y).Max();
  588. annotLine.SetRect(new CRect(
  589. (float)left,
  590. (float)bottom,
  591. (float)right,
  592. (float)top));
  593. annotLine.GetAreaMeasure().UpdateAnnotMeasure();
  594. annotLine.UpdateAp();
  595. if (annotLine.IsMersured())
  596. {
  597. PostMeasureInfo(this, annotLine);
  598. }
  599. }
  600. break;
  601. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  602. {
  603. List<CPoint> cPoints = new List<CPoint>();
  604. for (int i = 0; i < e.Points.Count; i++)
  605. {
  606. Point cPoint = new Point((float)((e.Points[i].X - e.annotData.PaintOffset.X) / e.annotData.CurrentZoom),
  607. (float)((e.Points[i].Y - e.annotData.PaintOffset.Y) / e.annotData.CurrentZoom));
  608. cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(cPoint)));
  609. }
  610. CPDFPolylineAnnotation annotLine = (e.annotData.Annot as CPDFPolylineAnnotation);
  611. annotLine.SetPoints(cPoints);
  612. double left = cPoints.AsEnumerable().Select(x => x.x).Min();
  613. double right = cPoints.AsEnumerable().Select(x => x.x).Max();
  614. double top = cPoints.AsEnumerable().Select(x => x.y).Min();
  615. double bottom = cPoints.AsEnumerable().Select(x => x.y).Max();
  616. annotLine.SetRect(new CRect(
  617. (float)left,
  618. (float)bottom,
  619. (float)right,
  620. (float)top));
  621. annotLine.GetPerimeterMeasure().UpdateAnnotMeasure();
  622. annotLine.UpdateAp();
  623. if (annotLine.IsMersured())
  624. {
  625. PostMeasureInfo(this, annotLine);
  626. }
  627. }
  628. break;
  629. default:
  630. break;
  631. }
  632. switch (e.annotData.AnnotType)
  633. {
  634. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  635. {
  636. currentParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
  637. (e.annotData.Annot as CPDFWidget).UpdateFormAp();
  638. break;
  639. }
  640. default:
  641. {
  642. currentParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), e.annotData.Annot);
  643. if (e.annotData.AnnotType != C_ANNOTATION_TYPE.C_ANNOTATION_SOUND)
  644. {
  645. e.annotData.Annot.UpdateAp();
  646. }
  647. break;
  648. }
  649. }
  650. annotHistory.PreviousParam = previousParam;
  651. annotHistory.PDFDoc = viewerTool.GetCPDFViewer().GetDocument();
  652. annotHistory.CurrentParam = currentParam;
  653. annotHistory.Action = HistoryAction.Update;
  654. viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
  655. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  656. }
  657. private void ViewerTool_MouseLeftButtonUpHandler(object sender, MouseEventObject e)
  658. {
  659. if (viewerTool == null)
  660. return;
  661. viewerTool.DrawEndSelectedMultiRect();
  662. viewerTool.DrawEndPageSelectedRect();
  663. if (currentToolType != ToolType.SelectedPage &&
  664. viewerTool.IsCanSave()&&
  665. cPDFAnnotation?.Type != C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT)
  666. {
  667. viewerTool.PDFViewer.EnableZoom(true);
  668. viewerTool.PDFViewer.CanHorizontallyScroll = true;
  669. viewerTool.PDFViewer.CanVerticallyScroll = true;
  670. }
  671. //To be optimized
  672. if (currentToolType != ToolType.WidgetEdit && currentToolType != ToolType.ContentEdit && viewerTool.IsText())
  673. {
  674. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.IBeam;
  675. }
  676. else if(currentToolType == ToolType.ContentEdit)
  677. {
  678. if(createContentEditType == CPDFEditType.EditText)
  679. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.IBeam;
  680. else
  681. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
  682. }
  683. else
  684. {
  685. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.Arrow;
  686. }
  687. if (currentToolType == ToolType.Customize)
  688. {
  689. viewerTool.CleanCustomizeTool();
  690. }
  691. if (e.hitTestType == MouseHitTestType.SelectRect)
  692. {
  693. List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
  694. {
  695. C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
  696. C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
  697. C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
  698. };
  699. if (list.Contains(e.annotType))
  700. {
  701. viewerTool.DrawEndEditAnnot();
  702. }
  703. else
  704. {
  705. viewerTool.DrawEndSelectedRect();
  706. }
  707. }
  708. switch (currentToolType)
  709. {
  710. case ToolType.CreateAnnot:
  711. CreateAnnotTypeMouseLeftUp(ref e);
  712. break;
  713. case ToolType.WidgetEdit:
  714. {
  715. if (cPDFAnnotation != null)
  716. {
  717. Rect rect = viewerTool.EndDrawWidget();
  718. CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
  719. cPDFAnnotation.SetRect(cRect);
  720. (cPDFAnnotation as CPDFWidget).UpdateFormAp();
  721. CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
  722. AnnotHistory annotHistory = ParamConverter.CreateHistory(cPDFAnnotation);
  723. if (annotHistory == null)
  724. {
  725. return;
  726. }
  727. WidgetParm annotParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), cPDFAnnotation) as WidgetParm;
  728. annotHistory.CurrentParam = annotParam;
  729. annotHistory.PDFDoc = cPDFDocument;
  730. viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
  731. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  732. e.annotType = cPDFAnnotation.Type;
  733. e.IsCreate = true;
  734. dynamic expandData = new ExpandoObject();
  735. expandData.AnnotIndex = annotParam.AnnotIndex;
  736. expandData.PageIndex = annotParam.PageIndex;
  737. expandData.AnnotParam = annotParam;
  738. e.Data = expandData;
  739. }
  740. }
  741. break;
  742. case ToolType.ContentEdit:
  743. {
  744. if (viewerTool.GetLastSelectedRect() != null)
  745. {
  746. viewerTool.DrawEndTextEdit(viewerTool.GetLastSelectedRect());
  747. editSelected = false;
  748. }
  749. else
  750. {
  751. if (createContentEditType == CPDFEditType.EditImage && viewerTool.PDFViewer.GetIsShowStampMouse())
  752. {
  753. Rect stampRect = viewerTool.PDFViewer.GetStampRect();
  754. Point mousePoint = new Point(
  755. stampRect.X - stampRect.Width / 2 * viewerTool.GetCPDFViewer().GetZoom(),
  756. stampRect.Y - stampRect.Height / 2 * viewerTool.GetCPDFViewer().GetZoom()
  757. );
  758. viewerTool.GetCPDFViewer().GetPointPageInfo(mousePoint, out int pageindex, out Rect paintRect, out Rect pageBound);
  759. if (pageindex >= 0)
  760. {
  761. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect((mousePoint.X - pageBound.X) / viewerTool.GetCPDFViewer().GetZoom(), (mousePoint.Y - pageBound.Y) / viewerTool.GetCPDFViewer().GetZoom(), stampRect.Width, stampRect.Height));
  762. CRect SaveRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
  763. CPDFPage docPage = viewerTool.PDFViewer.GetDocument().PageAtIndex(pageindex);
  764. CPDFEditPage EditPage = docPage.GetEditPage();
  765. CPDFEditImageArea cPDFEditImageArea = EditPage.CreateNewImageArea(SaveRect, createImagePath, string.Empty);
  766. if (cPDFEditImageArea == null)
  767. {
  768. byte[] imageData = null;
  769. int imageWidth = 0;
  770. int imageHeight = 0;
  771. PDFHelp.ImagePathToByte(createImagePath, ref imageData, ref imageWidth, ref imageHeight);
  772. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  773. {
  774. cPDFEditImageArea = EditPage.CreateNewImageArea(SaveRect, imageData, imageWidth, imageHeight);
  775. }
  776. }
  777. viewerTool.PDFViewer.UpdateRenderFrame();
  778. PDFEditHistory editHistory = new PDFEditHistory();
  779. editHistory.EditPage = EditPage;
  780. editHistory.PageIndex = pageindex;
  781. EditPage.EndEdit();
  782. viewerTool.PDFViewer.UndoManager.AddHistory(editHistory);
  783. e.IsCreate = true;
  784. }
  785. }
  786. else if (createContentEditType == CPDFEditType.EditText)
  787. {
  788. e.IsCreate = viewerTool.DrawEndTest();
  789. }
  790. else
  791. {
  792. e.IsCreate = true;
  793. }
  794. }
  795. }
  796. break;
  797. case ToolType.Customize:
  798. viewerTool.DrawEndCustomizeTool();
  799. break;
  800. default:
  801. break;
  802. }
  803. viewerTool.DrawEndSelectText();
  804. MouseLeftButtonUpHandler?.Invoke(this, e);
  805. if (viewerTool.IsCanSave())
  806. {
  807. cPDFAnnotation = null;
  808. }
  809. }
  810. private void SaveCurrentAnnot()
  811. {
  812. viewerTool.SetIsCanSave(true);
  813. MouseEventObject e = new MouseEventObject
  814. {
  815. mouseButtonEventArgs = null,
  816. hitTestType = MouseHitTestType.Unknown,
  817. annotType = C_ANNOTATION_TYPE.C_ANNOTATION_NONE,
  818. IsCreate = false
  819. };
  820. switch (currentToolType)
  821. {
  822. case ToolType.CreateAnnot:
  823. CreateAnnotTypeMouseLeftUp(ref e);
  824. break;
  825. case ToolType.WidgetEdit:
  826. {
  827. if (cPDFAnnotation != null)
  828. {
  829. Rect rect = viewerTool.EndDrawWidget();
  830. CRect cRect = new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top);
  831. cPDFAnnotation.SetRect(cRect);
  832. (cPDFAnnotation as CPDFWidget).UpdateFormAp();
  833. CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
  834. AnnotHistory annotHistory = ParamConverter.CreateHistory(cPDFAnnotation);
  835. if (annotHistory == null)
  836. {
  837. return;
  838. }
  839. WidgetParm annotParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), cPDFAnnotation) as WidgetParm;
  840. annotHistory.CurrentParam = annotParam;
  841. annotHistory.PDFDoc = cPDFDocument;
  842. viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
  843. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  844. e.annotType = cPDFAnnotation.Type;
  845. e.IsCreate = true;
  846. dynamic expandData = new ExpandoObject();
  847. expandData.AnnotIndex = annotParam.AnnotIndex;
  848. expandData.PageIndex = annotParam.PageIndex;
  849. expandData.AnnotParam = annotParam;
  850. e.Data = expandData;
  851. }
  852. }
  853. break;
  854. case ToolType.Customize:
  855. viewerTool.DrawEndCustomizeTool();
  856. break;
  857. default:
  858. break;
  859. }
  860. if (viewerTool.IsCanSave())
  861. {
  862. cPDFAnnotation = null;
  863. }
  864. }
  865. #region MouseLeftButtonUpCreateAnnot
  866. private void CreateAnnotTypeMouseLeftUp(ref MouseEventObject e)
  867. {
  868. //Mersured
  869. if (cPDFAnnotation != null)
  870. {
  871. switch (cPDFAnnotation.Type)
  872. {
  873. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  874. {
  875. if ((cPDFAnnotation as CPDFLineAnnotation).IsMersured())
  876. {
  877. MeasureSetting measureSetting = viewerTool.GetMeasureSetting();
  878. if (viewerTool.GetMoveLength() > measureSetting.MoveDetectionLength)
  879. {
  880. viewerTool.SetIsCanSave(true);
  881. }
  882. }
  883. }
  884. break;
  885. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  886. if ((cPDFAnnotation as CPDFPolygonAnnotation).IsMersured())
  887. {
  888. DefaultSettingParam defSetting = viewerTool.GetDefaultSettingParam();
  889. if (defSetting.IsCreateSquarePolygonMeasure)
  890. {
  891. MeasureSetting measureSetting = viewerTool.GetMeasureSetting();
  892. if (viewerTool.GetMoveLength() > measureSetting.MoveDetectionLength)
  893. {
  894. viewerTool.SetIsCanSave(true);
  895. }
  896. }
  897. }
  898. break;
  899. default:
  900. break;
  901. }
  902. }
  903. if (viewerTool.IsCanSave())
  904. {
  905. SaveCreateAnnotation(ref cPDFAnnotation, ref e);
  906. viewerTool.PDFViewer.EnableZoom(true);
  907. viewerTool.PDFViewer.CanHorizontallyScroll = true;
  908. viewerTool.PDFViewer.CanVerticallyScroll = true;
  909. }
  910. }
  911. private void SaveCreateAnnotation(ref CPDFAnnotation annotation, ref MouseEventObject e)
  912. {
  913. if (annotation == null)
  914. {
  915. return;
  916. }
  917. Point StartPoint = viewerTool.GetStartPoint();
  918. Point EndPoint = viewerTool.GetEndPoint();
  919. List<Point> points = viewerTool.GetInkDrawPoints();
  920. List<Point> measurepoints = viewerTool.GetMeasureDrawPoints();
  921. annotation.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  922. annotation.SetModifyDate(PDFHelp.GetCurrentPdfTime());
  923. Rect rect = viewerTool.EndDrawAnnot();
  924. if (annotation != null)
  925. {
  926. switch (annotation.Type)
  927. {
  928. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  929. SaveInkCreateAnnotation(ref annotation, points);
  930. e.IsCreate = true;
  931. e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
  932. e.Data = GetAnnotExpandObject(annotation);
  933. if (e.mouseButtonEventArgs!=null)
  934. {
  935. MouseLeftButtonUpHandler?.Invoke(this, e);
  936. }
  937. annotation = null;
  938. return;
  939. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  940. e.IsCreate = true;
  941. e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT;
  942. e.Data = GetAnnotExpandObject(annotation);
  943. if (e.mouseButtonEventArgs != null)
  944. {
  945. MouseLeftButtonUpHandler?.Invoke(this, e);
  946. }
  947. return;
  948. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  949. {
  950. if ((annotation as CPDFLineAnnotation).IsMersured())
  951. {
  952. if (measurepoints.Count > 1)
  953. {
  954. (annotation as CPDFLineAnnotation).SetLinePoints(new CPoint(
  955. (float)DpiHelper.StandardNumToPDFNum(measurepoints[0].X),
  956. (float)DpiHelper.StandardNumToPDFNum(measurepoints[0].Y)),
  957. new CPoint((float)DpiHelper.StandardNumToPDFNum(measurepoints[1].X),
  958. (float)DpiHelper.StandardNumToPDFNum(measurepoints[1].Y)));
  959. (annotation as CPDFLineAnnotation).GetDistanceMeasure().UpdateAnnotMeasure();
  960. PostMeasureInfo(this, annotation);
  961. }
  962. else
  963. {
  964. annotation.ReleaseAnnot();
  965. if (e.mouseButtonEventArgs != null)
  966. {
  967. MouseLeftButtonUpHandler?.Invoke(this, e);
  968. }
  969. annotation = null;
  970. return;
  971. }
  972. }
  973. else
  974. {
  975. if (EndPoint != new Point(-1, -1))
  976. {
  977. (annotation as CPDFLineAnnotation).SetLinePoints(new CPoint((float)StartPoint.X, (float)StartPoint.Y), new CPoint((float)EndPoint.X, (float)EndPoint.Y));
  978. }
  979. else
  980. {
  981. annotation.ReleaseAnnot();
  982. if (e.mouseButtonEventArgs != null)
  983. {
  984. MouseLeftButtonUpHandler?.Invoke(this, e);
  985. }
  986. annotation = null;
  987. return;
  988. }
  989. }
  990. }
  991. break;
  992. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  993. {
  994. if ((annotation as CPDFPolygonAnnotation).IsMersured())
  995. {
  996. List<CPoint> cPoints = new List<CPoint>();
  997. foreach (Point item in measurepoints)
  998. {
  999. cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
  1000. }
  1001. (annotation as CPDFPolygonAnnotation).SetPoints(cPoints);
  1002. (annotation as CPDFPolygonAnnotation).GetAreaMeasure().UpdateAnnotMeasure();
  1003. PostMeasureInfo(this, annotation);
  1004. }
  1005. }
  1006. break;
  1007. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  1008. {
  1009. if ((annotation as CPDFPolylineAnnotation).IsMersured())
  1010. {
  1011. List<CPoint> cPoints = new List<CPoint>();
  1012. foreach (Point item in measurepoints)
  1013. {
  1014. cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
  1015. }
  1016. (annotation as CPDFPolylineAnnotation).SetPoints(cPoints);
  1017. (annotation as CPDFPolylineAnnotation).GetPerimeterMeasure().UpdateAnnotMeasure();
  1018. PostMeasureInfo(this, annotation);
  1019. }
  1020. }
  1021. break;
  1022. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  1023. if (rect.Width > 0 && rect.Height > 0)
  1024. {
  1025. List<CRect> coreRectList = new List<CRect>
  1026. {
  1027. new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top)
  1028. };
  1029. (annotation as CPDFRedactAnnotation).SetQuardRects(coreRectList);
  1030. }
  1031. break;
  1032. default:
  1033. break;
  1034. }
  1035. if (rect.Width <= 0 && rect.Height <= 0)
  1036. {
  1037. switch (createAnnotType)
  1038. {
  1039. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  1040. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  1041. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  1042. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  1043. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  1044. {
  1045. annotation.RemoveAnnot();
  1046. viewerTool.DrawEndSelectText();
  1047. TextSelectInfo textSelectInfo = viewerTool.GetTextSelectInfo();
  1048. if (textSelectInfo.PageSelectPointList.Count > 0)
  1049. {
  1050. viewerTool.DrawEndSelectText();
  1051. viewerTool.RemoveSelectTextData();
  1052. GroupHistory historyData = null;
  1053. viewerTool.CreateAnnotForSelectText(textSelectInfo, createAnnotType, out historyData);
  1054. List<object> dataList = new List<object>();
  1055. if (historyData != null && historyData.Histories.Count > 0)
  1056. {
  1057. foreach (IHistory historyItem in historyData.Histories)
  1058. {
  1059. AnnotHistory checkHistory = historyItem as AnnotHistory;
  1060. if (checkHistory == null || checkHistory.CurrentParam == null)
  1061. {
  1062. continue;
  1063. }
  1064. dynamic expandData = new ExpandoObject();
  1065. expandData.AnnotIndex = checkHistory.CurrentParam.AnnotIndex;
  1066. expandData.PageIndex = checkHistory.CurrentParam.PageIndex;
  1067. expandData.AnnotParam = checkHistory.CurrentParam;
  1068. dataList.Add(expandData);
  1069. }
  1070. }
  1071. e.annotType = createAnnotType;
  1072. e.IsCreate = true;
  1073. if (dataList.Count > 0)
  1074. {
  1075. e.Data = dataList.Count > 1 ? dataList : dataList[0];
  1076. }
  1077. }
  1078. if(createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_REDACT && textSelectInfo.PageSelectPointList.Count ==0)
  1079. {
  1080. viewerTool.GetCPDFViewer().UpdateAnnotFrame();
  1081. }
  1082. }
  1083. break;
  1084. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  1085. {
  1086. if (!viewerTool.PDFViewer.GetIsShowStampMouse())
  1087. {
  1088. break;
  1089. }
  1090. Rect stampRect = viewerTool.PDFViewer.GetStampRect();
  1091. Point mousePoint = new Point(
  1092. stampRect.X - stampRect.Width / 2 * viewerTool.GetCPDFViewer().GetZoom(),
  1093. stampRect.Y - stampRect.Height / 2 * viewerTool.GetCPDFViewer().GetZoom()
  1094. );
  1095. viewerTool.GetCPDFViewer().GetPointPageInfo(mousePoint, out int pageindex, out Rect paintRect, out Rect pageBound);
  1096. if (pageindex < 0)
  1097. {
  1098. annotation.RemoveAnnot();
  1099. annotation = null;
  1100. return;
  1101. }
  1102. else
  1103. {
  1104. CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
  1105. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageindex);
  1106. Point cropPoint = new Point();
  1107. if (viewerTool.GetCPDFViewer().GetIsCrop())
  1108. {
  1109. CRect cropRect = cPDFPage.GetCropBounds();
  1110. cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
  1111. cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
  1112. }
  1113. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(
  1114. (mousePoint.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
  1115. (mousePoint.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
  1116. stampRect.Width, stampRect.Height)
  1117. );
  1118. CRect cStampRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
  1119. annotation.SetRect(cStampRect);
  1120. annotation.UpdateAp();
  1121. e.IsCreate = true;
  1122. e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  1123. e.Data = GetAnnotExpandObject(annotation);
  1124. StampAnnotHistory freeTextAnnotHistory = new StampAnnotHistory();
  1125. AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
  1126. annotParam.AnnotIndex = annotation.Page.GetAnnotCount() - 1;
  1127. freeTextAnnotHistory.CurrentParam = (StampParam)annotParam;
  1128. freeTextAnnotHistory.PDFDoc = viewerTool.GetCPDFViewer().GetDocument();
  1129. viewerTool.GetCPDFViewer().UndoManager.AddHistory(freeTextAnnotHistory);
  1130. }
  1131. viewerTool.GetCPDFViewer().UpdateAnnotFrame();
  1132. }
  1133. break;
  1134. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  1135. {
  1136. Point point = Mouse.GetPosition(viewerTool.PDFViewer);
  1137. viewerTool.GetCPDFViewer().GetPointPageInfo(point, out int pageindex, out Rect paintRect, out Rect pageBound);
  1138. if (pageindex < 0)
  1139. {
  1140. annotation.RemoveAnnot();
  1141. annotation = null;
  1142. return;
  1143. }
  1144. else
  1145. {
  1146. CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
  1147. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageindex);
  1148. Point cropPoint = new Point();
  1149. if (viewerTool.GetCPDFViewer().GetIsCrop())
  1150. {
  1151. CRect cropRect = cPDFPage.GetCropBounds();
  1152. cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
  1153. cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
  1154. }
  1155. CRect x = annotation.GetRect();
  1156. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(
  1157. (point.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
  1158. (point.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
  1159. x.width(), x.height())
  1160. );
  1161. PDFRect.X = PDFRect.X - x.width() / 2;
  1162. PDFRect.Y = PDFRect.Y - x.height() / 2;
  1163. CRect cStampRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
  1164. annotation.SetRect(cStampRect);
  1165. viewerTool.GetCPDFViewer().UpdateAnnotFrame();
  1166. e.IsCreate = true;
  1167. e.annotType = createAnnotType;
  1168. e.Data = GetAnnotExpandObject(annotation);
  1169. }
  1170. }
  1171. break;
  1172. default:
  1173. break;
  1174. }
  1175. //annotation.ReleaseAnnot();
  1176. if (e.mouseButtonEventArgs != null)
  1177. {
  1178. MouseLeftButtonUpHandler?.Invoke(this, e);
  1179. }
  1180. annotation = null;
  1181. return;
  1182. }
  1183. //CRect cRect = new CRect((float)rect.Left + annotation.GetBorderWidth(), (float)rect.Bottom - annotation.GetBorderWidth(), (float)rect.Right - annotation.GetBorderWidth(), (float)rect.Top + annotation.GetBorderWidth());
  1184. CRect cRect = new CRect(
  1185. (float)rect.Left,
  1186. (float)rect.Bottom,
  1187. (float)rect.Right,
  1188. (float)rect.Top);
  1189. annotation.SetRect(cRect);
  1190. annotation.UpdateAp();
  1191. AnnotHistory annotHistory = ParamConverter.CreateHistory(annotation);
  1192. if (annotHistory == null)
  1193. {
  1194. return;
  1195. }
  1196. AnnotParam currentParam;
  1197. switch (annotation.Type)
  1198. {
  1199. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  1200. currentParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
  1201. break;
  1202. default:
  1203. currentParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
  1204. break;
  1205. }
  1206. annotHistory.CurrentParam = currentParam;
  1207. annotHistory.Action = HistoryAction.Add;
  1208. annotHistory.PDFDoc = viewerTool.PDFViewer.GetDocument();
  1209. viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
  1210. viewerTool.ClearDrawAnnot();
  1211. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  1212. {
  1213. e.annotType = annotation.Type;
  1214. e.IsCreate = true;
  1215. dynamic expandData = new ExpandoObject();
  1216. expandData.AnnotIndex = currentParam.AnnotIndex;
  1217. expandData.PageIndex = currentParam.PageIndex;
  1218. expandData.AnnotParam = currentParam;
  1219. e.Data = expandData;
  1220. }
  1221. }
  1222. }
  1223. internal void PostMeasureInfo(object sender, CPDFAnnotation rawAnnot)
  1224. {
  1225. if (rawAnnot == null)
  1226. {
  1227. return;
  1228. }
  1229. try
  1230. {
  1231. if (rawAnnot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
  1232. {
  1233. CPDFLineAnnotation lineAnnot = rawAnnot as CPDFLineAnnotation;
  1234. if (lineAnnot.IsMersured() && lineAnnot.Points != null && lineAnnot.Points.Count() == 2)
  1235. {
  1236. CPDFDistanceMeasure lineMeasure = lineAnnot.GetDistanceMeasure();
  1237. CPDFMeasureInfo measureInfo = lineMeasure.MeasureInfo;
  1238. Vector standVector = new Vector(1, 0);
  1239. Point startPoint = new Point(lineAnnot.Points[0].x, lineAnnot.Points[0].y);
  1240. Point endPoint = new Point(lineAnnot.Points[1].x, lineAnnot.Points[1].y);
  1241. Vector movevector = endPoint - startPoint;
  1242. double showLenght = lineMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_LENGTH);
  1243. MeasureEventArgs measureEvent = new MeasureEventArgs();
  1244. measureEvent.Angle = (int)Math.Abs(Vector.AngleBetween(movevector, standVector));
  1245. measureEvent.RulerTranslateUnit = measureInfo.RulerTranslateUnit;
  1246. measureEvent.RulerTranslate = measureInfo.RulerTranslate;
  1247. measureEvent.RulerBase = measureInfo.RulerBase;
  1248. measureEvent.RulerBaseUnit = measureInfo.RulerBaseUnit;
  1249. measureEvent.MousePos = new Point(
  1250. (int)Math.Abs(movevector.X),
  1251. (int)Math.Abs(movevector.Y));
  1252. measureEvent.Type = CPDFMeasureType.CPDF_DISTANCE_MEASURE;
  1253. NumberFormatInfo formatInfo = new NumberFormatInfo();
  1254. formatInfo.NumberDecimalDigits = Math.Abs(measureInfo.Precision).ToString().Length - 1;
  1255. measureEvent.Distance = showLenght.ToString("N", formatInfo) + " " + measureInfo.RulerTranslateUnit;
  1256. measureEvent.Precision = GetMeasureShowPrecision(measureInfo.Precision);
  1257. viewerTool?.InvokeMeasureChangeEvent(sender, measureEvent);
  1258. }
  1259. }
  1260. if (rawAnnot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE)
  1261. {
  1262. CPDFPolylineAnnotation polylineAnnot = rawAnnot as CPDFPolylineAnnotation;
  1263. if (polylineAnnot.IsMersured() && polylineAnnot.Points != null && polylineAnnot.Points.Count() >= 2)
  1264. {
  1265. double totalInch = 0;
  1266. for (int i = 0; i < polylineAnnot.Points.Count - 1; i++)
  1267. {
  1268. Point endLinePoint = new Point(
  1269. polylineAnnot.Points[i + 1].x,
  1270. polylineAnnot.Points[i + 1].y
  1271. );
  1272. Point startLinePoint = new Point(
  1273. polylineAnnot.Points[i].x,
  1274. polylineAnnot.Points[i].y
  1275. );
  1276. Vector subVector = endLinePoint - startLinePoint;
  1277. totalInch += subVector.Length;
  1278. }
  1279. totalInch = totalInch / 72D;
  1280. CPDFPerimeterMeasure lineMeasure = polylineAnnot.GetPerimeterMeasure();
  1281. CPDFMeasureInfo measureInfo = lineMeasure.MeasureInfo;
  1282. double showLenght = lineMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_LENGTH);
  1283. MeasureEventArgs measureEvent = new MeasureEventArgs();
  1284. measureEvent.Angle = 0;
  1285. measureEvent.RulerTranslateUnit = measureInfo.RulerTranslateUnit;
  1286. measureEvent.RulerTranslate = measureInfo.RulerTranslate;
  1287. measureEvent.RulerBase = measureInfo.RulerBase;
  1288. measureEvent.RulerBaseUnit = measureInfo.RulerBaseUnit;
  1289. measureEvent.Precision = GetMeasureShowPrecision(measureInfo.Precision);
  1290. measureEvent.Type = CPDFMeasureType.CPDF_PERIMETER_MEASURE;
  1291. NumberFormatInfo formatInfo = new NumberFormatInfo();
  1292. formatInfo.NumberDecimalDigits = Math.Abs(measureInfo.Precision).ToString().Length - 1;
  1293. measureEvent.Distance = showLenght.ToString("N", formatInfo) + " " + measureInfo.RulerTranslateUnit;
  1294. viewerTool?.InvokeMeasureChangeEvent(sender, measureEvent);
  1295. }
  1296. }
  1297. if (rawAnnot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON)
  1298. {
  1299. CPDFPolygonAnnotation polygonAnnot = rawAnnot as CPDFPolygonAnnotation;
  1300. if (polygonAnnot.IsMersured() && polygonAnnot.Points != null && polygonAnnot.Points.Count() >= 2)
  1301. {
  1302. double totalInch = 0;
  1303. for (int i = 0; i < polygonAnnot.Points.Count - 1; i++)
  1304. {
  1305. Point endLinePoint = new Point(
  1306. polygonAnnot.Points[i + 1].x,
  1307. polygonAnnot.Points[i + 1].y
  1308. );
  1309. Point startLinePoint = new Point(
  1310. polygonAnnot.Points[i].x,
  1311. polygonAnnot.Points[i].y
  1312. );
  1313. Vector subVector = endLinePoint - startLinePoint;
  1314. totalInch += subVector.Length;
  1315. }
  1316. totalInch = totalInch / 72D;
  1317. CPDFAreaMeasure areaMeasure = polygonAnnot.GetAreaMeasure();
  1318. CPDFMeasureInfo measureInfo = areaMeasure.MeasureInfo;
  1319. double showLenght = areaMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_LENGTH);
  1320. MeasureEventArgs measureEvent = new MeasureEventArgs();
  1321. measureEvent.Angle = 0;
  1322. measureEvent.RulerTranslateUnit = measureInfo.RulerTranslateUnit;
  1323. measureEvent.RulerTranslate = measureInfo.RulerTranslate;
  1324. measureEvent.RulerBase = measureInfo.RulerBase;
  1325. measureEvent.RulerBaseUnit = measureInfo.RulerBaseUnit;
  1326. measureEvent.Precision = GetMeasureShowPrecision(measureInfo.Precision);
  1327. measureEvent.Type = CPDFMeasureType.CPDF_AREA_MEASURE;
  1328. NumberFormatInfo formatInfo = new NumberFormatInfo();
  1329. formatInfo.NumberDecimalDigits = Math.Abs(measureInfo.Precision).ToString().Length - 1;
  1330. measureEvent.Distance = showLenght.ToString("N", formatInfo) + " " + measureInfo.RulerTranslateUnit;
  1331. double area = areaMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_AREA);
  1332. measureEvent.Area = string.Format("{0} sq {1}", GetPrecisionData(area, measureEvent.Precision), measureEvent.RulerTranslateUnit);
  1333. viewerTool?.InvokeMeasureChangeEvent(sender, measureEvent);
  1334. }
  1335. }
  1336. }
  1337. catch (Exception e)
  1338. {
  1339. }
  1340. }
  1341. public string GetPrecisionData(double number, double precision)
  1342. {
  1343. NumberFormatInfo formatInfo = new NumberFormatInfo();
  1344. formatInfo.NumberDecimalDigits = 2;
  1345. if (precision == 1)
  1346. {
  1347. formatInfo.NumberDecimalDigits = 0;
  1348. }
  1349. if (precision == 0.1)
  1350. {
  1351. formatInfo.NumberDecimalDigits = 1;
  1352. }
  1353. if (precision == 0.01)
  1354. {
  1355. formatInfo.NumberDecimalDigits = 2;
  1356. }
  1357. if (precision == 0.001)
  1358. {
  1359. formatInfo.NumberDecimalDigits = 3;
  1360. }
  1361. if (precision == 0.0001)
  1362. {
  1363. formatInfo.NumberDecimalDigits = 4;
  1364. }
  1365. if (precision == 0.00001)
  1366. {
  1367. formatInfo.NumberDecimalDigits = 5;
  1368. }
  1369. return number.ToString("N", formatInfo);
  1370. }
  1371. internal double GetMeasureShowPrecision(int precision)
  1372. {
  1373. if (precision == CPDFMeasure.PRECISION_VALUE_ZERO)
  1374. {
  1375. return 1;
  1376. }
  1377. if (CPDFMeasure.PRECISION_VALUE_ONE == precision)
  1378. {
  1379. return 0.1;
  1380. }
  1381. if (CPDFMeasure.PRECISION_VALUE_TWO == precision)
  1382. {
  1383. return 0.01;
  1384. }
  1385. if (CPDFMeasure.PRECISION_VALUE_THREE == precision)
  1386. {
  1387. return 0.001;
  1388. }
  1389. if (CPDFMeasure.PRECISION_VALUE_FOUR == precision)
  1390. {
  1391. return 0.0001;
  1392. }
  1393. return 0;
  1394. }
  1395. private object GetAnnotExpandObject(CPDFAnnotation annot)
  1396. {
  1397. if (annot != null && annot.IsValid())
  1398. {
  1399. try
  1400. {
  1401. AnnotParam annotParam = null;
  1402. if (annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  1403. {
  1404. annotParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), annot);
  1405. }
  1406. else
  1407. {
  1408. annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annot);
  1409. }
  1410. if (annotParam != null)
  1411. {
  1412. annotParam.AnnotIndex = annot.Page.GetAnnotCount() - 1;
  1413. dynamic expandData = new ExpandoObject();
  1414. expandData.AnnotIndex = annotParam.AnnotIndex;
  1415. expandData.PageIndex = annot.Page.PageIndex;
  1416. expandData.AnnotParam = annotParam;
  1417. return expandData;
  1418. }
  1419. }
  1420. catch (Exception ex)
  1421. {
  1422. }
  1423. }
  1424. return null;
  1425. }
  1426. private void SaveInkCreateAnnotation(ref CPDFAnnotation annotation, List<Point> points)
  1427. {
  1428. // Creation of non-custom stamps
  1429. if (!viewerTool.PDFViewer.GetIsShowStampMouse())
  1430. {
  1431. if (points.Count < 5)
  1432. {
  1433. annotation.RemoveAnnot();
  1434. annotation = null;
  1435. return;
  1436. }
  1437. List<List<CPoint>> inkPathList = new List<List<CPoint>>();
  1438. List<CPoint> inkPath = new List<CPoint>();
  1439. foreach (Point inkNode in points)
  1440. {
  1441. inkPath.Add(new CPoint((float)DpiHelper.StandardNumToPDFNum(inkNode.X), (float)DpiHelper.StandardNumToPDFNum(inkNode.Y)));
  1442. }
  1443. inkPathList.Add(inkPath);
  1444. (annotation as CPDFInkAnnotation).SetInkPath(inkPathList);
  1445. (annotation as CPDFInkAnnotation).UpdateAp();
  1446. }
  1447. else
  1448. {
  1449. Rect stampRect = viewerTool.PDFViewer.GetStampRect();
  1450. Point mousePoint = new Point(
  1451. stampRect.X - stampRect.Width / 2 * viewerTool.GetCPDFViewer().GetZoom(),
  1452. stampRect.Y - stampRect.Height / 2 * viewerTool.GetCPDFViewer().GetZoom()
  1453. );
  1454. viewerTool.GetCPDFViewer().GetPointPageInfo(mousePoint, out int pageindex, out Rect paintRect, out Rect pageBound);
  1455. if (pageindex < 0)
  1456. {
  1457. annotation.RemoveAnnot();
  1458. annotation = null;
  1459. return;
  1460. }
  1461. else
  1462. {
  1463. CPDFPage cPDFPage = viewerTool.GetCPDFViewer().GetDocument().PageAtIndex(pageindex);
  1464. Point cropPoint = new Point();
  1465. if (viewerTool.GetCPDFViewer().GetIsCrop())
  1466. {
  1467. CRect cropRect = cPDFPage.GetCropBounds();
  1468. cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
  1469. cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
  1470. }
  1471. // Move the point
  1472. CPoint cPoint = new CPoint(
  1473. (float)((mousePoint.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom()),
  1474. (float)((mousePoint.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom()));
  1475. List<List<CPoint>> cPoints = (annotation as CPDFInkAnnotation).InkPath;
  1476. List<List<CPoint>> savePointList = new List<List<CPoint>>();
  1477. foreach (List<CPoint> inkNode in cPoints)
  1478. {
  1479. List<CPoint> savePoints = new List<CPoint>();
  1480. foreach (CPoint addPoint in inkNode)
  1481. {
  1482. savePoints.Add(
  1483. new CPoint(
  1484. (addPoint.x + (float)DpiHelper.StandardNumToPDFNum(cPoint.x)),
  1485. (addPoint.y + (float)DpiHelper.StandardNumToPDFNum(cPoint.y))
  1486. ));
  1487. }
  1488. if (savePoints.Count > 0)
  1489. {
  1490. savePointList.Add(savePoints);
  1491. }
  1492. }
  1493. (annotation as CPDFInkAnnotation).SetInkPath(savePointList);
  1494. (annotation as CPDFInkAnnotation).UpdateAp();
  1495. }
  1496. }
  1497. viewerTool.ClearDrawAnnot();
  1498. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  1499. InkAnnotHistory inkAnnotHistory = new InkAnnotHistory();
  1500. AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.PDFViewer.GetDocument(), cPDFAnnotation);
  1501. annotParam.AnnotIndex = cPDFAnnotation.Page.GetAnnotCount() - 1;
  1502. inkAnnotHistory.CurrentParam = (InkParam)annotParam;
  1503. inkAnnotHistory.PDFDoc = viewerTool.PDFViewer.GetDocument();
  1504. viewerTool.GetCPDFViewer().UndoManager.AddHistory(inkAnnotHistory);
  1505. return;
  1506. }
  1507. #endregion
  1508. private void ViewerTool_MouseMoveHandler(object sender, MouseEventObject e)
  1509. {
  1510. if (viewerTool == null)
  1511. return;
  1512. viewerTool.DrawMoveSelectedMultiRect();
  1513. viewerTool.DrawMovePageSelectedRect();
  1514. if (currentToolType != ToolType.ContentEdit)
  1515. {
  1516. if (e.hitTestType == MouseHitTestType.SelectRect)
  1517. {
  1518. List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
  1519. {
  1520. C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
  1521. C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
  1522. C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
  1523. };
  1524. Cursor oldCursor = viewerTool.Cursor;
  1525. Cursor newCursor = viewerTool.GetMoveSelectedRectCursor();
  1526. if (oldCursor != newCursor || viewerTool.PDFViewer.Cursor!=newCursor)
  1527. {
  1528. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = newCursor;
  1529. }
  1530. //viewerTool.PDFViewer.Cursor = viewerTool.Cursor= viewerTool.GetMoveSelectedRectCursor();
  1531. if (list.Contains(e.annotType))
  1532. {
  1533. viewerTool.DrawMoveEditAnnot();
  1534. }
  1535. else
  1536. {
  1537. if (e.annotType != C_ANNOTATION_TYPE.C_ANNOTATION_LINK)
  1538. {
  1539. bool tag = viewerTool.DrawMoveSelectedRect();
  1540. if (currentToolType == ToolType.WidgetEdit)
  1541. {
  1542. BaseWidget hitWidget = viewerTool?.GetCPDFViewer()?.AnnotHitTest() as BaseWidget;
  1543. if (hitWidget == null)
  1544. {
  1545. viewerTool.MoveDrawWidget(tag);
  1546. }
  1547. else
  1548. {
  1549. viewerTool.MoveDrawWidget(true);
  1550. }
  1551. }
  1552. }
  1553. }
  1554. }
  1555. else
  1556. {
  1557. if (currentToolType == ToolType.CreateAnnot)
  1558. {
  1559. if (!viewerTool.PDFViewer.GetIsShowStampMouse())
  1560. {
  1561. // 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.
  1562. viewerTool.MoveDrawAnnot();
  1563. }
  1564. switch (createAnnotType)
  1565. {
  1566. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  1567. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  1568. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  1569. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  1570. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  1571. viewerTool.DrawMoveSelectText(false);
  1572. break;
  1573. default:
  1574. break;
  1575. }
  1576. }
  1577. else if (currentToolType == ToolType.WidgetEdit)
  1578. {
  1579. BaseWidget hitWidget = viewerTool?.GetCPDFViewer()?.AnnotHitTest() as BaseWidget;
  1580. if (hitWidget == null)
  1581. {
  1582. viewerTool.MoveDrawWidget(false);
  1583. }
  1584. else
  1585. {
  1586. viewerTool.MoveDrawWidget(true);
  1587. }
  1588. }
  1589. else if (e.hitTestType == MouseHitTestType.Unknown && currentToolType != ToolType.WidgetEdit)
  1590. {
  1591. if (currentToolType == ToolType.Customize)
  1592. {
  1593. viewerTool.DrawMoveCustomizeTool();
  1594. }
  1595. else
  1596. {
  1597. TextSelectInfo textInfo = viewerTool.GetTextSelectInfo();
  1598. if ((textInfo.StartPage != -1 && e.mouseButtonEventArgs.LeftButton == MouseButtonState.Pressed) || viewerTool.IsText())
  1599. {
  1600. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.IBeam;
  1601. }
  1602. else
  1603. {
  1604. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.Arrow;
  1605. }
  1606. }
  1607. }
  1608. }
  1609. if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_NONE)
  1610. {
  1611. viewerTool.DrawMoveSelectText(false);
  1612. }
  1613. }
  1614. else
  1615. {
  1616. if (createContentEditType != CPDFEditType.EditImage)
  1617. {
  1618. Cursor cursor = Cursors.Arrow;
  1619. if (viewerTool.GetLastSelectedRect() != null)
  1620. {
  1621. if (editSelected)
  1622. {
  1623. viewerTool.DrawMoveTextEdit(viewerTool.GetLastSelectedRect(), clickEditSelected);
  1624. if(clickEditSelected)
  1625. cursor = Cursors.IBeam;
  1626. else
  1627. cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
  1628. }
  1629. else
  1630. {
  1631. cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
  1632. }
  1633. }
  1634. else
  1635. {
  1636. viewerTool.HideDrawSelectedMultiRect();
  1637. cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
  1638. }
  1639. if (cursor == Cursors.Arrow && createContentEditType == CPDFEditType.EditText)
  1640. {
  1641. cursor = Cursors.IBeam;
  1642. }
  1643. viewerTool.Cursor = cursor;
  1644. viewerTool.PDFViewer.Cursor = cursor;
  1645. }
  1646. else
  1647. {
  1648. //viewerTool.Cursor = Cursors.None;
  1649. //viewerTool.PDFViewer.Cursor = Cursors.None;
  1650. }
  1651. }
  1652. MouseMoveHandler?.Invoke(this, e);
  1653. }
  1654. private void MakeTextBoxReadOnly(TextBox textBox)
  1655. {
  1656. try
  1657. {
  1658. DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
  1659. FreeTextParam textParam = defaultSettingParam.FreeTextParamDef;
  1660. if(textParam.IsReadOnly)
  1661. {
  1662. textBox.IsReadOnly = true;
  1663. }
  1664. }
  1665. catch (Exception ex)
  1666. {
  1667. }
  1668. }
  1669. private void ViewerTool_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  1670. {
  1671. viewerTool.RemoveSelectTextData();
  1672. viewerTool.ReDrawSelectText();
  1673. viewerTool.HideWidgetHitPop();
  1674. switch (e.hitTestType)
  1675. {
  1676. case MouseHitTestType.Unknown:
  1677. {
  1678. if (currentToolType == ToolType.CreateAnnot)
  1679. {
  1680. switch ((e.mouseButtonEventArgs as MouseButtonEventArgs).ClickCount)
  1681. {
  1682. case 1:
  1683. if (viewerTool.IsCanSave())
  1684. {
  1685. cPDFAnnotation = viewerTool.StartDrawAnnot(createAnnotType);
  1686. viewerTool.CreateDefaultAnnot(cPDFAnnotation, createAnnotType, null);
  1687. if (cPDFAnnotation != null && createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT)
  1688. {
  1689. TextBox textui = viewerTool.CreateTextBox();
  1690. MakeTextBoxReadOnly(textui);
  1691. }
  1692. switch (createAnnotType)
  1693. {
  1694. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  1695. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  1696. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  1697. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  1698. {
  1699. viewerTool.DrawStartSelectText();
  1700. viewerTool.EndDrawAnnot();
  1701. }
  1702. break;
  1703. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  1704. if (viewerTool.IsText())
  1705. {
  1706. viewerTool.DrawStartSelectText();
  1707. viewerTool.EndDrawAnnot();
  1708. }
  1709. break;
  1710. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  1711. {
  1712. bool cansave = true;
  1713. CPDFLineAnnotation LineAnnotation = (cPDFAnnotation as CPDFLineAnnotation);
  1714. if (LineAnnotation != null)
  1715. {
  1716. if (LineAnnotation.IsMersured())
  1717. {
  1718. cansave = false;
  1719. }
  1720. }
  1721. viewerTool.SetIsCanSave(cansave);
  1722. }
  1723. break;
  1724. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  1725. {
  1726. bool cansave = true;
  1727. CPDFPolygonAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolygonAnnotation);
  1728. PolyAnnotation?.IsMersured();
  1729. if (PolyAnnotation != null)
  1730. {
  1731. if (PolyAnnotation.IsMersured())
  1732. {
  1733. cansave = false;
  1734. }
  1735. }
  1736. viewerTool.SetIsCanSave(cansave);
  1737. }
  1738. break;
  1739. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  1740. {
  1741. bool cansave = true;
  1742. CPDFPolylineAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolylineAnnotation);
  1743. PolyAnnotation?.IsMersured();
  1744. if (PolyAnnotation != null)
  1745. {
  1746. if (PolyAnnotation.IsMersured())
  1747. {
  1748. cansave = false;
  1749. }
  1750. }
  1751. viewerTool.SetIsCanSave(cansave);
  1752. }
  1753. break;
  1754. default:
  1755. break;
  1756. }
  1757. }
  1758. else
  1759. {
  1760. viewerTool.MultipleClick();
  1761. e.IsDrawing=true;
  1762. }
  1763. break;
  1764. case 2:
  1765. if (currentToolType != ToolType.Customize)
  1766. {
  1767. if (!viewerTool.IsCanSave())
  1768. {
  1769. viewerTool.SetIsCanSave(true);
  1770. }
  1771. }
  1772. break;
  1773. }
  1774. }
  1775. else if (currentToolType == ToolType.WidgetEdit)
  1776. {
  1777. cPDFAnnotation = viewerTool.StartDrawWidget(createWidgetType);
  1778. viewerTool.CreateDefaultWidget(cPDFAnnotation, createWidgetType, null);
  1779. }
  1780. else if (currentToolType == ToolType.Pan || currentToolType == ToolType.Viewer)
  1781. {
  1782. if (viewerTool.IsText())
  1783. {
  1784. viewerTool.DrawStartSelectText();
  1785. e.hitTestType = MouseHitTestType.Text;
  1786. }
  1787. }
  1788. else if (currentToolType == ToolType.Customize)
  1789. {
  1790. viewerTool.DrawStartCustomizeTool(CustomizeToolType.kErase);
  1791. }
  1792. viewerTool.CleanSelectedRect();
  1793. viewerTool.CleanEditAnnot();
  1794. }
  1795. break;
  1796. case MouseHitTestType.Widget:
  1797. {
  1798. viewerTool.CleanSelectedRect();
  1799. viewerTool.CleanEditAnnot();
  1800. BaseWidget hitWidget = viewerTool?.GetCPDFViewer()?.AnnotHitTest() as BaseWidget;
  1801. if (hitWidget != null)
  1802. {
  1803. viewerTool.ShowFormHitPop(hitWidget);
  1804. }
  1805. }
  1806. break;
  1807. case MouseHitTestType.MultiTextEdit:
  1808. viewerTool.DrawStartSelectedMultiRect();
  1809. break;
  1810. case MouseHitTestType.SelectedPageRect:
  1811. viewerTool.DrawStartPageSelectedRect();
  1812. break;
  1813. default:
  1814. {
  1815. List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
  1816. {
  1817. C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
  1818. C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
  1819. C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
  1820. };
  1821. if (list.Contains(e.annotType))
  1822. {
  1823. viewerTool.CleanSelectedRect();
  1824. if (!e.IsMersured||!list.Contains(createAnnotType))
  1825. {
  1826. viewerTool.StartDrawEditAnnot();
  1827. }
  1828. }
  1829. else
  1830. {
  1831. viewerTool.CleanEditAnnot();
  1832. viewerTool.DrawStartSelectedRect();
  1833. if (currentToolType == ToolType.WidgetEdit)
  1834. {
  1835. viewerTool.MoveDrawWidget(true);
  1836. }
  1837. }
  1838. }
  1839. break;
  1840. }
  1841. switch (currentToolType)
  1842. {
  1843. case ToolType.Pan:
  1844. {
  1845. if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_NONE)
  1846. {
  1847. switch ((e.mouseButtonEventArgs as MouseButtonEventArgs).ClickCount)
  1848. {
  1849. case 2:
  1850. viewerTool.DrawMoveSelectText(true);
  1851. break;
  1852. }
  1853. }
  1854. }
  1855. break;
  1856. case ToolType.ContentEdit:
  1857. {
  1858. editSelected = true;
  1859. clickEditSelected = true;
  1860. switch ((e.mouseButtonEventArgs as MouseButtonEventArgs).ClickCount)
  1861. {
  1862. case 2:
  1863. viewerTool.HandleTextSelectClick(viewerTool.GetLastSelectedRect(), true);
  1864. clickEditSelected = false;
  1865. MouseLeftButtonDownHandler?.Invoke(this, e);
  1866. return;
  1867. case 3:
  1868. viewerTool.HandleTextSelectClick(viewerTool.GetLastSelectedRect(), false);
  1869. clickEditSelected = false;
  1870. MouseLeftButtonDownHandler?.Invoke(this, e);
  1871. return;
  1872. }
  1873. if (createContentEditType != CPDFEditType.EditImage)
  1874. {
  1875. viewerTool.DrawTextEditDownEvent(true);
  1876. }
  1877. viewerTool.HideDrawSelectedMultiRect();
  1878. if (viewerTool.GetLastSelectedRect() != null)
  1879. {
  1880. Point point = Mouse.GetPosition(viewerTool);
  1881. PointControlType pointControlType = viewerTool.GetLastSelectedRect().GetHitControlIndex(point);
  1882. EditAreaObject editAreaObject = viewerTool.GetEditAreaObjectForRect(viewerTool.GetLastSelectedRect());
  1883. if (pointControlType != PointControlType.None &&
  1884. (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage || pointControlType != PointControlType.Body))
  1885. {
  1886. switch (pointControlType)
  1887. {
  1888. case PointControlType.LeftTop:
  1889. case PointControlType.RightBottom:
  1890. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeNWSE;
  1891. break;
  1892. case PointControlType.LeftMiddle:
  1893. case PointControlType.RightMiddle:
  1894. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeWE;
  1895. break;
  1896. case PointControlType.LeftBottom:
  1897. case PointControlType.RightTop:
  1898. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeNESW;
  1899. break;
  1900. case PointControlType.MiddlBottom:
  1901. case PointControlType.MiddleTop:
  1902. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeNS;
  1903. break;
  1904. case PointControlType.Line:
  1905. case PointControlType.Body:
  1906. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeAll;
  1907. break;
  1908. default:
  1909. break;
  1910. }
  1911. viewerTool.DrawStartTextEdit(viewerTool.GetLastSelectedRect());
  1912. clickEditSelected = false;
  1913. }
  1914. }
  1915. else
  1916. {
  1917. Point point = Mouse.GetPosition(viewerTool);
  1918. viewerTool.GetCPDFViewer().GetPointPageInfo(point, out int index, out Rect paintRect, out Rect pageBound);
  1919. if (index < 0)
  1920. {
  1921. MouseLeftButtonDownHandler?.Invoke(this, e);
  1922. return;
  1923. }
  1924. if (createContentEditType == CPDFEditType.EditText)
  1925. {
  1926. viewerTool.DrawTest(pageBound, index);
  1927. }
  1928. clickEditSelected = false;
  1929. }
  1930. }
  1931. break;
  1932. default:
  1933. break;
  1934. }
  1935. MouseLeftButtonDownHandler?.Invoke(this, e);
  1936. }
  1937. private void ViewerTool_MouseRightButtonDownHandler(object sender, MouseEventObject e)
  1938. {
  1939. if (e.mouseButtonEventArgs != null)
  1940. {
  1941. viewerTool?.SetPastePoint(e.mouseButtonEventArgs.GetPosition(viewerTool));
  1942. }
  1943. MouseRightButtonDownHandler?.Invoke(sender, e);
  1944. }
  1945. public void CreateLinkAnnotWithImage(int pageIndex, CRect rawImageRect)
  1946. {
  1947. if(viewerTool == null)
  1948. {
  1949. return;
  1950. }
  1951. viewerTool.RemoveSelectTextData();
  1952. viewerTool.ReDrawSelectText();
  1953. viewerTool.HideWidgetHitPop();
  1954. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  1955. CPDFDocument cPDFDocument = pdfViewer.GetDocument();
  1956. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageIndex);
  1957. CPDFLinkAnnotation linkAnnot = cPDFPage.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_LINK) as CPDFLinkAnnotation;
  1958. if (linkAnnot != null)
  1959. {
  1960. linkAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  1961. linkAnnot.SetModifyDate(PDFHelp.GetCurrentPdfTime());
  1962. List<CPDFAnnotation> annotList = cPDFPage.GetAnnotations();
  1963. int newIndex = cPDFPage.GetAnnotCount();
  1964. linkAnnot.SetRect(rawImageRect);
  1965. DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
  1966. LinkParam linkParam = defaultSettingParam.LinkParamDef;
  1967. switch (linkParam.Action)
  1968. {
  1969. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  1970. CPDFGoToAction gotoAction = new CPDFGoToAction();
  1971. CPDFDestination destination = new CPDFDestination();
  1972. destination.Position_X = linkParam.DestinationPosition.x;
  1973. destination.Position_Y = linkParam.DestinationPosition.y;
  1974. destination.PageIndex = linkParam.DestinationPageIndex;
  1975. gotoAction.SetDestination(cPDFDocument, destination);
  1976. linkAnnot.SetLinkAction(gotoAction);
  1977. break;
  1978. case C_ACTION_TYPE.ACTION_TYPE_URI:
  1979. CPDFUriAction uriAction = new CPDFUriAction();
  1980. if (!string.IsNullOrEmpty(linkParam.Uri))
  1981. {
  1982. uriAction.SetUri(linkParam.Uri);
  1983. }
  1984. linkAnnot.SetLinkAction(uriAction);
  1985. break;
  1986. default:
  1987. break;
  1988. }
  1989. if (!string.IsNullOrEmpty(linkParam.Content))
  1990. {
  1991. linkAnnot.SetContent(linkParam.Content);
  1992. }
  1993. if (!string.IsNullOrEmpty(linkParam.Author))
  1994. {
  1995. linkAnnot.SetAuthor(linkParam.Author);
  1996. }
  1997. if (!string.IsNullOrEmpty(linkParam.CreateTime))
  1998. {
  1999. linkAnnot.SetCreationDate(linkParam.CreateTime);
  2000. }
  2001. if (!string.IsNullOrEmpty(linkParam.UpdateTime))
  2002. {
  2003. linkAnnot.SetModifyDate(linkParam.UpdateTime);
  2004. }
  2005. linkAnnot.SetIsLocked(linkParam.Locked);
  2006. linkAnnot.SetTransparency(linkParam.Transparency);
  2007. MouseEventObject e= new MouseEventObject();
  2008. e.hitTestType = MouseHitTestType.Annot;
  2009. e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_LINK;
  2010. e.IsCreate = true;
  2011. AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), linkAnnot);
  2012. dynamic expandData = new ExpandoObject();
  2013. expandData.AnnotIndex = newIndex;
  2014. expandData.PageIndex=pageIndex;
  2015. expandData.AnnotParam= annotParam;
  2016. e.Data = expandData;
  2017. MouseLeftButtonUpHandler?.Invoke(this, e);
  2018. }
  2019. }
  2020. }
  2021. }