CPDFViewerTool.Command.cs 82 KB

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