CPDFToolManager.cs 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220
  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 bool SaveStampImageData(CPDFAnnotation annotation,CRect stampRect)
  912. {
  913. CPDFStampAnnotation stampAnnot=annotation as CPDFStampAnnotation;
  914. if(viewerTool==null || stampAnnot == null ||stampAnnot.GetStampType()!=C_STAMP_TYPE.IMAGE_STAMP)
  915. {
  916. return false;
  917. }
  918. try
  919. {
  920. DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
  921. StampParam stampParam = defaultSettingParam.StampParamDef;
  922. byte[] imageData = null;
  923. int imageWidth = 0;
  924. int imageHeight = 0;
  925. PDFHelp.ImageStreamToByte(stampParam.ImageStream, ref imageData, ref imageWidth, ref imageHeight);
  926. if (imageData != null && imageWidth > 0 && imageHeight > 0)
  927. {
  928. stampAnnot.SetRect(stampRect);
  929. stampAnnot.SetImageStamp(imageData,imageWidth,imageHeight,stampParam.Rotation);
  930. return true;
  931. }
  932. }
  933. catch (Exception ex)
  934. {
  935. }
  936. return false;
  937. }
  938. private void SaveCreateAnnotation(ref CPDFAnnotation annotation, ref MouseEventObject e)
  939. {
  940. if (annotation == null)
  941. {
  942. return;
  943. }
  944. Point StartPoint = viewerTool.GetStartPoint();
  945. Point EndPoint = viewerTool.GetEndPoint();
  946. List<Point> points = viewerTool.GetInkDrawPoints();
  947. List<Point> measurepoints = viewerTool.GetMeasureDrawPoints();
  948. annotation.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  949. annotation.SetModifyDate(PDFHelp.GetCurrentPdfTime());
  950. Rect rect = viewerTool.EndDrawAnnot();
  951. if (annotation != null)
  952. {
  953. switch (annotation.Type)
  954. {
  955. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  956. SaveInkCreateAnnotation(ref annotation, points);
  957. e.IsCreate = true;
  958. e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_INK;
  959. e.Data = GetAnnotExpandObject(annotation);
  960. if (e.mouseButtonEventArgs!=null)
  961. {
  962. MouseLeftButtonUpHandler?.Invoke(this, e);
  963. }
  964. annotation = null;
  965. return;
  966. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  967. e.IsCreate = true;
  968. e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT;
  969. e.Data = GetAnnotExpandObject(annotation);
  970. if (e.mouseButtonEventArgs != null)
  971. {
  972. MouseLeftButtonUpHandler?.Invoke(this, e);
  973. }
  974. return;
  975. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  976. {
  977. if ((annotation as CPDFLineAnnotation).IsMersured())
  978. {
  979. if (measurepoints.Count > 1)
  980. {
  981. (annotation as CPDFLineAnnotation).SetLinePoints(new CPoint(
  982. (float)DpiHelper.StandardNumToPDFNum(measurepoints[0].X),
  983. (float)DpiHelper.StandardNumToPDFNum(measurepoints[0].Y)),
  984. new CPoint((float)DpiHelper.StandardNumToPDFNum(measurepoints[1].X),
  985. (float)DpiHelper.StandardNumToPDFNum(measurepoints[1].Y)));
  986. (annotation as CPDFLineAnnotation).GetDistanceMeasure().UpdateAnnotMeasure();
  987. PostMeasureInfo(this, annotation);
  988. }
  989. else
  990. {
  991. annotation.ReleaseAnnot();
  992. if (e.mouseButtonEventArgs != null)
  993. {
  994. MouseLeftButtonUpHandler?.Invoke(this, e);
  995. }
  996. annotation = null;
  997. return;
  998. }
  999. }
  1000. else
  1001. {
  1002. if (EndPoint != new Point(-1, -1))
  1003. {
  1004. (annotation as CPDFLineAnnotation).SetLinePoints(new CPoint((float)StartPoint.X, (float)StartPoint.Y), new CPoint((float)EndPoint.X, (float)EndPoint.Y));
  1005. }
  1006. else
  1007. {
  1008. annotation.ReleaseAnnot();
  1009. if (e.mouseButtonEventArgs != null)
  1010. {
  1011. MouseLeftButtonUpHandler?.Invoke(this, e);
  1012. }
  1013. annotation = null;
  1014. return;
  1015. }
  1016. }
  1017. }
  1018. break;
  1019. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  1020. {
  1021. if ((annotation as CPDFPolygonAnnotation).IsMersured())
  1022. {
  1023. List<CPoint> cPoints = new List<CPoint>();
  1024. foreach (Point item in measurepoints)
  1025. {
  1026. cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
  1027. }
  1028. (annotation as CPDFPolygonAnnotation).SetPoints(cPoints);
  1029. (annotation as CPDFPolygonAnnotation).GetAreaMeasure().UpdateAnnotMeasure();
  1030. PostMeasureInfo(this, annotation);
  1031. }
  1032. }
  1033. break;
  1034. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  1035. {
  1036. if ((annotation as CPDFPolylineAnnotation).IsMersured())
  1037. {
  1038. List<CPoint> cPoints = new List<CPoint>();
  1039. foreach (Point item in measurepoints)
  1040. {
  1041. cPoints.Add(DataConversionForWPF.PointConversionForCPoint(DpiHelper.StandardPointToPDFPoint(item)));
  1042. }
  1043. (annotation as CPDFPolylineAnnotation).SetPoints(cPoints);
  1044. (annotation as CPDFPolylineAnnotation).GetPerimeterMeasure().UpdateAnnotMeasure();
  1045. PostMeasureInfo(this, annotation);
  1046. }
  1047. }
  1048. break;
  1049. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  1050. if (rect.Width > 0 && rect.Height > 0)
  1051. {
  1052. List<CRect> coreRectList = new List<CRect>
  1053. {
  1054. new CRect((float)rect.Left, (float)rect.Bottom, (float)rect.Right, (float)rect.Top)
  1055. };
  1056. (annotation as CPDFRedactAnnotation).SetQuardRects(coreRectList);
  1057. }
  1058. break;
  1059. default:
  1060. break;
  1061. }
  1062. if (rect.Width <= 0 && rect.Height <= 0)
  1063. {
  1064. switch (createAnnotType)
  1065. {
  1066. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  1067. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  1068. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  1069. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  1070. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  1071. {
  1072. annotation.RemoveAnnot();
  1073. viewerTool.DrawEndSelectText();
  1074. TextSelectInfo textSelectInfo = viewerTool.GetTextSelectInfo();
  1075. if (textSelectInfo.PageSelectPointList.Count > 0)
  1076. {
  1077. viewerTool.DrawEndSelectText();
  1078. viewerTool.RemoveSelectTextData();
  1079. GroupHistory historyData = null;
  1080. viewerTool.CreateAnnotForSelectText(textSelectInfo, createAnnotType, out historyData);
  1081. List<object> dataList = new List<object>();
  1082. if (historyData != null && historyData.Histories.Count > 0)
  1083. {
  1084. foreach (IHistory historyItem in historyData.Histories)
  1085. {
  1086. AnnotHistory checkHistory = historyItem as AnnotHistory;
  1087. if (checkHistory == null || checkHistory.CurrentParam == null)
  1088. {
  1089. continue;
  1090. }
  1091. dynamic expandData = new ExpandoObject();
  1092. expandData.AnnotIndex = checkHistory.CurrentParam.AnnotIndex;
  1093. expandData.PageIndex = checkHistory.CurrentParam.PageIndex;
  1094. expandData.AnnotParam = checkHistory.CurrentParam;
  1095. dataList.Add(expandData);
  1096. }
  1097. }
  1098. e.annotType = createAnnotType;
  1099. e.IsCreate = true;
  1100. if (dataList.Count > 0)
  1101. {
  1102. e.Data = dataList.Count > 1 ? dataList : dataList[0];
  1103. }
  1104. }
  1105. if(createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_REDACT && textSelectInfo.PageSelectPointList.Count ==0)
  1106. {
  1107. viewerTool.GetCPDFViewer().UpdateAnnotFrame();
  1108. }
  1109. }
  1110. break;
  1111. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  1112. {
  1113. if (!viewerTool.PDFViewer.GetIsShowStampMouse())
  1114. {
  1115. break;
  1116. }
  1117. Rect stampRect = viewerTool.PDFViewer.GetStampRect();
  1118. Point mousePoint = new Point(
  1119. stampRect.X - stampRect.Width / 2 * viewerTool.GetCPDFViewer().GetZoom(),
  1120. stampRect.Y - stampRect.Height / 2 * viewerTool.GetCPDFViewer().GetZoom()
  1121. );
  1122. viewerTool.GetCPDFViewer().GetPointPageInfo(mousePoint, out int pageindex, out Rect paintRect, out Rect pageBound);
  1123. if (pageindex < 0)
  1124. {
  1125. annotation.RemoveAnnot();
  1126. annotation = null;
  1127. return;
  1128. }
  1129. else
  1130. {
  1131. CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
  1132. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageindex);
  1133. Point cropPoint = new Point();
  1134. if (viewerTool.GetRotateAnnot())
  1135. {
  1136. PageViewData viewData = viewerTool.PDFViewer.GetPageNodeByPageIndex(annotation.Page.PageIndex);
  1137. cropPoint.X = viewData.CropLeft;
  1138. cropPoint.Y = viewData.CropTop;
  1139. }
  1140. else
  1141. {
  1142. if (viewerTool.GetCPDFViewer().GetIsCrop())
  1143. {
  1144. CRect cropRect = cPDFPage.GetCropBounds();
  1145. cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
  1146. cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
  1147. }
  1148. }
  1149. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(
  1150. (mousePoint.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
  1151. (mousePoint.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
  1152. stampRect.Width, stampRect.Height)
  1153. );
  1154. CRect cStampRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
  1155. if (SaveStampImageData(annotation,cStampRect) == false)
  1156. {
  1157. annotation.SetRect(cStampRect);
  1158. }
  1159. annotation.UpdateAp();
  1160. e.IsCreate = true;
  1161. e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_STAMP;
  1162. e.Data = GetAnnotExpandObject(annotation);
  1163. StampAnnotHistory freeTextAnnotHistory = new StampAnnotHistory();
  1164. AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
  1165. annotParam.AnnotIndex = annotation.Page.GetAnnotCount() - 1;
  1166. freeTextAnnotHistory.CurrentParam = (StampParam)annotParam;
  1167. freeTextAnnotHistory.PDFDoc = viewerTool.GetCPDFViewer().GetDocument();
  1168. viewerTool.GetCPDFViewer().UndoManager.AddHistory(freeTextAnnotHistory);
  1169. }
  1170. viewerTool.GetCPDFViewer().UpdateAnnotFrame();
  1171. }
  1172. break;
  1173. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  1174. {
  1175. Point point = Mouse.GetPosition(viewerTool.PDFViewer);
  1176. viewerTool.GetCPDFViewer().GetPointPageInfo(point, out int pageindex, out Rect paintRect, out Rect pageBound);
  1177. if (pageindex < 0)
  1178. {
  1179. annotation.RemoveAnnot();
  1180. annotation = null;
  1181. return;
  1182. }
  1183. else
  1184. {
  1185. CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
  1186. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageindex);
  1187. Point cropPoint = new Point();
  1188. if (viewerTool.GetCPDFViewer().GetIsCrop())
  1189. {
  1190. CRect cropRect = cPDFPage.GetCropBounds();
  1191. cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
  1192. cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
  1193. }
  1194. CRect x = annotation.GetRect();
  1195. Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(
  1196. (point.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
  1197. (point.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
  1198. x.width(), x.height())
  1199. );
  1200. PDFRect.X = PDFRect.X - x.width() / 2;
  1201. PDFRect.Y = PDFRect.Y - x.height() / 2;
  1202. CRect cStampRect = new CRect((float)PDFRect.Left, (float)PDFRect.Bottom, (float)PDFRect.Right, (float)PDFRect.Top);
  1203. annotation.SetRect(cStampRect);
  1204. viewerTool.GetCPDFViewer().UpdateAnnotFrame();
  1205. e.IsCreate = true;
  1206. e.annotType = createAnnotType;
  1207. e.Data = GetAnnotExpandObject(annotation);
  1208. }
  1209. }
  1210. break;
  1211. default:
  1212. break;
  1213. }
  1214. //annotation.ReleaseAnnot();
  1215. if (e.mouseButtonEventArgs != null)
  1216. {
  1217. MouseLeftButtonUpHandler?.Invoke(this, e);
  1218. }
  1219. annotation = null;
  1220. return;
  1221. }
  1222. //CRect cRect = new CRect((float)rect.Left + annotation.GetBorderWidth(), (float)rect.Bottom - annotation.GetBorderWidth(), (float)rect.Right - annotation.GetBorderWidth(), (float)rect.Top + annotation.GetBorderWidth());
  1223. CRect cRect = new CRect(
  1224. (float)rect.Left,
  1225. (float)rect.Bottom,
  1226. (float)rect.Right,
  1227. (float)rect.Top);
  1228. annotation.SetRect(cRect);
  1229. annotation.UpdateAp();
  1230. AnnotHistory annotHistory = ParamConverter.CreateHistory(annotation);
  1231. if (annotHistory == null)
  1232. {
  1233. return;
  1234. }
  1235. AnnotParam currentParam;
  1236. switch (annotation.Type)
  1237. {
  1238. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  1239. currentParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
  1240. break;
  1241. default:
  1242. currentParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annotation);
  1243. break;
  1244. }
  1245. annotHistory.CurrentParam = currentParam;
  1246. annotHistory.Action = HistoryAction.Add;
  1247. annotHistory.PDFDoc = viewerTool.PDFViewer.GetDocument();
  1248. viewerTool.GetCPDFViewer().UndoManager.AddHistory(annotHistory);
  1249. viewerTool.ClearDrawAnnot();
  1250. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  1251. {
  1252. e.annotType = annotation.Type;
  1253. e.IsCreate = true;
  1254. dynamic expandData = new ExpandoObject();
  1255. expandData.AnnotIndex = currentParam.AnnotIndex;
  1256. expandData.PageIndex = currentParam.PageIndex;
  1257. expandData.AnnotParam = currentParam;
  1258. e.Data = expandData;
  1259. }
  1260. }
  1261. }
  1262. internal void PostMeasureInfo(object sender, CPDFAnnotation rawAnnot)
  1263. {
  1264. if (rawAnnot == null)
  1265. {
  1266. return;
  1267. }
  1268. try
  1269. {
  1270. if (rawAnnot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_LINE)
  1271. {
  1272. CPDFLineAnnotation lineAnnot = rawAnnot as CPDFLineAnnotation;
  1273. if (lineAnnot.IsMersured() && lineAnnot.Points != null && lineAnnot.Points.Count() == 2)
  1274. {
  1275. CPDFDistanceMeasure lineMeasure = lineAnnot.GetDistanceMeasure();
  1276. CPDFMeasureInfo measureInfo = lineMeasure.MeasureInfo;
  1277. Vector standVector = new Vector(1, 0);
  1278. Point startPoint = new Point(lineAnnot.Points[0].x, lineAnnot.Points[0].y);
  1279. Point endPoint = new Point(lineAnnot.Points[1].x, lineAnnot.Points[1].y);
  1280. Vector movevector = endPoint - startPoint;
  1281. double showLenght = lineMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_LENGTH);
  1282. MeasureEventArgs measureEvent = new MeasureEventArgs();
  1283. measureEvent.Angle = (int)Math.Abs(Vector.AngleBetween(movevector, standVector));
  1284. measureEvent.RulerTranslateUnit = measureInfo.RulerTranslateUnit;
  1285. measureEvent.RulerTranslate = measureInfo.RulerTranslate;
  1286. measureEvent.RulerBase = measureInfo.RulerBase;
  1287. measureEvent.RulerBaseUnit = measureInfo.RulerBaseUnit;
  1288. measureEvent.MousePos = new Point(
  1289. (int)Math.Abs(movevector.X),
  1290. (int)Math.Abs(movevector.Y));
  1291. measureEvent.Type = CPDFMeasureType.CPDF_DISTANCE_MEASURE;
  1292. NumberFormatInfo formatInfo = new NumberFormatInfo();
  1293. formatInfo.NumberDecimalDigits = Math.Abs(measureInfo.Precision).ToString().Length - 1;
  1294. measureEvent.Distance = showLenght.ToString("N", formatInfo) + " " + measureInfo.RulerTranslateUnit;
  1295. measureEvent.Precision = GetMeasureShowPrecision(measureInfo.Precision);
  1296. viewerTool?.InvokeMeasureChangeEvent(sender, measureEvent);
  1297. }
  1298. }
  1299. if (rawAnnot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE)
  1300. {
  1301. CPDFPolylineAnnotation polylineAnnot = rawAnnot as CPDFPolylineAnnotation;
  1302. if (polylineAnnot.IsMersured() && polylineAnnot.Points != null && polylineAnnot.Points.Count() >= 2)
  1303. {
  1304. double totalInch = 0;
  1305. for (int i = 0; i < polylineAnnot.Points.Count - 1; i++)
  1306. {
  1307. Point endLinePoint = new Point(
  1308. polylineAnnot.Points[i + 1].x,
  1309. polylineAnnot.Points[i + 1].y
  1310. );
  1311. Point startLinePoint = new Point(
  1312. polylineAnnot.Points[i].x,
  1313. polylineAnnot.Points[i].y
  1314. );
  1315. Vector subVector = endLinePoint - startLinePoint;
  1316. totalInch += subVector.Length;
  1317. }
  1318. totalInch = totalInch / 72D;
  1319. CPDFPerimeterMeasure lineMeasure = polylineAnnot.GetPerimeterMeasure();
  1320. CPDFMeasureInfo measureInfo = lineMeasure.MeasureInfo;
  1321. double showLenght = lineMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_LENGTH);
  1322. MeasureEventArgs measureEvent = new MeasureEventArgs();
  1323. measureEvent.Angle = 0;
  1324. measureEvent.RulerTranslateUnit = measureInfo.RulerTranslateUnit;
  1325. measureEvent.RulerTranslate = measureInfo.RulerTranslate;
  1326. measureEvent.RulerBase = measureInfo.RulerBase;
  1327. measureEvent.RulerBaseUnit = measureInfo.RulerBaseUnit;
  1328. measureEvent.Precision = GetMeasureShowPrecision(measureInfo.Precision);
  1329. measureEvent.Type = CPDFMeasureType.CPDF_PERIMETER_MEASURE;
  1330. NumberFormatInfo formatInfo = new NumberFormatInfo();
  1331. formatInfo.NumberDecimalDigits = Math.Abs(measureInfo.Precision).ToString().Length - 1;
  1332. measureEvent.Distance = showLenght.ToString("N", formatInfo) + " " + measureInfo.RulerTranslateUnit;
  1333. viewerTool?.InvokeMeasureChangeEvent(sender, measureEvent);
  1334. }
  1335. }
  1336. if (rawAnnot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON)
  1337. {
  1338. CPDFPolygonAnnotation polygonAnnot = rawAnnot as CPDFPolygonAnnotation;
  1339. if (polygonAnnot.IsMersured() && polygonAnnot.Points != null && polygonAnnot.Points.Count() >= 2)
  1340. {
  1341. double totalInch = 0;
  1342. for (int i = 0; i < polygonAnnot.Points.Count - 1; i++)
  1343. {
  1344. Point endLinePoint = new Point(
  1345. polygonAnnot.Points[i + 1].x,
  1346. polygonAnnot.Points[i + 1].y
  1347. );
  1348. Point startLinePoint = new Point(
  1349. polygonAnnot.Points[i].x,
  1350. polygonAnnot.Points[i].y
  1351. );
  1352. Vector subVector = endLinePoint - startLinePoint;
  1353. totalInch += subVector.Length;
  1354. }
  1355. totalInch = totalInch / 72D;
  1356. CPDFAreaMeasure areaMeasure = polygonAnnot.GetAreaMeasure();
  1357. CPDFMeasureInfo measureInfo = areaMeasure.MeasureInfo;
  1358. double showLenght = areaMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_LENGTH);
  1359. MeasureEventArgs measureEvent = new MeasureEventArgs();
  1360. measureEvent.Angle = 0;
  1361. measureEvent.RulerTranslateUnit = measureInfo.RulerTranslateUnit;
  1362. measureEvent.RulerTranslate = measureInfo.RulerTranslate;
  1363. measureEvent.RulerBase = measureInfo.RulerBase;
  1364. measureEvent.RulerBaseUnit = measureInfo.RulerBaseUnit;
  1365. measureEvent.Precision = GetMeasureShowPrecision(measureInfo.Precision);
  1366. measureEvent.Type = CPDFMeasureType.CPDF_AREA_MEASURE;
  1367. NumberFormatInfo formatInfo = new NumberFormatInfo();
  1368. formatInfo.NumberDecimalDigits = Math.Abs(measureInfo.Precision).ToString().Length - 1;
  1369. measureEvent.Distance = showLenght.ToString("N", formatInfo) + " " + measureInfo.RulerTranslateUnit;
  1370. double area = areaMeasure.GetMeasurementResults(CPDFCaptionType.CPDF_CAPTION_AREA);
  1371. measureEvent.Area = string.Format("{0} sq {1}", GetPrecisionData(area, measureEvent.Precision), measureEvent.RulerTranslateUnit);
  1372. viewerTool?.InvokeMeasureChangeEvent(sender, measureEvent);
  1373. }
  1374. }
  1375. }
  1376. catch (Exception e)
  1377. {
  1378. }
  1379. }
  1380. public string GetPrecisionData(double number, double precision)
  1381. {
  1382. NumberFormatInfo formatInfo = new NumberFormatInfo();
  1383. formatInfo.NumberDecimalDigits = 2;
  1384. if (precision == 1)
  1385. {
  1386. formatInfo.NumberDecimalDigits = 0;
  1387. }
  1388. if (precision == 0.1)
  1389. {
  1390. formatInfo.NumberDecimalDigits = 1;
  1391. }
  1392. if (precision == 0.01)
  1393. {
  1394. formatInfo.NumberDecimalDigits = 2;
  1395. }
  1396. if (precision == 0.001)
  1397. {
  1398. formatInfo.NumberDecimalDigits = 3;
  1399. }
  1400. if (precision == 0.0001)
  1401. {
  1402. formatInfo.NumberDecimalDigits = 4;
  1403. }
  1404. if (precision == 0.00001)
  1405. {
  1406. formatInfo.NumberDecimalDigits = 5;
  1407. }
  1408. return number.ToString("N", formatInfo);
  1409. }
  1410. internal double GetMeasureShowPrecision(int precision)
  1411. {
  1412. if (precision == CPDFMeasure.PRECISION_VALUE_ZERO)
  1413. {
  1414. return 1;
  1415. }
  1416. if (CPDFMeasure.PRECISION_VALUE_ONE == precision)
  1417. {
  1418. return 0.1;
  1419. }
  1420. if (CPDFMeasure.PRECISION_VALUE_TWO == precision)
  1421. {
  1422. return 0.01;
  1423. }
  1424. if (CPDFMeasure.PRECISION_VALUE_THREE == precision)
  1425. {
  1426. return 0.001;
  1427. }
  1428. if (CPDFMeasure.PRECISION_VALUE_FOUR == precision)
  1429. {
  1430. return 0.0001;
  1431. }
  1432. return 0;
  1433. }
  1434. private object GetAnnotExpandObject(CPDFAnnotation annot)
  1435. {
  1436. if (annot != null && annot.IsValid())
  1437. {
  1438. try
  1439. {
  1440. AnnotParam annotParam = null;
  1441. if (annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  1442. {
  1443. annotParam = ParamConverter.WidgetConverter(viewerTool.GetCPDFViewer().GetDocument(), annot);
  1444. }
  1445. else
  1446. {
  1447. annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), annot);
  1448. }
  1449. if (annotParam != null)
  1450. {
  1451. annotParam.AnnotIndex = annot.Page.GetAnnotCount() - 1;
  1452. dynamic expandData = new ExpandoObject();
  1453. expandData.AnnotIndex = annotParam.AnnotIndex;
  1454. expandData.PageIndex = annot.Page.PageIndex;
  1455. expandData.AnnotParam = annotParam;
  1456. return expandData;
  1457. }
  1458. }
  1459. catch (Exception ex)
  1460. {
  1461. }
  1462. }
  1463. return null;
  1464. }
  1465. private void SaveInkCreateAnnotation(ref CPDFAnnotation annotation, List<Point> points)
  1466. {
  1467. // Creation of non-custom stamps
  1468. if (!viewerTool.PDFViewer.GetIsShowStampMouse())
  1469. {
  1470. if (points.Count < 5)
  1471. {
  1472. annotation.RemoveAnnot();
  1473. annotation = null;
  1474. return;
  1475. }
  1476. List<List<CPoint>> inkPathList = new List<List<CPoint>>();
  1477. List<CPoint> inkPath = new List<CPoint>();
  1478. foreach (Point inkNode in points)
  1479. {
  1480. inkPath.Add(new CPoint((float)DpiHelper.StandardNumToPDFNum(inkNode.X), (float)DpiHelper.StandardNumToPDFNum(inkNode.Y)));
  1481. }
  1482. inkPathList.Add(inkPath);
  1483. (annotation as CPDFInkAnnotation).SetInkPath(inkPathList);
  1484. (annotation as CPDFInkAnnotation).UpdateAp();
  1485. }
  1486. else
  1487. {
  1488. Rect stampRect = viewerTool.PDFViewer.GetStampRect();
  1489. Point mousePoint = new Point(
  1490. stampRect.X - stampRect.Width / 2 * viewerTool.GetCPDFViewer().GetZoom(),
  1491. stampRect.Y - stampRect.Height / 2 * viewerTool.GetCPDFViewer().GetZoom()
  1492. );
  1493. viewerTool.GetCPDFViewer().GetPointPageInfo(mousePoint, out int pageindex, out Rect paintRect, out Rect pageBound);
  1494. if (pageindex < 0)
  1495. {
  1496. annotation.RemoveAnnot();
  1497. annotation = null;
  1498. return;
  1499. }
  1500. else
  1501. {
  1502. CPDFPage cPDFPage = viewerTool.GetCPDFViewer().GetDocument().PageAtIndex(pageindex);
  1503. Point cropPoint = new Point();
  1504. if (viewerTool.GetCPDFViewer().GetIsCrop())
  1505. {
  1506. CRect cropRect = cPDFPage.GetCropBounds();
  1507. cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
  1508. cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
  1509. }
  1510. // Move the point
  1511. CPoint cPoint = new CPoint(
  1512. (float)((mousePoint.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom()),
  1513. (float)((mousePoint.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom()));
  1514. List<List<CPoint>> cPoints = (annotation as CPDFInkAnnotation).InkPath;
  1515. List<List<CPoint>> savePointList = new List<List<CPoint>>();
  1516. foreach (List<CPoint> inkNode in cPoints)
  1517. {
  1518. List<CPoint> savePoints = new List<CPoint>();
  1519. foreach (CPoint addPoint in inkNode)
  1520. {
  1521. savePoints.Add(
  1522. new CPoint(
  1523. (addPoint.x + (float)DpiHelper.StandardNumToPDFNum(cPoint.x)),
  1524. (addPoint.y + (float)DpiHelper.StandardNumToPDFNum(cPoint.y))
  1525. ));
  1526. }
  1527. if (savePoints.Count > 0)
  1528. {
  1529. savePointList.Add(savePoints);
  1530. }
  1531. }
  1532. (annotation as CPDFInkAnnotation).SetInkPath(savePointList);
  1533. (annotation as CPDFInkAnnotation).UpdateAp();
  1534. }
  1535. }
  1536. viewerTool.ClearDrawAnnot();
  1537. viewerTool.GetCPDFViewer().UpdateRenderFrame();
  1538. InkAnnotHistory inkAnnotHistory = new InkAnnotHistory();
  1539. AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.PDFViewer.GetDocument(), cPDFAnnotation);
  1540. annotParam.AnnotIndex = cPDFAnnotation.Page.GetAnnotCount() - 1;
  1541. inkAnnotHistory.CurrentParam = (InkParam)annotParam;
  1542. inkAnnotHistory.PDFDoc = viewerTool.PDFViewer.GetDocument();
  1543. viewerTool.GetCPDFViewer().UndoManager.AddHistory(inkAnnotHistory);
  1544. return;
  1545. }
  1546. #endregion
  1547. private void ViewerTool_MouseMoveHandler(object sender, MouseEventObject e)
  1548. {
  1549. if (viewerTool == null)
  1550. return;
  1551. viewerTool.DrawMoveSelectedMultiRect();
  1552. viewerTool.DrawMovePageSelectedRect();
  1553. if (currentToolType != ToolType.ContentEdit)
  1554. {
  1555. if (e.hitTestType == MouseHitTestType.SelectRect)
  1556. {
  1557. List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
  1558. {
  1559. C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
  1560. C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
  1561. C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
  1562. };
  1563. Cursor oldCursor = viewerTool.Cursor;
  1564. Cursor newCursor = viewerTool.GetMoveSelectedRectCursor();
  1565. if (oldCursor != newCursor || viewerTool.PDFViewer.Cursor!=newCursor)
  1566. {
  1567. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = newCursor;
  1568. }
  1569. //viewerTool.PDFViewer.Cursor = viewerTool.Cursor= viewerTool.GetMoveSelectedRectCursor();
  1570. if (list.Contains(e.annotType))
  1571. {
  1572. viewerTool.DrawMoveEditAnnot();
  1573. }
  1574. else
  1575. {
  1576. if (e.annotType != C_ANNOTATION_TYPE.C_ANNOTATION_LINK)
  1577. {
  1578. bool tag = viewerTool.DrawMoveSelectedRect();
  1579. if (currentToolType == ToolType.WidgetEdit)
  1580. {
  1581. BaseWidget hitWidget = viewerTool?.GetCPDFViewer()?.AnnotHitTest() as BaseWidget;
  1582. if (hitWidget == null)
  1583. {
  1584. viewerTool.MoveDrawWidget(tag);
  1585. }
  1586. else
  1587. {
  1588. viewerTool.MoveDrawWidget(true);
  1589. }
  1590. }
  1591. }
  1592. }
  1593. }
  1594. else
  1595. {
  1596. if (currentToolType == ToolType.CreateAnnot)
  1597. {
  1598. if (!viewerTool.PDFViewer.GetIsShowStampMouse())
  1599. {
  1600. // 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.
  1601. viewerTool.MoveDrawAnnot();
  1602. }
  1603. switch (createAnnotType)
  1604. {
  1605. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  1606. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  1607. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  1608. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  1609. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  1610. viewerTool.DrawMoveSelectText(false);
  1611. break;
  1612. default:
  1613. break;
  1614. }
  1615. }
  1616. else if (currentToolType == ToolType.WidgetEdit)
  1617. {
  1618. BaseWidget hitWidget = viewerTool?.GetCPDFViewer()?.AnnotHitTest() as BaseWidget;
  1619. if (hitWidget == null)
  1620. {
  1621. viewerTool.MoveDrawWidget(false);
  1622. }
  1623. else
  1624. {
  1625. viewerTool.MoveDrawWidget(true);
  1626. }
  1627. }
  1628. else if (e.hitTestType == MouseHitTestType.Unknown && currentToolType != ToolType.WidgetEdit)
  1629. {
  1630. if (currentToolType == ToolType.Customize)
  1631. {
  1632. viewerTool.DrawMoveCustomizeTool();
  1633. }
  1634. else
  1635. {
  1636. TextSelectInfo textInfo = viewerTool.GetTextSelectInfo();
  1637. if ((textInfo.StartPage != -1 && e.mouseButtonEventArgs.LeftButton == MouseButtonState.Pressed) || viewerTool.IsText())
  1638. {
  1639. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.IBeam;
  1640. }
  1641. else
  1642. {
  1643. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.Arrow;
  1644. }
  1645. }
  1646. }
  1647. }
  1648. if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_NONE)
  1649. {
  1650. viewerTool.DrawMoveSelectText(false);
  1651. }
  1652. }
  1653. else
  1654. {
  1655. if (createContentEditType != CPDFEditType.EditImage)
  1656. {
  1657. Cursor cursor = Cursors.Arrow;
  1658. if (viewerTool.GetLastSelectedRect() != null)
  1659. {
  1660. if (editSelected)
  1661. {
  1662. viewerTool.DrawMoveTextEdit(viewerTool.GetLastSelectedRect(), clickEditSelected);
  1663. if(clickEditSelected)
  1664. cursor = Cursors.IBeam;
  1665. else
  1666. cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
  1667. }
  1668. else
  1669. {
  1670. cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
  1671. }
  1672. }
  1673. else
  1674. {
  1675. viewerTool.HideDrawSelectedMultiRect();
  1676. cursor = viewerTool.DrawMoveTest(viewerTool.GetLastSelectedRect());
  1677. }
  1678. if (cursor == Cursors.Arrow && createContentEditType == CPDFEditType.EditText)
  1679. {
  1680. cursor = Cursors.IBeam;
  1681. }
  1682. viewerTool.Cursor = cursor;
  1683. viewerTool.PDFViewer.Cursor = cursor;
  1684. }
  1685. else
  1686. {
  1687. //viewerTool.Cursor = Cursors.None;
  1688. //viewerTool.PDFViewer.Cursor = Cursors.None;
  1689. }
  1690. }
  1691. MouseMoveHandler?.Invoke(this, e);
  1692. }
  1693. private void MakeTextBoxReadOnly(TextBox textBox)
  1694. {
  1695. try
  1696. {
  1697. DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
  1698. FreeTextParam textParam = defaultSettingParam.FreeTextParamDef;
  1699. if(textParam.IsReadOnly)
  1700. {
  1701. textBox.IsReadOnly = true;
  1702. }
  1703. }
  1704. catch (Exception ex)
  1705. {
  1706. }
  1707. }
  1708. private void ViewerTool_MouseLeftButtonDownHandler(object sender, MouseEventObject e)
  1709. {
  1710. viewerTool.RemoveSelectTextData();
  1711. viewerTool.ReDrawSelectText();
  1712. viewerTool.HideWidgetHitPop();
  1713. switch (e.hitTestType)
  1714. {
  1715. case MouseHitTestType.Unknown:
  1716. {
  1717. if (currentToolType == ToolType.CreateAnnot)
  1718. {
  1719. switch ((e.mouseButtonEventArgs as MouseButtonEventArgs).ClickCount)
  1720. {
  1721. case 1:
  1722. if (viewerTool.IsCanSave())
  1723. {
  1724. cPDFAnnotation = viewerTool.StartDrawAnnot(createAnnotType);
  1725. viewerTool.CreateDefaultAnnot(cPDFAnnotation, createAnnotType, null);
  1726. if (cPDFAnnotation != null && createAnnotType == C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT)
  1727. {
  1728. TextBox textui = viewerTool.CreateTextBox();
  1729. MakeTextBoxReadOnly(textui);
  1730. }
  1731. switch (createAnnotType)
  1732. {
  1733. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  1734. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  1735. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  1736. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  1737. {
  1738. viewerTool.DrawStartSelectText();
  1739. viewerTool.EndDrawAnnot();
  1740. }
  1741. break;
  1742. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  1743. if (viewerTool.IsText())
  1744. {
  1745. viewerTool.DrawStartSelectText();
  1746. viewerTool.EndDrawAnnot();
  1747. }
  1748. break;
  1749. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  1750. {
  1751. bool cansave = true;
  1752. CPDFLineAnnotation LineAnnotation = (cPDFAnnotation as CPDFLineAnnotation);
  1753. if (LineAnnotation != null)
  1754. {
  1755. if (LineAnnotation.IsMersured())
  1756. {
  1757. cansave = false;
  1758. }
  1759. }
  1760. viewerTool.SetIsCanSave(cansave);
  1761. }
  1762. break;
  1763. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  1764. {
  1765. bool cansave = true;
  1766. CPDFPolygonAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolygonAnnotation);
  1767. PolyAnnotation?.IsMersured();
  1768. if (PolyAnnotation != null)
  1769. {
  1770. if (PolyAnnotation.IsMersured())
  1771. {
  1772. cansave = false;
  1773. }
  1774. }
  1775. viewerTool.SetIsCanSave(cansave);
  1776. }
  1777. break;
  1778. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  1779. {
  1780. bool cansave = true;
  1781. CPDFPolylineAnnotation PolyAnnotation = (cPDFAnnotation as CPDFPolylineAnnotation);
  1782. PolyAnnotation?.IsMersured();
  1783. if (PolyAnnotation != null)
  1784. {
  1785. if (PolyAnnotation.IsMersured())
  1786. {
  1787. cansave = false;
  1788. }
  1789. }
  1790. viewerTool.SetIsCanSave(cansave);
  1791. }
  1792. break;
  1793. default:
  1794. break;
  1795. }
  1796. }
  1797. else
  1798. {
  1799. viewerTool.MultipleClick();
  1800. e.IsDrawing=true;
  1801. }
  1802. break;
  1803. case 2:
  1804. if (currentToolType != ToolType.Customize)
  1805. {
  1806. if (!viewerTool.IsCanSave())
  1807. {
  1808. viewerTool.SetIsCanSave(true);
  1809. }
  1810. }
  1811. break;
  1812. }
  1813. }
  1814. else if (currentToolType == ToolType.WidgetEdit)
  1815. {
  1816. cPDFAnnotation = viewerTool.StartDrawWidget(createWidgetType);
  1817. viewerTool.CreateDefaultWidget(cPDFAnnotation, createWidgetType, null);
  1818. }
  1819. else if (currentToolType == ToolType.Pan || currentToolType == ToolType.Viewer)
  1820. {
  1821. if (viewerTool.IsText())
  1822. {
  1823. viewerTool.DrawStartSelectText();
  1824. e.hitTestType = MouseHitTestType.Text;
  1825. }
  1826. }
  1827. else if (currentToolType == ToolType.Customize)
  1828. {
  1829. viewerTool.DrawStartCustomizeTool(CustomizeToolType.kErase);
  1830. }
  1831. viewerTool.CleanSelectedRect();
  1832. viewerTool.CleanEditAnnot();
  1833. }
  1834. break;
  1835. case MouseHitTestType.Widget:
  1836. {
  1837. viewerTool.CleanSelectedRect();
  1838. viewerTool.CleanEditAnnot();
  1839. BaseWidget hitWidget = viewerTool?.GetCPDFViewer()?.AnnotHitTest() as BaseWidget;
  1840. if (hitWidget != null)
  1841. {
  1842. viewerTool.ShowFormHitPop(hitWidget);
  1843. }
  1844. }
  1845. break;
  1846. case MouseHitTestType.MultiTextEdit:
  1847. viewerTool.DrawStartSelectedMultiRect();
  1848. break;
  1849. case MouseHitTestType.SelectedPageRect:
  1850. viewerTool.DrawStartPageSelectedRect();
  1851. break;
  1852. default:
  1853. {
  1854. List<C_ANNOTATION_TYPE> list = new List<C_ANNOTATION_TYPE>()
  1855. {
  1856. C_ANNOTATION_TYPE.C_ANNOTATION_LINE,
  1857. C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON,
  1858. C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE,
  1859. };
  1860. if (list.Contains(e.annotType))
  1861. {
  1862. viewerTool.CleanSelectedRect();
  1863. if (!e.IsMersured||!list.Contains(createAnnotType))
  1864. {
  1865. viewerTool.StartDrawEditAnnot();
  1866. }
  1867. }
  1868. else
  1869. {
  1870. viewerTool.CleanEditAnnot();
  1871. viewerTool.DrawStartSelectedRect();
  1872. if (currentToolType == ToolType.WidgetEdit)
  1873. {
  1874. viewerTool.MoveDrawWidget(true);
  1875. }
  1876. }
  1877. }
  1878. break;
  1879. }
  1880. switch (currentToolType)
  1881. {
  1882. case ToolType.Pan:
  1883. {
  1884. if (e.annotType == C_ANNOTATION_TYPE.C_ANNOTATION_NONE)
  1885. {
  1886. switch ((e.mouseButtonEventArgs as MouseButtonEventArgs).ClickCount)
  1887. {
  1888. case 2:
  1889. viewerTool.DrawMoveSelectText(true);
  1890. break;
  1891. }
  1892. }
  1893. }
  1894. break;
  1895. case ToolType.ContentEdit:
  1896. {
  1897. editSelected = true;
  1898. clickEditSelected = true;
  1899. switch ((e.mouseButtonEventArgs as MouseButtonEventArgs).ClickCount)
  1900. {
  1901. case 2:
  1902. viewerTool.HandleTextSelectClick(viewerTool.GetLastSelectedRect(), true);
  1903. clickEditSelected = false;
  1904. MouseLeftButtonDownHandler?.Invoke(this, e);
  1905. return;
  1906. case 3:
  1907. viewerTool.HandleTextSelectClick(viewerTool.GetLastSelectedRect(), false);
  1908. clickEditSelected = false;
  1909. MouseLeftButtonDownHandler?.Invoke(this, e);
  1910. return;
  1911. }
  1912. if (createContentEditType != CPDFEditType.EditImage)
  1913. {
  1914. viewerTool.DrawTextEditDownEvent(true);
  1915. }
  1916. viewerTool.HideDrawSelectedMultiRect();
  1917. if (viewerTool.GetLastSelectedRect() != null)
  1918. {
  1919. Point point = Mouse.GetPosition(viewerTool);
  1920. PointControlType pointControlType = viewerTool.GetLastSelectedRect().GetHitControlIndex(point);
  1921. EditAreaObject editAreaObject = viewerTool.GetEditAreaObjectForRect(viewerTool.GetLastSelectedRect());
  1922. if (pointControlType != PointControlType.None &&
  1923. (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage || pointControlType != PointControlType.Body))
  1924. {
  1925. switch (pointControlType)
  1926. {
  1927. case PointControlType.LeftTop:
  1928. case PointControlType.RightBottom:
  1929. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeNWSE;
  1930. break;
  1931. case PointControlType.LeftMiddle:
  1932. case PointControlType.RightMiddle:
  1933. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeWE;
  1934. break;
  1935. case PointControlType.LeftBottom:
  1936. case PointControlType.RightTop:
  1937. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeNESW;
  1938. break;
  1939. case PointControlType.MiddlBottom:
  1940. case PointControlType.MiddleTop:
  1941. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeNS;
  1942. break;
  1943. case PointControlType.Line:
  1944. case PointControlType.Body:
  1945. viewerTool.PDFViewer.Cursor = viewerTool.Cursor = Cursors.SizeAll;
  1946. break;
  1947. default:
  1948. break;
  1949. }
  1950. viewerTool.DrawStartTextEdit(viewerTool.GetLastSelectedRect());
  1951. clickEditSelected = false;
  1952. }
  1953. }
  1954. else
  1955. {
  1956. Point point = Mouse.GetPosition(viewerTool);
  1957. viewerTool.GetCPDFViewer().GetPointPageInfo(point, out int index, out Rect paintRect, out Rect pageBound);
  1958. if (index < 0)
  1959. {
  1960. MouseLeftButtonDownHandler?.Invoke(this, e);
  1961. return;
  1962. }
  1963. if (createContentEditType == CPDFEditType.EditText)
  1964. {
  1965. viewerTool.DrawTest(pageBound, index);
  1966. }
  1967. clickEditSelected = false;
  1968. }
  1969. }
  1970. break;
  1971. default:
  1972. break;
  1973. }
  1974. MouseLeftButtonDownHandler?.Invoke(this, e);
  1975. }
  1976. private void ViewerTool_MouseRightButtonDownHandler(object sender, MouseEventObject e)
  1977. {
  1978. if (e.mouseButtonEventArgs != null)
  1979. {
  1980. viewerTool?.SetPastePoint(e.mouseButtonEventArgs.GetPosition(viewerTool));
  1981. }
  1982. MouseRightButtonDownHandler?.Invoke(sender, e);
  1983. }
  1984. public void CreateLinkAnnotWithImage(int pageIndex, CRect rawImageRect)
  1985. {
  1986. if(viewerTool == null)
  1987. {
  1988. return;
  1989. }
  1990. viewerTool.RemoveSelectTextData();
  1991. viewerTool.ReDrawSelectText();
  1992. viewerTool.HideWidgetHitPop();
  1993. CPDFViewer pdfViewer = viewerTool.GetCPDFViewer();
  1994. CPDFDocument cPDFDocument = pdfViewer.GetDocument();
  1995. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageIndex);
  1996. CPDFLinkAnnotation linkAnnot = cPDFPage.CreateAnnot(C_ANNOTATION_TYPE.C_ANNOTATION_LINK) as CPDFLinkAnnotation;
  1997. if (linkAnnot != null)
  1998. {
  1999. linkAnnot.SetCreationDate(PDFHelp.GetCurrentPdfTime());
  2000. linkAnnot.SetModifyDate(PDFHelp.GetCurrentPdfTime());
  2001. List<CPDFAnnotation> annotList = cPDFPage.GetAnnotations();
  2002. int newIndex = cPDFPage.GetAnnotCount();
  2003. linkAnnot.SetRect(rawImageRect);
  2004. DefaultSettingParam defaultSettingParam = viewerTool.GetDefaultSettingParam();
  2005. LinkParam linkParam = defaultSettingParam.LinkParamDef;
  2006. switch (linkParam.Action)
  2007. {
  2008. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  2009. CPDFGoToAction gotoAction = new CPDFGoToAction();
  2010. CPDFDestination destination = new CPDFDestination();
  2011. destination.Position_X = linkParam.DestinationPosition.x;
  2012. destination.Position_Y = linkParam.DestinationPosition.y;
  2013. destination.PageIndex = linkParam.DestinationPageIndex;
  2014. gotoAction.SetDestination(cPDFDocument, destination);
  2015. linkAnnot.SetLinkAction(gotoAction);
  2016. break;
  2017. case C_ACTION_TYPE.ACTION_TYPE_URI:
  2018. CPDFUriAction uriAction = new CPDFUriAction();
  2019. if (!string.IsNullOrEmpty(linkParam.Uri))
  2020. {
  2021. uriAction.SetUri(linkParam.Uri);
  2022. }
  2023. linkAnnot.SetLinkAction(uriAction);
  2024. break;
  2025. default:
  2026. break;
  2027. }
  2028. if (!string.IsNullOrEmpty(linkParam.Content))
  2029. {
  2030. linkAnnot.SetContent(linkParam.Content);
  2031. }
  2032. if (!string.IsNullOrEmpty(linkParam.Author))
  2033. {
  2034. linkAnnot.SetAuthor(linkParam.Author);
  2035. }
  2036. if (!string.IsNullOrEmpty(linkParam.CreateTime))
  2037. {
  2038. linkAnnot.SetCreationDate(linkParam.CreateTime);
  2039. }
  2040. if (!string.IsNullOrEmpty(linkParam.UpdateTime))
  2041. {
  2042. linkAnnot.SetModifyDate(linkParam.UpdateTime);
  2043. }
  2044. linkAnnot.SetIsLocked(linkParam.Locked);
  2045. linkAnnot.SetTransparency(linkParam.Transparency);
  2046. MouseEventObject e= new MouseEventObject();
  2047. e.hitTestType = MouseHitTestType.Annot;
  2048. e.annotType = C_ANNOTATION_TYPE.C_ANNOTATION_LINK;
  2049. e.IsCreate = true;
  2050. AnnotParam annotParam = ParamConverter.AnnotConverter(viewerTool.GetCPDFViewer().GetDocument(), linkAnnot);
  2051. dynamic expandData = new ExpandoObject();
  2052. expandData.AnnotIndex = newIndex;
  2053. expandData.PageIndex=pageIndex;
  2054. expandData.AnnotParam= annotParam;
  2055. e.Data = expandData;
  2056. MouseLeftButtonUpHandler?.Invoke(this, e);
  2057. }
  2058. }
  2059. }
  2060. }