CPDFViewerTool.Command.cs 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFAnnotation.Form;
  4. using ComPDFKit.PDFDocument;
  5. using ComPDFKit.PDFPage;
  6. using ComPDFKit.PDFPage.Edit;
  7. using ComPDFKit.Tool.DrawTool;
  8. using ComPDFKit.Tool.Help;
  9. using ComPDFKit.Tool.UndoManger;
  10. using ComPDFKit.Viewer.Annot;
  11. using ComPDFKit.Viewer.Helper;
  12. using ComPDFKitViewer;
  13. using ComPDFKitViewer.BaseObject;
  14. using ComPDFKitViewer.Helper;
  15. using ComPDFKitViewer.Widget;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Dynamic;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Windows;
  22. using System.Windows.Input;
  23. using System.Windows.Media;
  24. using System.Windows.Media.Imaging;
  25. namespace ComPDFKit.Tool
  26. {
  27. partial class CPDFViewerTool
  28. {
  29. public class CommandData
  30. {
  31. public ExecutedRoutedEventArgs uIEventArgs { get; set; }
  32. public bool StartCommand { get; set; }
  33. public CPDFEditType PDFEditType { get; set; }
  34. public AnnotParam CurrentParam { get; set; } = null;
  35. }
  36. /// <summary>
  37. /// System provided related command time notification
  38. /// </summary>
  39. public event EventHandler<CommandData> CommandExecutedHandler;
  40. public AnnotParam PasteParam { get; set; }
  41. internal class PDFEditCommandData
  42. {
  43. public string TextContent { get; set; }
  44. /// <summary>
  45. /// Original rectangle in PDF (72DPI)
  46. /// </summary>
  47. public Rect PDFRect { get; set; }
  48. public bool EditAreaCopied { get; set; }
  49. public CPDFEditType EditType { get; set; }
  50. public CPDFCopyEditArea CopyArea { get; set; }
  51. public CPDFEditPage EditPage { get; set; }
  52. }
  53. internal Point rightPressPoint = new Point(-1, -1);
  54. internal static List<PDFEditCommandData> lastPDFEditArgsList { get; private set; } = new List<PDFEditCommandData>();
  55. internal static List<AnnotParam> lastAnnotList { get; private set; } = new List<AnnotParam>();
  56. internal void BindCommand()
  57. {
  58. CommandBinding copyBind = new CommandBinding(ApplicationCommands.Copy);
  59. copyBind.CanExecute += CommandCanExecute;
  60. copyBind.Executed += CommandBind_Executed;
  61. CommandBindings.Add(copyBind);
  62. CommandBinding cutBind = new CommandBinding(ApplicationCommands.Cut);
  63. cutBind.CanExecute += CommandCanExecute;
  64. cutBind.Executed += CommandBind_Executed;
  65. CommandBindings.Add(cutBind);
  66. CommandBinding pasteBind = new CommandBinding(ApplicationCommands.Paste);
  67. pasteBind.CanExecute += CommandCanExecute;
  68. pasteBind.Executed += CommandBind_Executed;
  69. CommandBindings.Add(pasteBind);
  70. CommandBinding deleteBind = new CommandBinding(ApplicationCommands.Delete);
  71. deleteBind.CanExecute += CommandCanExecute;
  72. deleteBind.Executed += CommandBind_Executed;
  73. CommandBindings.Add(deleteBind);
  74. CommandBinding playBind = new CommandBinding(MediaCommands.Play);
  75. playBind.CanExecute += PlayBind_CanExecute;
  76. playBind.Executed += PlayBind_Executed;
  77. CommandBindings.Add(playBind);
  78. CommandBinding pastWithoutStyle = new CommandBinding(CustomCommands.PasteWithoutStyle);
  79. pastWithoutStyle.CanExecute += CommandCanExecute;
  80. pastWithoutStyle.Executed += CommandBind_Executed;
  81. CommandBindings.Add(pastWithoutStyle);
  82. CommandBinding selectAllBind = new CommandBinding(ApplicationCommands.SelectAll);
  83. selectAllBind.CanExecute += CommandCanExecute;
  84. selectAllBind.Executed += CommandBind_Executed;
  85. CommandBindings.Add(selectAllBind);
  86. }
  87. private void PlayBind_Executed(object sender, ExecutedRoutedEventArgs e)
  88. {
  89. BaseAnnot cmdArgs = e.Parameter as BaseAnnot;
  90. if (cmdArgs != null && cmdArgs.GetAnnotData() != null)
  91. {
  92. if (cmdArgs is SoundAnnot)
  93. {
  94. (cmdArgs as SoundAnnot).Play();
  95. }
  96. if (cmdArgs is MovieAnnot)
  97. {
  98. (cmdArgs as MovieAnnot).Play();
  99. }
  100. }
  101. e.Handled = true;
  102. }
  103. private void PlayBind_CanExecute(object sender, CanExecuteRoutedEventArgs e)
  104. {
  105. e.CanExecute = false;
  106. BaseAnnot cmdArgs = e.Parameter as BaseAnnot;
  107. if (cmdArgs != null && cmdArgs.GetAnnotData() != null)
  108. {
  109. e.CanExecute = true;
  110. }
  111. e.Handled = true;
  112. e.ContinueRouting = false;
  113. }
  114. public void ReBindCommand(List<CommandBinding> commandBindings)
  115. {
  116. CommandBindings.Clear();
  117. foreach (CommandBinding binding in commandBindings)
  118. {
  119. CommandBindings.Add(binding);
  120. }
  121. }
  122. private bool IsCanDoCommand = true;
  123. public void CanDoCommand()
  124. {
  125. IsCanDoCommand = true;
  126. }
  127. public void NotDoCommand()
  128. {
  129. IsCanDoCommand = false;
  130. }
  131. private void CommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
  132. {
  133. if (e.Command is RoutedUICommand uiCommand)
  134. {
  135. switch (currentModel)
  136. {
  137. case ToolType.Viewer:
  138. CheckViewerCommandStatus(uiCommand, e);
  139. break;
  140. case ToolType.CreateAnnot:
  141. case ToolType.WidgetEdit:
  142. case ToolType.Pan:
  143. CheckAnnotCommandStatus(uiCommand, e);
  144. break;
  145. case ToolType.Customize:
  146. break;
  147. case ToolType.ContentEdit:
  148. {
  149. CheckPDFEditCommandStatus(uiCommand, e);
  150. }
  151. break;
  152. default:
  153. break;
  154. }
  155. }
  156. }
  157. private void CommandBind_Executed(object sender, ExecutedRoutedEventArgs e)
  158. {
  159. RoutedUICommand uiCommand = e.Command as RoutedUICommand;
  160. if (uiCommand != null)
  161. {
  162. try
  163. {
  164. PasteParam = null;
  165. CommandData commandData = new CommandData();
  166. commandData.uIEventArgs = e;
  167. commandData.StartCommand = true;
  168. CPDFEditType editType = CPDFEditType.None;
  169. CommandExecutedHandler?.Invoke(this, commandData);
  170. if (e.Handled)
  171. {
  172. return;
  173. }
  174. if (!IsCanDoCommand)
  175. {
  176. CanDoCommand();
  177. return;
  178. }
  179. switch (currentModel)
  180. {
  181. case ToolType.Viewer:
  182. ExecuteViewerCommand(uiCommand);
  183. break;
  184. case ToolType.CreateAnnot:
  185. case ToolType.WidgetEdit:
  186. case ToolType.Pan:
  187. ExecuteAnnotCommand(uiCommand);
  188. break;
  189. case ToolType.ContentEdit:
  190. {
  191. ExecutePDFEditCommand(uiCommand, out editType);
  192. }
  193. break;
  194. case ToolType.Customize:
  195. break;
  196. default:
  197. break;
  198. }
  199. commandData.StartCommand = false;
  200. commandData.PDFEditType = editType;
  201. commandData.CurrentParam = PasteParam;
  202. CommandExecutedHandler?.Invoke(this, commandData);
  203. }
  204. catch (Exception ex)
  205. {
  206. }
  207. }
  208. }
  209. public void SetPastePoint(Point point)
  210. {
  211. rightPressPoint = point;
  212. }
  213. #region ContentEdit
  214. private void CheckPDFEditCommandStatus(RoutedUICommand uiCommand, CanExecuteRoutedEventArgs e)
  215. {
  216. switch (uiCommand.Name)
  217. {
  218. case "Copy":
  219. case "Cut":
  220. case "Delete":
  221. case "SelectAll":
  222. {
  223. if (currentEditAreaObject != null)
  224. {
  225. e.CanExecute = true;
  226. }
  227. //Add multi status
  228. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  229. if (multiSelectedRect != null && multiSelectedRect.Children.Count > 0)
  230. {
  231. e.CanExecute = true;
  232. }
  233. break;
  234. }
  235. case "Paste":
  236. case "PasteWithoutStyle":
  237. foreach (PDFEditCommandData checkItem in lastPDFEditArgsList)
  238. {
  239. if (checkItem.EditType == CPDFEditType.EditText && string.IsNullOrEmpty(checkItem.TextContent) == false)
  240. {
  241. e.CanExecute = true;
  242. break;
  243. }
  244. if (checkItem.EditType == CPDFEditType.EditImage && checkItem.EditAreaCopied)
  245. {
  246. e.CanExecute = true;
  247. break;
  248. }
  249. }
  250. try
  251. {
  252. if (Clipboard.ContainsText())
  253. {
  254. if (!string.IsNullOrEmpty(Clipboard.GetText()))
  255. {
  256. e.CanExecute = true;
  257. }
  258. }
  259. if (Clipboard.ContainsImage())
  260. {
  261. if (Clipboard.GetImage() != null)
  262. {
  263. e.CanExecute = true;
  264. }
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. }
  270. break;
  271. }
  272. }
  273. private void ExecutePDFEditCommand(RoutedUICommand uiCommand, out CPDFEditType editType)
  274. {
  275. editType = CPDFEditType.None;
  276. switch (uiCommand.Name)
  277. {
  278. case "Copy":
  279. CopyPDFEditData(out editType);
  280. break;
  281. case "Cut":
  282. CopyPDFEditData(out editType);
  283. DelPDFEditData(out editType);
  284. break;
  285. case "Delete":
  286. DelPDFEditData(out editType);
  287. break;
  288. case "Paste":
  289. SetEditCopyData();
  290. if (lastPDFEditArgsList.Count > 0)
  291. {
  292. PastePDFEditData(out editType);
  293. PDFViewer.UpdateRenderFrame();
  294. }
  295. break;
  296. case "PasteWithoutStyle":
  297. SetEditCopyData();
  298. if (lastPDFEditArgsList.Count > 0)
  299. {
  300. PastePDFEditData(out editType, false);
  301. PDFViewer.UpdateRenderFrame();
  302. }
  303. break;
  304. case "SelectAll":
  305. SelectAllPDFEditData(out editType);
  306. break;
  307. }
  308. }
  309. private void SetEditCopyData()
  310. {
  311. try
  312. {
  313. if (Clipboard.ContainsText())
  314. {
  315. string copyText = Clipboard.GetText();
  316. bool findCopy = false;
  317. if (lastPDFEditArgsList != null && lastPDFEditArgsList.Count > 0)
  318. {
  319. foreach (PDFEditCommandData checkItem in lastPDFEditArgsList)
  320. {
  321. if (checkItem.EditType == CPDFEditType.EditText && copyText == checkItem.TextContent)
  322. {
  323. findCopy = true;
  324. }
  325. }
  326. }
  327. if (findCopy == false)
  328. {
  329. lastPDFEditArgsList?.Clear();
  330. if (string.IsNullOrEmpty(copyText) == false)
  331. {
  332. PDFEditCommandData commandData = new PDFEditCommandData();
  333. commandData.EditType = CPDFEditType.EditText;
  334. commandData.TextContent = copyText;
  335. int PageIndex = PDFViewer.CurrentRenderFrame.PageIndex;
  336. RenderData render = PDFViewer.GetCurrentRenderPageForIndex(PageIndex);
  337. Rect rect = render.PaintRect;
  338. Point centerPoint = new Point(
  339. rect.Width / PDFViewer.CurrentRenderFrame.ZoomFactor / 2,
  340. rect.Height / PDFViewer.CurrentRenderFrame.ZoomFactor / 2);
  341. commandData.PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(centerPoint.X, centerPoint.Y, 0, 0));
  342. lastPDFEditArgsList.Add(commandData);
  343. }
  344. }
  345. }
  346. else if (Clipboard.ContainsImage())
  347. {
  348. if (Clipboard.GetImage() != null)
  349. {
  350. BitmapSource bitmapSource = Clipboard.GetImage();
  351. PDFEditCommandData commandData = new PDFEditCommandData();
  352. commandData.EditType = CPDFEditType.EditImage;
  353. int PageIndex = PDFViewer.CurrentRenderFrame.PageIndex;
  354. RenderData render = PDFViewer.GetCurrentRenderPageForIndex(PageIndex);
  355. Rect rect = render.PaintRect;
  356. Point centerPoint = new Point(
  357. rect.Width / PDFViewer.CurrentRenderFrame.ZoomFactor / 2,
  358. rect.Height / PDFViewer.CurrentRenderFrame.ZoomFactor / 2);
  359. commandData.PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(centerPoint.X, centerPoint.Y, bitmapSource.PixelWidth, bitmapSource.PixelHeight));
  360. lastPDFEditArgsList.Clear();
  361. lastPDFEditArgsList.Add(commandData);
  362. }
  363. }
  364. }
  365. catch (Exception ex)
  366. {
  367. }
  368. }
  369. private void CopyPDFEditData(out CPDFEditType editType)
  370. {
  371. editType = CPDFEditType.None;
  372. if (CPDFEditPage.CopyPage != null)
  373. {
  374. CPDFEditPage.CopyPage.ReleaseCopyEditAreaList();
  375. }
  376. try
  377. {
  378. lastPDFEditArgsList.Clear();
  379. Clipboard.Clear();
  380. if (currentEditAreaObject != null)
  381. {
  382. PDFEditCommandData commandData = new PDFEditCommandData();
  383. if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditText)
  384. {
  385. editType = CPDFEditType.EditText;
  386. CPDFEditTextArea editTextArea = currentEditAreaObject.cPDFEditArea as CPDFEditTextArea;
  387. commandData.TextContent = editTextArea.SelectText;
  388. if (selectAllCharsForLine || string.IsNullOrEmpty(commandData.TextContent))
  389. {
  390. CPDFEditPage editPage = currentEditAreaObject.cPDFEditPage;
  391. commandData.EditType = CPDFEditType.EditText;
  392. commandData.EditAreaCopied = editPage.CopyEditArea(currentEditAreaObject.cPDFEditArea);
  393. if (commandData.EditAreaCopied)
  394. {
  395. List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
  396. CPDFCopyEditArea CopyArea = copyList[copyList.Count - 1];
  397. commandData.TextContent = CopyArea.GetCopyTextAreaContent();
  398. commandData.CopyArea = CopyArea;
  399. commandData.EditPage = editPage;
  400. }
  401. }
  402. try
  403. {
  404. Clipboard.Clear();
  405. Clipboard.SetText(commandData.TextContent);
  406. Clipboard.Flush();
  407. }
  408. catch (Exception)
  409. {
  410. }
  411. commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(currentEditAreaObject.cPDFEditArea.GetFrame());
  412. lastPDFEditArgsList.Add(commandData);
  413. }
  414. if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage)
  415. {
  416. editType = CPDFEditType.EditImage;
  417. CPDFEditPage editPage = currentEditAreaObject.cPDFEditPage;
  418. commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(currentEditAreaObject.cPDFEditArea.GetFrame());
  419. commandData.EditAreaCopied = editPage.CopyEditArea(currentEditAreaObject.cPDFEditArea);
  420. commandData.EditType = CPDFEditType.EditImage;
  421. if (commandData.EditAreaCopied)
  422. {
  423. List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
  424. commandData.CopyArea = copyList[copyList.Count - 1];
  425. commandData.EditPage = editPage;
  426. lastPDFEditArgsList.Add(commandData);
  427. }
  428. }
  429. }
  430. else
  431. {
  432. //Add multi status
  433. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  434. if (multiSelectedRect != null && multiSelectedRect.Children.Count > 0)
  435. {
  436. foreach (SelectedRect selectedRect in multiSelectedRect.Children)
  437. {
  438. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(selectedRect);
  439. if (editAreaObject != null)
  440. {
  441. PDFEditCommandData commandData = new PDFEditCommandData();
  442. if (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditText)
  443. {
  444. editType = CPDFEditType.EditText;
  445. CPDFEditTextArea editTextArea = editAreaObject.cPDFEditArea as CPDFEditTextArea;
  446. commandData.TextContent = editTextArea.SelectText;
  447. if (!string.IsNullOrEmpty(commandData.TextContent))
  448. {
  449. CPDFEditPage editPage = editAreaObject.cPDFEditPage;
  450. commandData.EditType = CPDFEditType.EditText;
  451. commandData.EditAreaCopied = editPage.CopyEditArea(editAreaObject.cPDFEditArea);
  452. if (commandData.EditAreaCopied)
  453. {
  454. List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
  455. CPDFCopyEditArea CopyArea = copyList[copyList.Count - 1];
  456. commandData.TextContent = CopyArea.GetCopyTextAreaContent();
  457. commandData.CopyArea = CopyArea;
  458. commandData.EditPage = editPage;
  459. }
  460. }
  461. try
  462. {
  463. Clipboard.Clear();
  464. Clipboard.SetText(commandData.TextContent);
  465. Clipboard.Flush();
  466. }
  467. catch (Exception)
  468. {
  469. }
  470. commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(editAreaObject.cPDFEditArea.GetFrame());
  471. lastPDFEditArgsList.Add(commandData);
  472. }
  473. if (editAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage)
  474. {
  475. editType = CPDFEditType.EditImage;
  476. CPDFEditPage editPage = editAreaObject.cPDFEditPage;
  477. commandData.PDFRect = DataConversionForWPF.CRectConversionForRect(editAreaObject.cPDFEditArea.GetFrame());
  478. commandData.EditAreaCopied = editPage.CopyEditArea(editAreaObject.cPDFEditArea);
  479. commandData.EditType = CPDFEditType.EditImage;
  480. if (commandData.EditAreaCopied)
  481. {
  482. List<CPDFCopyEditArea> copyList = editPage.GetCopyEditAreaList();
  483. commandData.CopyArea = copyList[copyList.Count - 1];
  484. commandData.EditPage = editPage;
  485. lastPDFEditArgsList.Add(commandData);
  486. }
  487. }
  488. }
  489. }
  490. }
  491. }
  492. }
  493. catch
  494. {
  495. }
  496. }
  497. private void DelPDFEditData(out CPDFEditType editType)
  498. {
  499. editType = CPDFEditType.None;
  500. if (currentEditAreaObject != null)
  501. {
  502. GroupHistory groupHistory = new GroupHistory();
  503. PDFEditHistory editHistory = new PDFEditHistory();
  504. editHistory.EditPage = currentEditAreaObject.cPDFEditPage;
  505. editHistory.PageIndex = currentEditAreaObject.PageIndex;
  506. groupHistory.Histories.Add(editHistory);
  507. if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditText)
  508. {
  509. editType = CPDFEditType.EditText;
  510. CPDFEditTextArea editTextArea = currentEditAreaObject.cPDFEditArea as CPDFEditTextArea;
  511. string selectContent = editTextArea.SelectText;
  512. if (string.IsNullOrEmpty(selectContent) == false && !selectAllCharsForLine)
  513. {
  514. DeleteChars();
  515. }
  516. else
  517. {
  518. RemoveTextBlock();
  519. }
  520. }
  521. if (currentEditAreaObject.cPDFEditArea.Type == CPDFEditType.EditImage)
  522. {
  523. editType = CPDFEditType.EditImage;
  524. RemoveImageBlock();
  525. }
  526. if (PDFViewer != null && PDFViewer.UndoManager != null)
  527. {
  528. PDFViewer.UndoManager.AddHistory(groupHistory);
  529. //After removing the data, you need to get the data again.
  530. PDFViewer.UpdateRenderFrame();
  531. }
  532. }
  533. else
  534. {
  535. //Add multi status
  536. MultiSelectedRect multiSelectedRect = CommonHelper.FindVisualChild<MultiSelectedRect>(PDFViewer.GetViewForTag(MultiSelectedRectViewTag));
  537. if (multiSelectedRect != null && multiSelectedRect.Children.Count > 0)
  538. {
  539. List<EditAreaObject> editAreaObjectList = new List<EditAreaObject>();
  540. foreach (SelectedRect selectedRect in multiSelectedRect.Children)
  541. {
  542. EditAreaObject editAreaObject = GetEditAreaObjectListForRect(selectedRect);
  543. editAreaObjectList.Add(editAreaObject);
  544. }
  545. if (editAreaObjectList != null && editAreaObjectList.Count > 0)
  546. {
  547. editAreaObjectList = editAreaObjectList.OrderByDescending(x => x.EditAreaIndex).ToList();
  548. foreach (EditAreaObject editareaobject in editAreaObjectList)
  549. {
  550. GroupHistory groupHistory = new GroupHistory();
  551. PDFEditHistory editHistory = new PDFEditHistory();
  552. editHistory.EditPage = editareaobject.cPDFEditPage;
  553. editHistory.PageIndex = editareaobject.PageIndex;
  554. groupHistory.Histories.Add(editHistory);
  555. if (editareaobject.cPDFEditArea.Type == CPDFEditType.EditText)
  556. {
  557. editType = CPDFEditType.EditText;
  558. CPDFEditTextArea editTextArea = editareaobject.cPDFEditArea as CPDFEditTextArea;
  559. string selectContent = editTextArea.SelectText;
  560. RemoveTextBlock(editareaobject);
  561. PDFEditHistory deleteHistory = new PDFEditHistory();
  562. deleteHistory.EditPage = editareaobject.cPDFEditPage;
  563. deleteHistory.PageIndex = editareaobject.PageIndex;
  564. groupHistory.Histories.Add(deleteHistory);
  565. }
  566. if (editareaobject.cPDFEditArea.Type == CPDFEditType.EditImage)
  567. {
  568. editType = CPDFEditType.EditImage;
  569. RemoveImageBlock(editareaobject);
  570. }
  571. //After removing the data, you need to get the data again.
  572. PDFViewer.UpdateRenderFrame();
  573. if (PDFViewer != null && PDFViewer.UndoManager != null)
  574. {
  575. PDFViewer.UndoManager.AddHistory(groupHistory);
  576. }
  577. }
  578. }
  579. CleanSelectedMultiRect();
  580. OpenSelectedMulti(false);
  581. }
  582. }
  583. }
  584. private void PastePDFEditData(out CPDFEditType editType, bool pasteMatchStyle = true)
  585. {
  586. editType = CPDFEditType.None;
  587. double left = 0;
  588. double right = 0;
  589. double top = 0;
  590. double bottom = 0;
  591. bool initial = false;
  592. #region Calculate the maximum rectangle
  593. foreach (PDFEditCommandData commandData in lastPDFEditArgsList)
  594. {
  595. if (initial == false)
  596. {
  597. left = commandData.PDFRect.Left;
  598. right = commandData.PDFRect.Right;
  599. top = commandData.PDFRect.Top;
  600. bottom = commandData.PDFRect.Bottom;
  601. initial = true;
  602. continue;
  603. }
  604. left = Math.Min(left, commandData.PDFRect.Left);
  605. right = Math.Max(right, commandData.PDFRect.Right);
  606. top = Math.Min(top, commandData.PDFRect.Top);
  607. bottom = Math.Max(bottom, commandData.PDFRect.Bottom);
  608. }
  609. left = DpiHelper.PDFNumToStandardNum(left);
  610. right = DpiHelper.PDFNumToStandardNum(right);
  611. top = DpiHelper.PDFNumToStandardNum(top);
  612. bottom = DpiHelper.PDFNumToStandardNum(bottom);
  613. int offsetX = 25;
  614. int offsetY = 25;
  615. Point hoverPoint = rightPressPoint;
  616. rightPressPoint = new Point(-1, -1);
  617. int pageIndex = PDFViewer.CurrentRenderFrame.PageIndex;
  618. // Judge whether the right-click coordinate is on the page.
  619. PDFViewer.GetePointToPage(hoverPoint, out RenderData renderData, out Point pagePoint);
  620. if (renderData != null)
  621. {
  622. //Calculate the offset from the upper left corner.
  623. offsetX = (int)(pagePoint.X / currentZoom - left);
  624. offsetY = (int)(pagePoint.Y / currentZoom - top);
  625. if (left + offsetX < 0)
  626. {
  627. offsetX = (int)-left;
  628. }
  629. if (right + offsetX > renderData.PageBound.Width / currentZoom)
  630. {
  631. offsetX = (int)(renderData.PageBound.Width / currentZoom - right);
  632. }
  633. if (top + offsetY < 0)
  634. {
  635. offsetY = (int)-top;
  636. }
  637. if (bottom + offsetY > renderData.PageBound.Height / currentZoom)
  638. {
  639. offsetY = (int)(renderData.PageBound.Height / currentZoom - bottom);
  640. }
  641. pageIndex = renderData.PageIndex;
  642. }
  643. else
  644. {
  645. RenderData render = PDFViewer.GetCurrentRenderPageForIndex(pageIndex);
  646. //Max rectangle (standard DPI).
  647. Rect maxRect = new Rect((int)left + render.PaintRect.Left / currentZoom, (int)top + render.PaintRect.Top / currentZoom, (int)(right - left), (int)(bottom - top));
  648. //Center point of the visible range.
  649. Point centerPoint = new Point(
  650. render.PaintRect.Left / currentZoom + render.PaintRect.Width / currentZoom / 2,
  651. render.PaintRect.Top / currentZoom + render.PaintRect.Height / currentZoom / 2);
  652. //Visible range.
  653. Rect checkRect = new Rect(
  654. render.PaintRect.Left / currentZoom,
  655. render.PaintRect.Top / currentZoom,
  656. render.PaintRect.Width / currentZoom,
  657. render.PaintRect.Height / currentZoom);
  658. if (!checkRect.IntersectsWith(maxRect))
  659. {
  660. offsetX = (int)(left - centerPoint.X);
  661. offsetY = (int)(top - centerPoint.Y);
  662. }
  663. if (left + offsetX < 0)
  664. {
  665. offsetX = (int)-left;
  666. }
  667. if (right + offsetX > render.RenderRect.Width / currentZoom)
  668. {
  669. offsetX = (int)(render.RenderRect.Width / currentZoom / 2 - right);
  670. }
  671. if (top + offsetY < 0)
  672. {
  673. offsetY = (int)-top;
  674. }
  675. if (bottom + offsetY > render.RenderRect.Height / currentZoom)
  676. {
  677. offsetY = (int)(render.RenderRect.Height / currentZoom / 2 - bottom);
  678. }
  679. }
  680. #endregion
  681. foreach (PDFEditCommandData commandData in lastPDFEditArgsList)
  682. {
  683. GroupHistory groupHistory = new GroupHistory();
  684. CPDFPage docPage = PDFViewer.GetDocument().PageAtIndex(pageIndex);
  685. CPDFEditPage editPage = docPage.GetEditPage();
  686. RenderData render = PDFViewer.GetCurrentRenderPageForIndex(pageIndex);
  687. Rect offsetRect = AddPasteOffset(commandData.PDFRect, (int)DpiHelper.StandardNumToPDFNum(offsetX), (int)DpiHelper.StandardNumToPDFNum(offsetY), new Size(DpiHelper.StandardNumToPDFNum(render.PageBound.Width / currentZoom), DpiHelper.StandardNumToPDFNum(render.PageBound.Height / currentZoom)));
  688. commandData.PDFRect = offsetRect;
  689. if (commandData.EditType == CPDFEditType.EditText)
  690. {
  691. editType = CPDFEditType.EditText;
  692. if (pasteMatchStyle && commandData.EditAreaCopied)
  693. {
  694. commandData.CopyArea?.PasteEditArea(editPage, new CPoint((float)offsetRect.Left, (float)offsetRect.Top));
  695. if (editPage.CanUndo())
  696. {
  697. PDFEditHistory editHistory = new PDFEditHistory();
  698. editHistory.EditPage = editPage;
  699. editHistory.PageIndex = pageIndex;
  700. groupHistory.Histories.Add(editHistory);
  701. CPDFViewer pdfViewer = GetCPDFViewer();
  702. if (pdfViewer != null && pdfViewer.UndoManager != null)
  703. {
  704. pdfViewer.UndoManager.AddHistory(groupHistory);
  705. }
  706. }
  707. SelectedEditAreaForIndex(pageIndex, editPage.GetEditAreaList().Count - 1, false);
  708. }
  709. else
  710. {
  711. PDFEditHistory editHistory = new PDFEditHistory();
  712. if (!string.IsNullOrEmpty(commandData.TextContent))
  713. {
  714. EditAreaObject editAreaObject = GetHitTestAreaObject(hoverPoint);
  715. if (editAreaObject != null && editAreaObject.cPDFEditArea is CPDFEditTextArea)
  716. {
  717. CPDFEditTextArea TextArea = editAreaObject.cPDFEditArea as CPDFEditTextArea;
  718. if (TextArea.SelectLineRects.Count > 0)
  719. {
  720. TextArea.DeleteChars();
  721. TextArea.ClearSelectChars();
  722. PDFEditHistory deleteHistory = new PDFEditHistory();
  723. deleteHistory.EditPage = editPage;
  724. deleteHistory.PageIndex = pageIndex;
  725. groupHistory.Histories.Add(deleteHistory);
  726. }
  727. TextArea.InsertText(commandData.TextContent);
  728. editHistory.EditPage = editPage;
  729. editHistory.PageIndex = pageIndex;
  730. groupHistory.Histories.Add(editHistory);
  731. CPDFViewer pdfViewer = GetCPDFViewer();
  732. if (pdfViewer != null && pdfViewer.UndoManager != null)
  733. {
  734. pdfViewer.UndoManager.AddHistory(groupHistory);
  735. }
  736. }
  737. else
  738. {
  739. PDFEditHistory createHistory = new PDFEditHistory();
  740. CPDFEditTextArea editArea = editPage.CreateNewTextArea(DataConversionForWPF.RectConversionForCRect(offsetRect), "Helvetica", 14, new byte[3] { 0, 0, 0 });
  741. createHistory.EditPage = editPage;
  742. createHistory.PageIndex = pageIndex;
  743. groupHistory.Histories.Add(createHistory);
  744. if (editArea != null)
  745. {
  746. if (editArea.InsertText(commandData.TextContent))
  747. {
  748. editHistory.EditPage = editPage;
  749. editHistory.PageIndex = pageIndex;
  750. groupHistory.Histories.Add(editHistory);
  751. }
  752. SelectedEditAreaForIndex(pageIndex, editPage.GetEditAreaList().Count - 1, false);
  753. }
  754. CPDFViewer pdfViewer = GetCPDFViewer();
  755. if (pdfViewer != null && pdfViewer.UndoManager != null)
  756. {
  757. pdfViewer.UndoManager.AddHistory(groupHistory);
  758. }
  759. }
  760. }
  761. }
  762. }
  763. if (commandData.EditType == CPDFEditType.EditImage)
  764. {
  765. editType = CPDFEditType.EditImage;
  766. PDFEditHistory editHistory = new PDFEditHistory();
  767. if (commandData.EditAreaCopied)
  768. {
  769. commandData.CopyArea?.PasteEditArea(editPage, new CPoint((float)offsetRect.Left, (float)offsetRect.Top));
  770. editHistory.EditPage = editPage;
  771. editHistory.PageIndex = pageIndex;
  772. CPDFViewer pdfViewer = GetCPDFViewer();
  773. if (pdfViewer != null && pdfViewer.UndoManager != null)
  774. {
  775. pdfViewer.UndoManager.AddHistory(editHistory);
  776. }
  777. SelectedEditAreaForIndex(pageIndex, editPage.GetEditAreaList().Count - 1, false);
  778. }
  779. else
  780. {
  781. BitmapSource bitmapSource = BinaryStructConverter.ImageFromClipboardDib();
  782. if (bitmapSource != null)
  783. {
  784. PDFEditHistory createHistory = new PDFEditHistory();
  785. byte[] imageData = new byte[bitmapSource.PixelWidth * bitmapSource.PixelHeight * 4];
  786. if (bitmapSource.Format != PixelFormats.Bgra32)
  787. {
  788. FormatConvertedBitmap covert = new FormatConvertedBitmap(bitmapSource, PixelFormats.Bgra32, bitmapSource.Palette, 0);
  789. covert.CopyPixels(imageData, bitmapSource.PixelWidth * 4, 0);
  790. }
  791. else
  792. {
  793. bitmapSource.CopyPixels(imageData, bitmapSource.PixelWidth * 4, 0);
  794. }
  795. CPDFEditImageArea editArea = editPage.CreateNewImageArea(DataConversionForWPF.RectConversionForCRect(offsetRect), imageData, bitmapSource.PixelWidth, bitmapSource.PixelHeight);
  796. createHistory.EditPage = editPage;
  797. createHistory.PageIndex = pageIndex;
  798. groupHistory.Histories.Add(createHistory);
  799. if (editArea != null)
  800. {
  801. editHistory.EditPage = editPage;
  802. editHistory.PageIndex = pageIndex;
  803. SelectedEditAreaForIndex(pageIndex, editPage.GetEditAreaList().Count - 1, false);
  804. }
  805. CPDFViewer pdfViewer = GetCPDFViewer();
  806. if (pdfViewer != null && pdfViewer.UndoManager != null)
  807. {
  808. pdfViewer.UndoManager.AddHistory(groupHistory);
  809. }
  810. }
  811. }
  812. }
  813. editPage.EndEdit();
  814. }
  815. }
  816. private void SelectAllPDFEditData(out CPDFEditType editType)
  817. {
  818. editType = CPDFEditType.None;
  819. if (currentEditAreaObject != null && currentEditAreaObject.cPDFEditPage != null)
  820. {
  821. CPDFEditTextArea textArea = currentEditAreaObject.cPDFEditArea as CPDFEditTextArea;
  822. textArea.SelectAllChars();
  823. editType = CPDFEditType.EditText;
  824. PDFViewer.UpdateRenderFrame();
  825. }
  826. }
  827. private Rect AddPasteOffset(Rect clientRect, int offsetX, int offsetY, Size pageSize)
  828. {
  829. clientRect.X += offsetX;
  830. clientRect.Y += offsetY;
  831. if (clientRect.Left < 0)
  832. {
  833. clientRect.X = 0;
  834. }
  835. if (clientRect.Top < 0)
  836. {
  837. clientRect.Y = 0;
  838. }
  839. if (clientRect.Right > pageSize.Width)
  840. {
  841. clientRect.X = pageSize.Width - Math.Min(clientRect.Width, pageSize.Width);
  842. }
  843. if (clientRect.Bottom > pageSize.Height)
  844. {
  845. clientRect.Y = pageSize.Height - Math.Min(clientRect.Height, pageSize.Height);
  846. }
  847. return clientRect;
  848. }
  849. #endregion
  850. #region Annot
  851. private bool CheckCacheHitTestAnnot(string cmdName = "")
  852. {
  853. if (cacheHitTestAnnot == null)
  854. {
  855. return false;
  856. }
  857. AnnotData hitData = cacheHitTestAnnot.GetAnnotData();
  858. if (hitData == null)
  859. {
  860. return false;
  861. }
  862. if (hitData.Annot == null)
  863. {
  864. return false;
  865. }
  866. if (cmdName == "Delete" && hitData.Annot is CPDFSignatureWidget)
  867. {
  868. CPDFSignatureWidget signAnnot = hitData.Annot as CPDFSignatureWidget;
  869. if (signAnnot != null && signAnnot.IsSigned())
  870. {
  871. return false;
  872. }
  873. }
  874. return true;
  875. }
  876. private bool CheckAnnotCanDoCopyCut(bool isCut = false)
  877. {
  878. if (!CheckCacheHitTestAnnot(isCut ? "Delete" : ""))
  879. {
  880. return false;
  881. }
  882. if (cacheHitTestAnnot.GetAnnotData().Annot.GetIsLocked() && isCut)
  883. {
  884. return false;
  885. }
  886. switch (cacheHitTestAnnot.CurrentType)
  887. {
  888. case C_ANNOTATION_TYPE.C_ANNOTATION_HIGHLIGHT:
  889. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUIGGLY:
  890. case C_ANNOTATION_TYPE.C_ANNOTATION_UNDERLINE:
  891. case C_ANNOTATION_TYPE.C_ANNOTATION_STRIKEOUT:
  892. case C_ANNOTATION_TYPE.C_ANNOTATION_REDACT:
  893. case C_ANNOTATION_TYPE.C_ANNOTATION_SOUND:
  894. case C_ANNOTATION_TYPE.C_ANNOTATION_MOVIE:
  895. case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
  896. return false;
  897. default:
  898. break;
  899. }
  900. return true;
  901. }
  902. private void CheckViewerCommandStatus(RoutedUICommand uiCommand, CanExecuteRoutedEventArgs e)
  903. {
  904. switch (uiCommand.Name)
  905. {
  906. case "Copy":
  907. TextSelectInfo textSelectInfo = GetTextSelectInfo();
  908. if (!e.CanExecute && textSelectInfo != null)
  909. {
  910. foreach (int key in textSelectInfo.PageSelectText.Keys)
  911. {
  912. if (textSelectInfo.PageSelectText[key] != string.Empty)
  913. {
  914. e.CanExecute = true;
  915. break;
  916. }
  917. }
  918. }
  919. break;
  920. default:
  921. return;
  922. }
  923. }
  924. private void CheckAnnotCommandStatus(RoutedUICommand uiCommand, CanExecuteRoutedEventArgs e)
  925. {
  926. switch (uiCommand.Name)
  927. {
  928. case "Copy":
  929. e.CanExecute = CheckAnnotCanDoCopyCut();
  930. TextSelectInfo textSelectInfo = GetTextSelectInfo();
  931. if (!e.CanExecute && textSelectInfo != null)
  932. {
  933. foreach (int key in textSelectInfo.PageSelectText.Keys)
  934. {
  935. if (textSelectInfo.PageSelectText[key] != string.Empty)
  936. {
  937. e.CanExecute = true;
  938. break;
  939. }
  940. }
  941. }
  942. break;
  943. case "Cut":
  944. e.CanExecute = CheckAnnotCanDoCopyCut(true);
  945. break;
  946. case "Delete":
  947. e.CanExecute = CheckCacheHitTestAnnot("Delete");
  948. break;
  949. case "Paste":
  950. if (lastAnnotList.Count > 0)
  951. {
  952. e.CanExecute = true;
  953. }
  954. break;
  955. }
  956. }
  957. private void ExecuteViewerCommand(RoutedUICommand uiCommand)
  958. {
  959. switch (uiCommand.Name)
  960. {
  961. case "Copy":
  962. TextSelectInfo textSelectInfo = GetTextSelectInfo();
  963. if (textSelectInfo != null)
  964. {
  965. StringBuilder copyTextBuilder = new StringBuilder();
  966. foreach (int key in textSelectInfo.PageSelectText.Keys)
  967. {
  968. if (textSelectInfo.PageSelectText[key] != string.Empty)
  969. {
  970. copyTextBuilder.Append(textSelectInfo.PageSelectText[key]);
  971. }
  972. }
  973. if (copyTextBuilder.Length > 0)
  974. {
  975. try
  976. {
  977. Clipboard.Clear();
  978. Clipboard.SetText(copyTextBuilder.ToString());
  979. }
  980. catch (Exception)
  981. {
  982. }
  983. }
  984. }
  985. break;
  986. default:
  987. return;
  988. }
  989. }
  990. private void ExecuteAnnotCommand(RoutedUICommand uiCommand)
  991. {
  992. switch (uiCommand.Name)
  993. {
  994. case "Copy":
  995. if (cacheHitTestAnnot != null)
  996. {
  997. lastAnnotList.Clear();
  998. AnnotParam annotParam = ParamConverter.AnnotConverter(GetCPDFViewer().GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
  999. lastAnnotList.Add(annotParam);
  1000. }
  1001. if (cacheMoveWidget != null)
  1002. {
  1003. lastAnnotList.Clear();
  1004. AnnotParam annotParam = ParamConverter.WidgetConverter(GetCPDFViewer().GetDocument(), cacheMoveWidget.GetAnnotData().Annot);
  1005. lastAnnotList.Add(annotParam);
  1006. }
  1007. else
  1008. {
  1009. TextSelectInfo textSelectInfo = GetTextSelectInfo();
  1010. if (textSelectInfo != null)
  1011. {
  1012. StringBuilder copyTextBuilder = new StringBuilder();
  1013. foreach (int key in textSelectInfo.PageSelectText.Keys)
  1014. {
  1015. if (textSelectInfo.PageSelectText[key] != string.Empty)
  1016. {
  1017. copyTextBuilder.Append(textSelectInfo.PageSelectText[key]);
  1018. }
  1019. }
  1020. if (copyTextBuilder.Length > 0)
  1021. {
  1022. try
  1023. {
  1024. Clipboard.Clear();
  1025. Clipboard.SetText(copyTextBuilder.ToString());
  1026. }
  1027. catch (Exception)
  1028. {
  1029. }
  1030. }
  1031. }
  1032. }
  1033. break;
  1034. case "Cut":
  1035. if (cacheHitTestAnnot != null)
  1036. {
  1037. lastAnnotList.Clear();
  1038. AnnotParam annotParam;
  1039. if (cacheHitTestAnnot.CurrentType == C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET)
  1040. {
  1041. annotParam = ParamConverter.WidgetConverter(GetCPDFViewer().GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
  1042. }
  1043. else
  1044. {
  1045. annotParam = ParamConverter.AnnotConverter(GetCPDFViewer().GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
  1046. }
  1047. lastAnnotList.Add(annotParam);
  1048. }
  1049. if (cacheMoveWidget != null)
  1050. {
  1051. lastAnnotList.Clear();
  1052. AnnotParam annotParam = ParamConverter.WidgetConverter(GetCPDFViewer().GetDocument(), cacheMoveWidget.GetAnnotData().Annot);
  1053. lastAnnotList.Add(annotParam);
  1054. }
  1055. DeleteAnnotData();
  1056. PDFViewer.UpdateAnnotFrame();
  1057. break;
  1058. case "Delete":
  1059. DeleteAnnotData();
  1060. PDFViewer.UpdateAnnotFrame();
  1061. break;
  1062. case "Paste":
  1063. PasteAnnotData();
  1064. PDFViewer.UpdateAnnotFrame();
  1065. break;
  1066. }
  1067. }
  1068. private void PasteAnnotData(bool pasteMatchStyle = false)
  1069. {
  1070. AnnotHistory annotHistory = null;
  1071. foreach (AnnotParam item in lastAnnotList)
  1072. {
  1073. if (item == null)
  1074. {
  1075. continue;
  1076. }
  1077. Point point = rightPressPoint;
  1078. rightPressPoint = new Point(-1, -1);
  1079. switch (item.CurrentType)
  1080. {
  1081. case C_ANNOTATION_TYPE.C_ANNOTATION_TEXT:
  1082. {
  1083. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  1084. Rect rect;
  1085. annotHistory = new StickyNoteAnnotHistory();
  1086. annotHistory.PDFDoc = cPDFDocument;
  1087. int index = -1;
  1088. if (point.Equals(new Point(-1, -1)))
  1089. {
  1090. index = item.PageIndex;
  1091. rect = new Rect(
  1092. (item.ClientRect.left + 25),
  1093. (item.ClientRect.top + 25),
  1094. item.ClientRect.width(),
  1095. item.ClientRect.height()
  1096. );
  1097. }
  1098. else
  1099. {
  1100. PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
  1101. CRect cRect = item.ClientRect;
  1102. Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
  1103. Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  1104. rect = new Rect(
  1105. (pdfPoint.X - cRect.width() / 2),
  1106. (pdfPoint.Y - cRect.height() / 2),
  1107. cRect.width(),
  1108. cRect.height()
  1109. );
  1110. }
  1111. CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
  1112. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  1113. if (cPDFPage == null)
  1114. return;
  1115. CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
  1116. CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
  1117. cPDFAnnotation.SetRect(setRect);
  1118. cPDFAnnotation.UpdateAp();
  1119. AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
  1120. (annotHistory as StickyNoteAnnotHistory).CurrentParam = (StickyNoteParam)annotParam;
  1121. }
  1122. break;
  1123. case C_ANNOTATION_TYPE.C_ANNOTATION_LINK:
  1124. {
  1125. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  1126. Rect rect;
  1127. annotHistory = new LinkAnnotHistory();
  1128. annotHistory.PDFDoc = cPDFDocument;
  1129. int index = -1;
  1130. if (point.Equals(new Point(-1, -1)))
  1131. {
  1132. index = item.PageIndex;
  1133. rect = new Rect(
  1134. (item.ClientRect.left + 25),
  1135. (item.ClientRect.top + 25),
  1136. item.ClientRect.width(),
  1137. item.ClientRect.height()
  1138. );
  1139. }
  1140. else
  1141. {
  1142. PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
  1143. CRect cRect = item.ClientRect;
  1144. Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
  1145. Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  1146. rect = new Rect(
  1147. (pdfPoint.X - cRect.width() / 2),
  1148. (pdfPoint.Y - cRect.height() / 2),
  1149. cRect.width(),
  1150. cRect.height()
  1151. );
  1152. }
  1153. CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
  1154. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  1155. if (cPDFPage == null)
  1156. return;
  1157. CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
  1158. CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
  1159. cPDFAnnotation.SetRect(setRect);
  1160. cPDFAnnotation.UpdateAp();
  1161. AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
  1162. (annotHistory as LinkAnnotHistory).CurrentParam = (LinkParam)annotParam;
  1163. }
  1164. break;
  1165. case C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT:
  1166. {
  1167. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  1168. Rect rect;
  1169. annotHistory = new FreeTextAnnotHistory();
  1170. annotHistory.PDFDoc = cPDFDocument;
  1171. int index = -1;
  1172. if (point.Equals(new Point(-1, -1)))
  1173. {
  1174. index = item.PageIndex;
  1175. rect = new Rect(
  1176. (item.ClientRect.left + 25),
  1177. (item.ClientRect.top + 25),
  1178. item.ClientRect.width(),
  1179. item.ClientRect.height()
  1180. );
  1181. }
  1182. else
  1183. {
  1184. PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
  1185. CRect cRect = item.ClientRect;
  1186. Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
  1187. Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  1188. rect = new Rect(
  1189. (pdfPoint.X - cRect.width() / 2),
  1190. (pdfPoint.Y - cRect.height() / 2),
  1191. cRect.width(),
  1192. cRect.height()
  1193. );
  1194. }
  1195. CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
  1196. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  1197. if (cPDFPage == null)
  1198. return;
  1199. CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
  1200. CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
  1201. cPDFAnnotation.SetRect(setRect);
  1202. cPDFAnnotation.UpdateAp();
  1203. AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
  1204. (annotHistory as FreeTextAnnotHistory).CurrentParam = (FreeTextParam)annotParam;
  1205. }
  1206. break;
  1207. case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
  1208. {
  1209. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  1210. Rect rect;
  1211. annotHistory = new LineAnnotHistory();
  1212. annotHistory.PDFDoc = cPDFDocument;
  1213. int index = -1;
  1214. if (point.Equals(new Point(-1, -1)))
  1215. {
  1216. index = item.PageIndex;
  1217. rect = new Rect(
  1218. (item.ClientRect.left + 25),
  1219. (item.ClientRect.top + 25),
  1220. item.ClientRect.width(),
  1221. item.ClientRect.height()
  1222. );
  1223. }
  1224. else
  1225. {
  1226. PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
  1227. CRect cRect = item.ClientRect;
  1228. Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
  1229. Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  1230. rect = new Rect(
  1231. (pdfPoint.X - cRect.width() / 2),
  1232. (pdfPoint.Y - cRect.height() / 2),
  1233. cRect.width(),
  1234. cRect.height()
  1235. );
  1236. }
  1237. CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
  1238. LineParam newLineParam = new LineParam();
  1239. item.CopyTo(newLineParam);
  1240. {
  1241. float offsetX = setRect.left - item.ClientRect.left;
  1242. float offsetY = setRect.top - item.ClientRect.top;
  1243. newLineParam.HeadPoint = new CPoint(newLineParam.HeadPoint.x + offsetX, newLineParam.HeadPoint.y + offsetY);
  1244. newLineParam.TailPoint = new CPoint(newLineParam.TailPoint.x + offsetX, newLineParam.TailPoint.y + offsetY);
  1245. }
  1246. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  1247. if (cPDFPage == null)
  1248. return;
  1249. CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
  1250. CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
  1251. (cPDFAnnotation as CPDFLineAnnotation)?.SetLinePoints(newLineParam.HeadPoint, newLineParam.TailPoint);
  1252. cPDFAnnotation.SetRect(setRect);
  1253. cPDFAnnotation.UpdateAp();
  1254. AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
  1255. (annotHistory as LineAnnotHistory).CurrentParam = (LineParam)annotParam;
  1256. }
  1257. break;
  1258. case C_ANNOTATION_TYPE.C_ANNOTATION_SQUARE:
  1259. {
  1260. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  1261. Rect rect;
  1262. annotHistory = new SquareAnnotHistory();
  1263. annotHistory.PDFDoc = cPDFDocument;
  1264. int index = -1;
  1265. if (point.Equals(new Point(-1, -1)))
  1266. {
  1267. index = item.PageIndex;
  1268. rect = new Rect(
  1269. (item.ClientRect.left + 25),
  1270. (item.ClientRect.top + 25),
  1271. item.ClientRect.width(),
  1272. item.ClientRect.height()
  1273. );
  1274. }
  1275. else
  1276. {
  1277. PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
  1278. CRect cRect = item.ClientRect;
  1279. Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
  1280. Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  1281. rect = new Rect(
  1282. (pdfPoint.X - cRect.width() / 2),
  1283. (pdfPoint.Y - cRect.height() / 2),
  1284. cRect.width(),
  1285. cRect.height()
  1286. );
  1287. }
  1288. CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
  1289. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  1290. if (cPDFPage == null)
  1291. return;
  1292. CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
  1293. CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
  1294. cPDFAnnotation.SetRect(setRect);
  1295. cPDFAnnotation.UpdateAp();
  1296. AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
  1297. (annotHistory as SquareAnnotHistory).CurrentParam = (SquareParam)annotParam;
  1298. }
  1299. break;
  1300. case C_ANNOTATION_TYPE.C_ANNOTATION_CIRCLE:
  1301. {
  1302. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  1303. Rect rect;
  1304. annotHistory = new CircleAnnotHistory();
  1305. annotHistory.PDFDoc = cPDFDocument;
  1306. int index = -1;
  1307. if (point.Equals(new Point(-1, -1)))
  1308. {
  1309. index = item.PageIndex;
  1310. rect = new Rect(
  1311. (item.ClientRect.left + 25),
  1312. (item.ClientRect.top + 25),
  1313. item.ClientRect.width(),
  1314. item.ClientRect.height()
  1315. );
  1316. }
  1317. else
  1318. {
  1319. PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
  1320. CRect cRect = item.ClientRect;
  1321. Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
  1322. Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  1323. rect = new Rect(
  1324. (pdfPoint.X - cRect.width() / 2),
  1325. (pdfPoint.Y - cRect.height() / 2),
  1326. cRect.width(),
  1327. cRect.height()
  1328. );
  1329. }
  1330. CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
  1331. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  1332. if (cPDFPage == null)
  1333. return;
  1334. CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
  1335. CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
  1336. cPDFAnnotation.SetRect(setRect);
  1337. cPDFAnnotation.UpdateAp();
  1338. AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
  1339. (annotHistory as CircleAnnotHistory).CurrentParam = (CircleParam)annotParam;
  1340. }
  1341. break;
  1342. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
  1343. break;
  1344. case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
  1345. break;
  1346. case C_ANNOTATION_TYPE.C_ANNOTATION_STAMP:
  1347. {
  1348. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  1349. Rect rect;
  1350. annotHistory = new StampAnnotHistory();
  1351. annotHistory.PDFDoc = cPDFDocument;
  1352. int index = -1;
  1353. if (point.Equals(new Point(-1, -1)))
  1354. {
  1355. index = item.PageIndex;
  1356. rect = new Rect(
  1357. (item.ClientRect.left + 25),
  1358. (item.ClientRect.top + 25),
  1359. item.ClientRect.width(),
  1360. item.ClientRect.height()
  1361. );
  1362. }
  1363. else
  1364. {
  1365. PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
  1366. CRect cRect = item.ClientRect;
  1367. Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
  1368. Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  1369. rect = new Rect(
  1370. (pdfPoint.X - cRect.width() / 2),
  1371. (pdfPoint.Y - cRect.height() / 2),
  1372. cRect.width(),
  1373. cRect.height()
  1374. );
  1375. }
  1376. CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
  1377. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  1378. if (cPDFPage == null)
  1379. return;
  1380. CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(item.CurrentType);
  1381. CreateDefaultAnnot(cPDFAnnotation, item.CurrentType, item);
  1382. cPDFAnnotation.SetRect(setRect);
  1383. cPDFAnnotation.UpdateAp();
  1384. AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
  1385. (annotHistory as StampAnnotHistory).CurrentParam = (StampParam)annotParam;
  1386. }
  1387. break;
  1388. case C_ANNOTATION_TYPE.C_ANNOTATION_CARET:
  1389. break;
  1390. case C_ANNOTATION_TYPE.C_ANNOTATION_INK:
  1391. {
  1392. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  1393. Rect rect;
  1394. annotHistory = new InkAnnotHistory();
  1395. annotHistory.PDFDoc = cPDFDocument;
  1396. int index = -1;
  1397. if (point.Equals(new Point(-1, -1)))
  1398. {
  1399. index = item.PageIndex;
  1400. rect = new Rect(
  1401. (item.ClientRect.left + 25),
  1402. (item.ClientRect.top + 25),
  1403. item.ClientRect.width(),
  1404. item.ClientRect.height()
  1405. );
  1406. }
  1407. else
  1408. {
  1409. PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
  1410. CRect cRect = item.ClientRect;
  1411. Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
  1412. Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  1413. rect = new Rect(
  1414. (pdfPoint.X - cRect.width() / 2),
  1415. (pdfPoint.Y - cRect.height() / 2),
  1416. cRect.width(),
  1417. cRect.height()
  1418. );
  1419. }
  1420. CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
  1421. InkParam newInkParam = new InkParam();
  1422. item.CopyTo(newInkParam);
  1423. if (newInkParam.InkPath != null && newInkParam.InkPath.Count > 0)
  1424. {
  1425. float offsetX = setRect.left - item.ClientRect.left;
  1426. float offsetY = setRect.top - item.ClientRect.top;
  1427. List<List<CPoint>> arrangeList = new List<List<CPoint>>();
  1428. foreach (List<CPoint> inkNode in newInkParam.InkPath)
  1429. {
  1430. List<CPoint> inkPath = new List<CPoint>();
  1431. arrangeList.Add(inkPath);
  1432. foreach (CPoint addPoint in inkNode)
  1433. {
  1434. inkPath.Add(new CPoint(addPoint.x + offsetX, addPoint.y + offsetY));
  1435. }
  1436. }
  1437. newInkParam.InkPath = arrangeList;
  1438. newInkParam.ClientRect = setRect;
  1439. }
  1440. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  1441. if (cPDFPage == null)
  1442. return;
  1443. CPDFAnnotation cPDFAnnotation = cPDFPage.CreateAnnot(newInkParam.CurrentType);
  1444. CreateDefaultAnnot(cPDFAnnotation, newInkParam.CurrentType, newInkParam);
  1445. cPDFAnnotation.UpdateAp();
  1446. AnnotParam annotParam = ParamConverter.AnnotConverter(cPDFDocument, cPDFAnnotation);
  1447. (annotHistory as InkAnnotHistory).CurrentParam = (InkParam)annotParam;
  1448. }
  1449. break;
  1450. case C_ANNOTATION_TYPE.C_ANNOTATION_POPUP:
  1451. break;
  1452. case C_ANNOTATION_TYPE.C_ANNOTATION_FILEATTACHMENT:
  1453. break;
  1454. case C_ANNOTATION_TYPE.C_ANNOTATION_WIDGET:
  1455. {
  1456. rightPressPoint = point;
  1457. bool result = PasteWidgetData(ref annotHistory, item as WidgetParm);
  1458. if (!result)
  1459. return;
  1460. }
  1461. break;
  1462. case C_ANNOTATION_TYPE.C_ANNOTATION_SCREEN:
  1463. break;
  1464. case C_ANNOTATION_TYPE.C_ANNOTATION_PRINTERMARK:
  1465. break;
  1466. case C_ANNOTATION_TYPE.C_ANNOTATION_TRAPNET:
  1467. break;
  1468. case C_ANNOTATION_TYPE.C_ANNOTATION_WATERMARK:
  1469. break;
  1470. case C_ANNOTATION_TYPE.C_ANNOTATION_3D:
  1471. break;
  1472. case C_ANNOTATION_TYPE.C_ANNOTATION_RICHMEDIA:
  1473. break;
  1474. case C_ANNOTATION_TYPE.C_ANNOTATION_INTERCHANGE:
  1475. break;
  1476. default:
  1477. break;
  1478. }
  1479. PasteParam = annotHistory.CurrentParam;
  1480. PDFViewer.UndoManager.AddHistory(annotHistory);
  1481. }
  1482. }
  1483. private void DeleteAnnotData()
  1484. {
  1485. dynamic notifyData = null;
  1486. if (cacheHitTestAnnot != null)
  1487. {
  1488. AnnotHistory annotHistory = ParamConverter.CreateHistory(cacheHitTestAnnot.GetAnnotData().Annot);
  1489. if (annotHistory == null)
  1490. {
  1491. return;
  1492. }
  1493. AnnotParam annotParam = null;
  1494. if (cacheHitTestAnnot is BaseWidget)
  1495. {
  1496. annotParam = ParamConverter.WidgetConverter(PDFViewer.GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
  1497. }
  1498. else
  1499. {
  1500. annotParam = ParamConverter.AnnotConverter(PDFViewer.GetDocument(), cacheHitTestAnnot.GetAnnotData().Annot);
  1501. }
  1502. if (annotParam != null)
  1503. {
  1504. notifyData = new ExpandoObject();
  1505. notifyData.Action = HistoryAction.Remove;
  1506. notifyData.PageIndex = annotParam.PageIndex;
  1507. notifyData.AnnotIndex = annotParam.AnnotIndex;
  1508. notifyData.AnnotType = annotParam.CurrentType;
  1509. notifyData.CurrentParam = annotParam;
  1510. if (annotParam is WidgetParm)
  1511. {
  1512. notifyData.WidgetType = (annotParam as WidgetParm).WidgetType;
  1513. }
  1514. annotHistory.CurrentParam = annotParam;
  1515. annotHistory.PDFDoc = PDFViewer.GetDocument();
  1516. annotHistory.Action = HistoryAction.Remove;
  1517. PDFViewer.UndoManager.AddHistory(annotHistory);
  1518. List<C_ANNOTATION_TYPE> checkEditType = 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. if (checkEditType.Contains(cacheHitTestAnnot.CurrentType))
  1525. {
  1526. //Need to clear the measurement selected edit box.
  1527. CleanEditAnnot();
  1528. }
  1529. cacheHitTestAnnot.RemoveClean(true);
  1530. cacheHitTestAnnot.GetAnnotData().Annot.RemoveAnnot();
  1531. cacheHitTestAnnot = null;
  1532. }
  1533. CleanSelectedRect();
  1534. }
  1535. if (cacheMoveWidget != null)
  1536. {
  1537. AnnotHistory annotHistory = ParamConverter.CreateHistory(cacheMoveWidget.GetAnnotData().Annot);
  1538. if (annotHistory == null)
  1539. {
  1540. return;
  1541. }
  1542. AnnotParam annotParam = ParamConverter.WidgetConverter(PDFViewer.GetDocument(), cacheMoveWidget.GetAnnotData().Annot);
  1543. if (annotParam != null)
  1544. {
  1545. notifyData = new ExpandoObject();
  1546. notifyData.Action = HistoryAction.Remove;
  1547. notifyData.PageIndex = annotParam.PageIndex;
  1548. notifyData.AnnotIndex = annotParam.AnnotIndex;
  1549. notifyData.AnnotType = annotParam.CurrentType;
  1550. notifyData.WidgetType = (annotParam as WidgetParm).WidgetType;
  1551. notifyData.CurrentParam = annotParam;
  1552. annotHistory.CurrentParam = annotParam;
  1553. annotHistory.PDFDoc = PDFViewer.GetDocument();
  1554. annotHistory.Action = HistoryAction.Remove;
  1555. PDFViewer.UndoManager.AddHistory(annotHistory);
  1556. cacheMoveWidget.GetAnnotData().Annot.RemoveAnnot();
  1557. cacheMoveWidget = null;
  1558. }
  1559. CleanSelectedRect();
  1560. }
  1561. if (notifyData != null)
  1562. {
  1563. AnnotChanged?.Invoke(this, notifyData);
  1564. }
  1565. }
  1566. private bool PasteWidgetData(ref AnnotHistory annotHistory, WidgetParm item)
  1567. {
  1568. CPDFDocument cPDFDocument = PDFViewer.GetDocument();
  1569. Point point = rightPressPoint;
  1570. rightPressPoint = new Point(-1, -1);
  1571. Rect rect;
  1572. int index = -1;
  1573. if (point.Equals(new Point(-1, -1)))
  1574. {
  1575. index = item.PageIndex;
  1576. rect = new Rect(
  1577. (item.ClientRect.left + 25),
  1578. (item.ClientRect.top + 25),
  1579. item.ClientRect.width(),
  1580. item.ClientRect.height()
  1581. );
  1582. }
  1583. else
  1584. {
  1585. PDFViewer.GetPointPageInfo(point, out index, out Rect paintRect, out var pageBound);
  1586. CRect cRect = item.ClientRect;
  1587. Point zoomPoint = new Point((point.X - pageBound.X) / currentZoom, (point.Y - pageBound.Y) / currentZoom);
  1588. Point pdfPoint = DpiHelper.StandardPointToPDFPoint(zoomPoint);
  1589. rect = new Rect(
  1590. (pdfPoint.X - cRect.width() / 2),
  1591. (pdfPoint.Y - cRect.height() / 2),
  1592. cRect.width(),
  1593. cRect.height()
  1594. );
  1595. }
  1596. CPDFPage cPDFPage = cPDFDocument.PageAtIndex(index);
  1597. if (cPDFPage == null)
  1598. return false;
  1599. CPDFAnnotation cPDFAnnotation = cPDFPage.CreateWidget(item.WidgetType);
  1600. CreateDefaultWidget(cPDFAnnotation, item.WidgetType, item);
  1601. CRect setRect = DataConversionForWPF.RectConversionForCRect(rect);
  1602. cPDFAnnotation.SetRect(setRect);
  1603. (cPDFAnnotation as CPDFWidget).UpdateFormAp();
  1604. AnnotParam annotParam = ParamConverter.WidgetConverter(cPDFDocument, cPDFAnnotation);
  1605. switch (item.WidgetType)
  1606. {
  1607. case C_WIDGET_TYPE.WIDGET_NONE:
  1608. break;
  1609. case C_WIDGET_TYPE.WIDGET_PUSHBUTTON:
  1610. annotHistory = new PushButtonHistory();
  1611. (annotHistory as PushButtonHistory).CurrentParam = (PushButtonParam)annotParam;
  1612. annotHistory.PDFDoc = cPDFDocument;
  1613. break;
  1614. case C_WIDGET_TYPE.WIDGET_CHECKBOX:
  1615. annotHistory = new CheckBoxHistory();
  1616. (annotHistory as CheckBoxHistory).CurrentParam = (CheckBoxParam)annotParam;
  1617. annotHistory.PDFDoc = cPDFDocument;
  1618. break;
  1619. case C_WIDGET_TYPE.WIDGET_RADIOBUTTON:
  1620. annotHistory = new RadioButtonHistory();
  1621. (annotHistory as RadioButtonHistory).CurrentParam = (RadioButtonParam)annotParam;
  1622. annotHistory.PDFDoc = cPDFDocument;
  1623. break;
  1624. case C_WIDGET_TYPE.WIDGET_TEXTFIELD:
  1625. annotHistory = new TextBoxHistory();
  1626. (annotHistory as TextBoxHistory).CurrentParam = (TextBoxParam)annotParam;
  1627. annotHistory.PDFDoc = cPDFDocument;
  1628. break;
  1629. case C_WIDGET_TYPE.WIDGET_COMBOBOX:
  1630. annotHistory = new ComboBoxHistory();
  1631. (annotHistory as ComboBoxHistory).CurrentParam = (ComboBoxParam)annotParam;
  1632. annotHistory.PDFDoc = cPDFDocument;
  1633. break;
  1634. case C_WIDGET_TYPE.WIDGET_LISTBOX:
  1635. annotHistory = new ListBoxHistory();
  1636. (annotHistory as ListBoxHistory).CurrentParam = (ListBoxParam)annotParam;
  1637. annotHistory.PDFDoc = cPDFDocument;
  1638. break;
  1639. case C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS:
  1640. annotHistory = new SignatureHistory();
  1641. (annotHistory as SignatureHistory).CurrentParam = (SignatureParam)annotParam;
  1642. annotHistory.PDFDoc = cPDFDocument;
  1643. break;
  1644. case C_WIDGET_TYPE.WIDGET_UNKNOWN:
  1645. break;
  1646. default:
  1647. break;
  1648. }
  1649. return true;
  1650. }
  1651. #endregion
  1652. }
  1653. }