AnnotToolContentViewModel.Command.cs 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFAnnotation;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKit.PDFDocument.Action;
  5. using ComPDFKitViewer;
  6. using ComPDFKitViewer.AnnotEvent;
  7. using ComPDFKitViewer.PdfViewer;
  8. using PDF_Master.CustomControl;
  9. using PDF_Master.EventAggregators;
  10. using PDF_Master.Helper;
  11. using PDF_Master.Model.AnnotPanel;
  12. using PDF_Master.Model.FillAndSign;
  13. using PDF_Master.Properties;
  14. using PDF_Master.ViewModels.BOTA;
  15. using PDF_Master.ViewModels.PropertyPanel.AnnotPanel;
  16. using PDF_Master.ViewModels.Tools.AnnotManager;
  17. using PDF_Master.Views.BOTA;
  18. using PDFSettings;
  19. using Prism.Mvvm;
  20. using Prism.Regions;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Diagnostics;
  24. using System.Linq;
  25. using System.Windows;
  26. using System.Windows.Controls;
  27. using System.Windows.Controls.Primitives;
  28. using System.Windows.Input;
  29. using System.Windows.Markup;
  30. using System.Windows.Media;
  31. namespace PDF_Master.ViewModels.Tools
  32. {
  33. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  34. {
  35. #region 事件绑定和解绑
  36. private void BindingEvent()
  37. {
  38. //属性面板与注释工具栏绑定:属性面板的属性变化,会同步注释工具栏的属性值
  39. //比如在属性面板里更改注释颜色,会同时更新工具栏对应的工具颜色
  40. PropertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  41. PropertyPanel.DataChanged += AnnotPropertyPanel_DataChanged;
  42. PropertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  43. PropertyPanel.AnnotTypeChanged += AnnotPropertyPanel_AnnotTypeChanged;
  44. //快捷键
  45. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  46. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  47. }
  48. private void UnBindingEvent()
  49. {
  50. PropertyPanel.DataChanged -= AnnotPropertyPanel_DataChanged;
  51. PropertyPanel.AnnotTypeChanged -= AnnotPropertyPanel_AnnotTypeChanged;
  52. //快捷盘解绑
  53. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  54. }
  55. private void BindingPDFViewerHandler()
  56. {
  57. //来自PDFViewer的响应事件
  58. if (PDFViewer != null)
  59. {
  60. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  61. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  62. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  63. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  64. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  65. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  66. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  67. PDFViewer.SnapshotCommandHandler += PDFViewer_SnapshotCommandHandler;
  68. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  69. PDFViewer.PDFActionHandler += PDFViewer_PDFActionHandler;
  70. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  71. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  72. PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
  73. PDFViewer.PreviewMouseLeftButtonDown += PDFViewer_PreviewMouseLeftButtonDown;
  74. CommandManager.AddPreviewExecutedHandler(PDFViewer, PreviewExcutePDFViewer);
  75. }
  76. }
  77. //判断
  78. private void PreviewExcutePDFViewer(object sender, ExecutedRoutedEventArgs e)
  79. {
  80. if (e.Command == ApplicationCommands.Paste)
  81. {
  82. IsPasteShape = true;
  83. ShapeNames.Clear();
  84. Trace.WriteLine("几次" + 1);
  85. var items = PDFViewer.GetCopyAnnotData();
  86. foreach (var item in items)
  87. {
  88. bool IsShape = false;
  89. if (item is FreehandAnnotArgs)
  90. {
  91. foreach (var point in viewContentViewModel.FillAndSign)
  92. {
  93. if ((item as FreehandAnnotArgs).PageIndex == point.PageIndex && (item as FreehandAnnotArgs).AnnotIndex == point.AnnotIndex)
  94. {
  95. ShapeNames.Add(point.Shape);
  96. Trace.WriteLine("woshi什么" + point.Shape);
  97. IsShape = true;
  98. continue;
  99. }
  100. }
  101. if (!IsShape)
  102. {
  103. ShapeNames.Add("Annot");
  104. Trace.WriteLine("woshi什么" + "Freehand");
  105. }
  106. }
  107. else
  108. {
  109. ShapeNames.Add("Annot");
  110. }
  111. }
  112. }
  113. if (e.Command == ApplicationCommands.Copy)
  114. {
  115. }
  116. }
  117. private void UnBindingPDFViewerHandler()
  118. {
  119. if (PDFViewer != null)
  120. {
  121. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  122. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  123. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  124. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  125. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  126. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  127. PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
  128. }
  129. }
  130. #endregion 事件绑定和解绑
  131. #region 与触发事件调用相关的函数
  132. //鼠标左键双击注释
  133. private void PDFViewer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  134. {
  135. if (e.ClickCount == 1)
  136. {
  137. //不禁止取消选中注释
  138. PDFViewer.DisableClearSelectAnnot(false);
  139. //PropertyPanel.IsSharpAnnotSelected = true;
  140. //PropertyPanel.IsFreeHandSelected = true;
  141. //PDFViewer.ClearSelectAnnots();
  142. //BOTA所有列表都需要响应 单击阅读页取消多选
  143. if (viewContentViewModel.OpenBOTA == true)
  144. {
  145. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  146. }
  147. }
  148. if (e.ClickCount == 2)
  149. {
  150. if (CurrentSelectedAnnot != null)
  151. {
  152. var type = CurrentSelectedAnnot.EventType;
  153. if (type != AnnotArgsType.AnnotSticky && type != AnnotArgsType.AnnotFreeText &&
  154. type != AnnotArgsType.AnnotHighlight && type != AnnotArgsType.AnnotUnderline
  155. && type != AnnotArgsType.AnnotStrikeout && type != AnnotArgsType.AnnotLink)
  156. {
  157. int dpi = DpiHelpers.Dpi;
  158. var rect = CurrentSelectedAnnot.ClientRect;
  159. rect = new Rect(
  160. rect.Left * PDFViewer.ZoomFactor,
  161. rect.Top * PDFViewer.ZoomFactor,
  162. rect.Width * PDFViewer.ZoomFactor,
  163. rect.Height * PDFViewer.ZoomFactor);
  164. var ui = PDFViewer.Parent as ContentControl;
  165. if (ui != null)
  166. {
  167. var point = e.GetPosition(ui);
  168. int pageIndex = 0;
  169. Point pagePoint = new Point(0, 0);
  170. PDFViewer.ConvertViewPointToPage(point, out pageIndex, out pagePoint);
  171. if (pagePoint.X >= rect.Left && pagePoint.X <= rect.Right && pagePoint.Y >= rect.Top && pagePoint.Y <= rect.Bottom)
  172. PopAnnotNoteText(CurrentSelectedAnnot);
  173. }
  174. }
  175. if (type == AnnotArgsType.AnnotSticky)
  176. {
  177. (CurrentSelectedAnnot as StickyAnnotArgs).PopupEditWnd();
  178. }
  179. }
  180. }
  181. }
  182. //超链接跳转
  183. private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
  184. {
  185. if (action == null)
  186. {
  187. return;
  188. }
  189. switch (action.ActionType)
  190. {
  191. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  192. if (PDFViewer != null)
  193. {
  194. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  195. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
  196. if (dest != null)
  197. {
  198. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
  199. }
  200. }
  201. break;
  202. case C_ACTION_TYPE.ACTION_TYPE_URI:
  203. {
  204. CPDFUriAction uriAction = action as CPDFUriAction;
  205. string uri = uriAction.GetUri();
  206. try
  207. {
  208. if (!string.IsNullOrEmpty(uri))
  209. {
  210. Process.Start(uri);
  211. }
  212. }
  213. catch (Exception ex)
  214. {
  215. }
  216. }
  217. break;
  218. }
  219. }
  220. private void GetSelectedAnnots(AnnotAttribEvent e)
  221. {
  222. var annot = e.AnnotItemsList[0];
  223. switch (annot.EventType)
  224. {
  225. case AnnotArgsType.AnnotHighlight:
  226. GetHighLight(e.AnnotItemsList);
  227. break;
  228. case AnnotArgsType.AnnotUnderline:
  229. GetUnderLine(e.AnnotItemsList);
  230. break;
  231. case AnnotArgsType.AnnotStrikeout:
  232. GetStrikeout(e.AnnotItemsList);
  233. break;
  234. case AnnotArgsType.AnnotSquiggly:
  235. GetSquiggly(e.AnnotItemsList);
  236. break;
  237. case AnnotArgsType.AnnotFreehand:
  238. GetFreehand(e.AnnotItemsList);
  239. break;
  240. case AnnotArgsType.AnnotFreeText:
  241. GetFreetext(e.AnnotItemsList);
  242. break;
  243. case AnnotArgsType.AnnotSquare:
  244. GetRect(e.AnnotItemsList);
  245. break;
  246. case AnnotArgsType.AnnotCircle:
  247. GetCircle(e.AnnotItemsList);
  248. break;
  249. case AnnotArgsType.AnnotLine:
  250. bool isLine = true;
  251. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  252. {
  253. if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineStart] != C_LINE_TYPE.LINETYPE_NONE)
  254. {
  255. isLine = false;
  256. }
  257. }
  258. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  259. {
  260. if ((C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_UNKNOWN && (C_LINE_TYPE)e.Attribs[AnnotAttrib.LineEnd] != C_LINE_TYPE.LINETYPE_NONE)
  261. {
  262. isLine = false;
  263. }
  264. }
  265. if (isLine)
  266. GetArrowLine("Line", e.AnnotItemsList);
  267. else
  268. GetArrowLine("Arrow", e.AnnotItemsList);
  269. break;
  270. case AnnotArgsType.AnnotLink:
  271. //viewContentViewModel.IsCreateLink = false;
  272. //e.IsAnnotCreateReset= true;
  273. if (StrAnnotToolChecked == "Link")
  274. {
  275. PropertyPanel.IsAddLink = false;
  276. }
  277. GetLink(e.AnnotItemsList, e);
  278. break;
  279. case AnnotArgsType.AnnotSticky:
  280. GetStickyNote(e.AnnotItemsList);
  281. customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  282. customStickyPopup.GetPDFViewer = PDFViewer;
  283. if (e.IsAnnotCreateReset)
  284. {
  285. PropertyPanel.annot = e.AnnotItemsList[0];
  286. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  287. PropertyPanel.AnnotEvents = null;
  288. PropertyPanel.AnnotEvent = AnnotEvent;
  289. PropertyPanel.annotlists = e.AnnotItemsList;
  290. }
  291. break;
  292. case AnnotArgsType.AnnotStamp:
  293. if (e.IsAnnotCreateReset == false)
  294. {
  295. GetStamp();
  296. }
  297. break;
  298. }
  299. }
  300. /// <summary>
  301. /// 选中注释 区分签名、图章、手绘
  302. /// </summary>
  303. /// <param name="annotlist"></param>
  304. private void SelectedSignature(List<AnnotHandlerEventArgs> annotlist)
  305. {
  306. if (annotlist == null || annotlist.Count == 0)
  307. return;
  308. var annot = annotlist[0];
  309. if (annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand)
  310. return;
  311. if (annot.PageIndex < 0 || annot.AnnotIndex < 0)
  312. return;
  313. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  314. if (signAnnot == null)
  315. {
  316. //var key = ToolExpandDict.FirstOrDefault(q => q.Value == annot.EventType);
  317. //if (!string.IsNullOrEmpty(StrAnnotToolChecked))
  318. // StrAnnotToolChecked = key.Key.ToString();
  319. //if (annot.EventType == AnnotArgsType.AnnotStamp)
  320. //{
  321. // StrAnnotToolChecked = "Stamp";
  322. //}
  323. //else
  324. //{
  325. // StrAnnotToolChecked = "";
  326. //}
  327. }
  328. else
  329. {
  330. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  331. {
  332. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  333. //GetSignature();
  334. //StrAnnotToolChecked = "Signature";
  335. }
  336. }
  337. }
  338. private void AddAnnotSignature(AnnotHandlerEventArgs annot)
  339. {
  340. if ((annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand) ||
  341. (annot.PageIndex < 0 || annot.AnnotIndex < 0)) return;
  342. if (StrAnnotToolChecked == "Signature")
  343. {
  344. if (viewContentViewModel.AnnotSignatures == null)
  345. viewContentViewModel.AnnotSignatures = new List<Tuple<int, int>>();
  346. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  347. if (signAnnot == null)
  348. {
  349. viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(annot.PageIndex, annot.AnnotIndex));
  350. }
  351. }
  352. }
  353. #endregion 与触发事件调用相关的函数
  354. #region PDFViewer事件
  355. private AnnotHandlerEventArgs CurrentSelectedAnnot = null;
  356. private bool isShowPropertyPanel = false;
  357. //选中和非选中注释
  358. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  359. {
  360. CurrentSelectedAnnot = null;
  361. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  362. {
  363. //viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  364. return;
  365. }
  366. if (e == null)
  367. {
  368. //PDFViewer.DisableClearSelectAnnot(false);
  369. //PropertyPanel.IsSharpAnnotSelected = true;
  370. //PropertyPanel.IsFreeHandSelected = true;
  371. if (string.IsNullOrWhiteSpace(StrAnnotToolChecked))
  372. {
  373. //PDFViewer.ClearSelectAnnots();
  374. PropertyPanel.annot = null;
  375. PropertyPanel.AnnotEvents = null;
  376. PropertyPanel.AnnotEvent = null;
  377. PropertyPanel.annotlists = null;
  378. if (PropertyPanel.IsAddLink == false)
  379. {
  380. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  381. }
  382. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  383. //HandToolIsCheckedEvent(false);
  384. return;
  385. }
  386. else
  387. {
  388. if (StrAnnotToolChecked == "Rect" && PropertyPanel.IsSelectedTextAddShape == false)
  389. {
  390. AnnotHandlerEventArgs annotArgs = null;
  391. //此处不能用这个方法更新创建注释的属性 会导致死循环
  392. //选择文字 点击矩形 会导致死循环
  393. // FindAnnotTypeKey(StrAnnotToolChecked, ref annotArgs);
  394. PropertyPanel.annot = null;
  395. PropertyPanel.AnnotEvents = null;
  396. PropertyPanel.AnnotEvent = null;
  397. PropertyPanel.annotlists = null;
  398. switch (PropertyPanel.SharpsAnnot)
  399. {
  400. case "Rect":
  401. annotArgs = GetRect();
  402. break;
  403. case "Circle":
  404. annotArgs = GetCircle();
  405. break;
  406. case "Arrow":
  407. annotArgs = GetArrowLine("Arrow");
  408. break;
  409. case "Line":
  410. annotArgs = GetArrowLine("Line");
  411. break;
  412. }
  413. return;
  414. }
  415. if (StrAnnotToolChecked == "Freehand")
  416. {
  417. GetFreehand();
  418. }
  419. }
  420. }
  421. if (e != null)
  422. {
  423. if (e.IsMouseRightActive)
  424. {
  425. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  426. {
  427. ShowPropertyPanel(false);
  428. return;
  429. }
  430. }
  431. var annot = e.AnnotItemsList[0];
  432. if (annot != null)
  433. {
  434. if (e.AnnotItemsList.Count == 1)
  435. {
  436. viewContentViewModel.IsMultiSelected = false;
  437. //IsAnnotCreateReset:是否为创建注释的状态
  438. if (e.IsAnnotCreateReset == false)
  439. {
  440. CurrentSelectedAnnot = annot;
  441. //未选注释工具-形状注释,选中形状注释,属性面板不显示(矩形、圆、线、箭头)
  442. if (StrAnnotToolChecked != "Rect"
  443. && (annot.EventType == AnnotArgsType.AnnotSquare ||
  444. annot.EventType == AnnotArgsType.AnnotCircle ||
  445. annot.EventType == AnnotArgsType.AnnotLine))
  446. {
  447. PropertyPanel.IsSharpAnnotSelected = false;
  448. }
  449. else
  450. {
  451. PropertyPanel.IsSharpAnnotSelected = true;
  452. }
  453. if (StrAnnotToolChecked != "Freehand" && annot.EventType == AnnotArgsType.AnnotFreehand)
  454. {
  455. PropertyPanel.IsFreeHandSelected = false;
  456. }
  457. else
  458. {
  459. PropertyPanel.IsFreeHandSelected = true;
  460. }
  461. isShowPropertyPanel = viewContentViewModel.IsPropertyOpen;
  462. GetSelectedAnnots(e);
  463. SelectedSignature(e.AnnotItemsList);
  464. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty
  465. && annot.EventType != AnnotArgsType.AnnotStamp && StrAnnotToolChecked != "Signature"
  466. && annot.EventType != AnnotArgsType.AnnotLink)
  467. {
  468. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  469. if (signAnnot == null)
  470. {
  471. if (e.IsMouseRightActive)
  472. {
  473. ShowPropertyPanel(isShowPropertyPanel);
  474. }
  475. else
  476. {
  477. ShowPropertyPanel(true);
  478. }
  479. }
  480. }
  481. else if (StrAnnotToolChecked == "Signature")
  482. {
  483. GetSignature();
  484. }
  485. //注释列表同步选中
  486. SelectedBotaAnnotationList(e);
  487. }
  488. else
  489. {
  490. if (!string.IsNullOrEmpty(StrAnnotToolChecked) || PropertyPanel.IsAddLink == true)
  491. {
  492. GetSelectedAnnots(e);
  493. PDFViewer.SetToolParam(annot);
  494. }
  495. else
  496. {
  497. if (IsNoSelectMenu)
  498. {
  499. return;
  500. }
  501. PropertyPanel.annot = null;
  502. PropertyPanel.AnnotEvents = null;
  503. PropertyPanel.AnnotEvent = null;
  504. PropertyPanel.annotlists = null;
  505. PDFViewer.SetMouseMode(MouseModes.PanTool);
  506. HandToolIsCheckedEvent(false);
  507. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  508. }
  509. //switch (annot.EventType)
  510. //{
  511. // case AnnotArgsType.AnnotFreeText:
  512. // annot = GetFreetext(e.AnnotItemsList);
  513. // PDFViewer.SetToolParam(annot);
  514. // break;
  515. // case AnnotArgsType.AnnotSticky:
  516. // customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  517. // customStickyPopup.GetPDFViewer = PDFViewer;
  518. // propertyPanel.annot = e.AnnotItemsList[0];
  519. // var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  520. // propertyPanel.AnnotEvents = null;
  521. // propertyPanel.AnnotEvent = AnnotEvent;
  522. // propertyPanel.annotlists = e.AnnotItemsList;
  523. // break;
  524. // case AnnotArgsType.AnnotLink:
  525. // //viewContentViewModel.IsCreateLink = false;
  526. // GetLink(e.AnnotItemsList, e);
  527. // PDFViewer.SetToolParam(annot);
  528. // break;
  529. //}
  530. #region //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  531. //注释代码原因:设计已经重新调整逻辑:所有注释创建后,编辑属性,所有属性会作用于下次创建的注释中。
  532. //if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  533. //annot.EventType != AnnotArgsType.AnnotUnderline &&
  534. //annot.EventType != AnnotArgsType.AnnotHighlight &&
  535. //annot.EventType != AnnotArgsType.AnnotSquiggly &&
  536. //annot.EventType != AnnotArgsType.AnnotLink &&
  537. //annot.EventType != AnnotArgsType.AnnotFreehand &&
  538. //annot.EventType != AnnotArgsType.AnnotSticky &&
  539. //)
  540. //{
  541. // if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  542. // {
  543. // var strLineAnnotTag = "";
  544. // if (e.AnnotItemsList[0] is LineAnnotArgs)
  545. // {
  546. // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
  547. // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
  548. // {
  549. // strLineAnnotTag = "Line";
  550. // }
  551. // else
  552. // {
  553. // strLineAnnotTag = "Arrow";
  554. // }
  555. // }
  556. // foreach (var item in ToolExpandDict)
  557. // {
  558. // if (item.Value == e.AnnotItemsList[0].EventType)
  559. // {
  560. // annot = null;//新建注释时,回到默认值
  561. // if (string.IsNullOrEmpty(strLineAnnotTag))
  562. // {
  563. // FindAnnotTypeKey(item.Key, ref annot);
  564. // break;
  565. // }
  566. // else
  567. // {
  568. // if (strLineAnnotTag == item.Key)
  569. // {
  570. // FindAnnotTypeKey(item.Key, ref annot);
  571. // break;
  572. // }
  573. // }
  574. // }
  575. // }
  576. // PDFViewer.SetToolParam(annot);
  577. // }
  578. //}
  579. //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  580. //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
  581. //{
  582. // ShowPropertyPanel(false);
  583. //}
  584. //else
  585. //{
  586. // ShowPropertyPanel();
  587. //}
  588. #endregion //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  589. }
  590. }
  591. else
  592. {
  593. //框选注释
  594. PropertyPanel.annotlists = e.AnnotItemsList;
  595. viewContentViewModel.IsMultiSelected= true;
  596. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  597. ShowPropertyPanel(true);
  598. #region MVP 在对多选注释做处理
  599. //bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
  600. //if (isDifferentAnnotTyle)
  601. // viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  602. //else
  603. // GetSelectedAnnots(e);
  604. #endregion MVP 在对多选注释做处理
  605. }
  606. }
  607. }
  608. }
  609. /// <summary>
  610. /// 注释列表同步选中
  611. /// </summary>
  612. /// <param name="e"></param>
  613. private void SelectedBotaAnnotationList(AnnotAttribEvent e)
  614. {
  615. var list = e.GetPageAnnotsIndex();
  616. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  617. //if (viewContentViewModel.OpenBOTA == false || isTabItemAnnotation == false || bOTAContent.TabItemAnnotation.IsSelected == false)
  618. //{
  619. // viewContentViewModel.OpenBOTA = true;
  620. // bOTAContent.TabItemAnnotation.IsSelected = true;
  621. //}
  622. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true /*&& bOTAContent.TabItemAnnotation.IsSelected == true*/ && list != null && list.Count > 0)
  623. {
  624. if (list.Keys.Count == 0)
  625. {
  626. return;
  627. }
  628. var pageindex = new List<int>(list.Keys);
  629. List<int> annotes = new List<int>();
  630. list.TryGetValue(pageindex[0], out annotes);
  631. int annoteindex = annotes[0];
  632. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  633. if (viewModel != null)
  634. {
  635. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  636. }
  637. }
  638. }
  639. //在注释工具的状态下,右键菜单
  640. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  641. {
  642. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  643. return;
  644. if ((UIElement)sender != null)
  645. {
  646. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  647. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  648. }
  649. switch (e.CommandType)
  650. {
  651. case CommandType.Context:
  652. if (e.AnnotEventArgsList.Count > 0)
  653. {
  654. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  655. {
  656. //绑定标记密文处右键菜单
  657. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  658. }
  659. else
  660. {
  661. if (e.AnnotEventArgsList.Count == 1)
  662. {
  663. var selectedAnnot = e.AnnotEventArgsList[0];
  664. PopMenuCheckedLineDash(selectedAnnot);
  665. PopMenuCheckedFontFamily(selectedAnnot);
  666. PopMenuCheckedTextAglin(selectedAnnot);
  667. switch (selectedAnnot.EventType)
  668. {
  669. case AnnotArgsType.AnnotHighlight:
  670. case AnnotArgsType.AnnotUnderline:
  671. case AnnotArgsType.AnnotStrikeout:
  672. case AnnotArgsType.AnnotSquiggly:
  673. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  674. {
  675. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  676. }
  677. else
  678. {
  679. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  680. }
  681. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  682. break;
  683. case AnnotArgsType.AnnotFreehand:
  684. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  685. break;
  686. case AnnotArgsType.AnnotFreeText:
  687. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  688. break;
  689. case AnnotArgsType.AnnotSticky:
  690. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  691. break;
  692. case AnnotArgsType.AnnotSquare:
  693. case AnnotArgsType.AnnotCircle:
  694. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  695. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  696. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  697. break;
  698. case AnnotArgsType.AnnotLine:
  699. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  700. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  701. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  702. break;
  703. case AnnotArgsType.AnnotLink:
  704. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  705. break;
  706. case AnnotArgsType.AnnotStamp:
  707. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  708. break;
  709. }
  710. }
  711. else
  712. {
  713. bool isHigh = true;//是否为高亮
  714. foreach (var item in e.AnnotEventArgsList)
  715. {
  716. if (AnnotTransfer.IsHightAnnot(item) == false)
  717. {
  718. isHigh = false;
  719. break;
  720. }
  721. }
  722. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  723. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  724. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  725. }
  726. }
  727. if (e.PopupMenu != null)
  728. {
  729. e.Handle = true;
  730. }
  731. }
  732. else
  733. {
  734. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  735. {
  736. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  737. if (e.PopupMenu != null)
  738. {
  739. e.Handle = true;
  740. }
  741. }
  742. else
  743. {
  744. e.PopupMenu = ViewerContextMenu(sender);
  745. if (e.PopupMenu != null)
  746. {
  747. e.Handle = true;
  748. }
  749. }
  750. }
  751. break;
  752. }
  753. }
  754. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  755. {
  756. if (e.Command == ApplicationCommands.Copy)
  757. {
  758. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsCopying, dialogs);
  759. if (result.IsDiscryptied)
  760. {
  761. if (result.Password != null)
  762. {
  763. string filePath = PDFViewer.Document.FilePath;
  764. var unlockresult = PDFViewer.Document.CheckOwnerPassword(result.Password);
  765. }
  766. }
  767. else
  768. {
  769. e.Handled = true;
  770. }
  771. }
  772. }
  773. /// <summary>
  774. /// 右键菜单,选中字体样式按钮状态
  775. /// </summary>
  776. /// <param name="annot"></param>
  777. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  778. {
  779. if (annot != null)
  780. {
  781. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  782. {
  783. var freeText = annot as FreeTextAnnotArgs;
  784. string fontFamily = freeText.FontFamily.ToString();
  785. if (fontFamily == "Arial")
  786. {
  787. fontFamily = "Helvetica";
  788. }
  789. if (fontFamily == "Courier New")
  790. {
  791. fontFamily = "Courier";
  792. }
  793. if (fontFamily == "Times New Roman")
  794. {
  795. fontFamily = "Times";
  796. }
  797. FreeTextAnnotPopMenu.SetIsChecked(fontFamily, true);
  798. }
  799. }
  800. }
  801. /// <summary>
  802. /// 右键菜单,选中文本内容对齐按钮状态
  803. /// </summary>
  804. /// <param name="annot"></param>
  805. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  806. {
  807. if (annot != null)
  808. {
  809. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  810. {
  811. var freeText = annot as FreeTextAnnotArgs;
  812. switch (freeText.Align)
  813. {
  814. case TextAlignment.Left:
  815. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  816. break;
  817. case TextAlignment.Center:
  818. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  819. break;
  820. case TextAlignment.Right:
  821. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  822. break;
  823. case TextAlignment.Justify:
  824. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  825. break;
  826. default:
  827. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  828. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  829. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  830. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  831. break;
  832. }
  833. }
  834. }
  835. }
  836. //右键菜单,选中虚实线按钮状态
  837. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  838. {
  839. if (annot != null)
  840. {
  841. bool isSolidLineDash = true;
  842. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  843. {
  844. var freeHand = annot as FreehandAnnotArgs;
  845. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  846. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  847. }
  848. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  849. {
  850. var square = annot as SquareAnnotArgs;
  851. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  852. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  853. }
  854. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  855. {
  856. var circle = annot as CircleAnnotArgs;
  857. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  858. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  859. }
  860. else if (annot.EventType == AnnotArgsType.AnnotLine)
  861. {
  862. var line = annot as LineAnnotArgs;
  863. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  864. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  865. }
  866. }
  867. }
  868. /// <summary>
  869. /// 内容选择工具
  870. /// </summary>
  871. /// <param name="sender"></param>
  872. /// <param name="e"></param>
  873. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  874. {
  875. SnapshotEditToolArgs snapToolArgs = new SnapshotEditToolArgs();
  876. if (PDFViewer.ToolManager.CurrentAnnotArgs is SnapshotEditToolArgs)
  877. {
  878. snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  879. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  880. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  881. SnapshotEditMenuViewModel.areaCropPageUndoManager = new AreaCropPageUndoManager(PDFViewer);
  882. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  883. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  884. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  885. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  886. {
  887. e.PopupMenu = popMenu;
  888. e.Handle = true;
  889. if (popMenu != null && popMenu.Items.Count == 5)
  890. {
  891. //复制
  892. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  893. menuItem.CommandTarget = PDFViewer;
  894. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  895. //导出
  896. menuItem = popMenu.Items[1] as MenuItem;
  897. menuItem.CommandTarget = PDFViewer;
  898. if (menuItem.Items.Count == 3)
  899. {
  900. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  901. menuItem1.CommandTarget = PDFViewer;
  902. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  903. menuItem1 = menuItem.Items[1] as MenuItem;
  904. menuItem1.CommandTarget = PDFViewer;
  905. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  906. menuItem1 = menuItem.Items[2] as MenuItem;
  907. menuItem1.CommandTarget = PDFViewer;
  908. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  909. }
  910. //裁剪
  911. menuItem = popMenu.Items[2] as MenuItem;
  912. menuItem.CommandTarget = PDFViewer;
  913. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  914. //缩放至所选区域
  915. menuItem = popMenu.Items[3] as MenuItem;
  916. menuItem.CommandTarget = PDFViewer;
  917. menuItem.Visibility = Visibility.Collapsed;
  918. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  919. //打印
  920. menuItem = popMenu.Items[4] as MenuItem;
  921. menuItem.CommandTarget = PDFViewer;
  922. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  923. }
  924. }
  925. }
  926. }
  927. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  928. {
  929. switch (e.Key)
  930. {
  931. case "CloseSnap":
  932. {
  933. #region to do
  934. //var item = PDFViewerTab.SelectedItem as TabItem;
  935. //if (item == null)
  936. //{
  937. // ClearSelectedToolPanel();
  938. // return;
  939. //}
  940. //Grid grid = item.Content as Grid;
  941. //if (grid == null || grid.Children.Count == 0)
  942. //{
  943. // ClearSelectedToolPanel();
  944. // return;
  945. //}
  946. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  947. //if (pdfViewer == null)
  948. //{
  949. // ClearSelectedToolPanel();
  950. // return;
  951. //}
  952. #endregion to do
  953. switch (PDFViewer.MouseMode)
  954. {
  955. case MouseModes.SelectTextTool:
  956. break;
  957. default:
  958. BtnSelecttoolIsChecked = false;
  959. //BtnHandIsChecked = true;
  960. PDFViewer.EnableZoom(true);
  961. PDFViewer.EnableScroll(true);
  962. PDFViewer.SetMouseMode(MouseModes.PanTool);
  963. HandToolIsCheckedEvent(false);
  964. break;
  965. }
  966. }
  967. break;
  968. default:
  969. break;
  970. }
  971. }
  972. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  973. {
  974. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  975. AnnotationContentViewModel viewModel = null;
  976. AnnotationContent annotation = null;
  977. if (viewContentViewModel.OpenBOTA == true)
  978. {
  979. viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out annotation);
  980. }
  981. bool isMultiple = false;
  982. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  983. if (e != null && e.Count > 0)
  984. {
  985. for (int i = 0; i < e.Count; i++)
  986. {
  987. AnnotEditEvent editEvent = e[i];
  988. bool isVisible = PDFViewer.CheckAnnotVisible(editEvent.PageIndex, editEvent.AnnotIndex);
  989. var annot = editEvent.EditAnnotArgs;
  990. switch (editEvent.EditAction)
  991. {
  992. case ActionType.Add:
  993. #region 区分复制填写签名图形
  994. if (IsPasteShape)
  995. {
  996. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreehand)
  997. {
  998. if (ShapeNames.Count != 0 && ShapeNames[i] != "Annot")
  999. {
  1000. try
  1001. {
  1002. viewContentViewModel.FillAndSign.Add(new FillAndSignIsShape(editEvent.PageIndex, editEvent.AnnotIndex, ShapeNames[i]));
  1003. }
  1004. catch { }
  1005. }
  1006. }
  1007. }
  1008. #endregion 区分复制填写签名图形
  1009. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  1010. {
  1011. //填写与签名在此区域不选中,不添加selectAnnotDicts词典当中
  1012. }
  1013. else
  1014. {
  1015. if (PropertyPanel.IsMultiSelected)
  1016. {
  1017. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  1018. {
  1019. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  1020. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1021. }
  1022. else
  1023. {
  1024. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1025. }
  1026. isMultiple = true;
  1027. }
  1028. else
  1029. {
  1030. if (
  1031. annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  1032. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp ||
  1033. annot.EventType == AnnotArgsType.AnnotLink
  1034. /*|| annot.EventType == AnnotArgsType.AnnotSticky ||annot.EventType == AnnotArgsType.AnnotFreeText || annot.EventType == AnnotArgsType.AnnotFreehand*/)
  1035. {
  1036. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  1037. {
  1038. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  1039. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1040. }
  1041. else
  1042. {
  1043. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1044. }
  1045. isMultiple = true;
  1046. }
  1047. }
  1048. }
  1049. if (viewModel != null)
  1050. {
  1051. int pageindex = editEvent.PageIndex;
  1052. int annotindex = editEvent.AnnotIndex;
  1053. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  1054. }
  1055. //添加书签注释,用于未保存前跟图章手绘注释的区分
  1056. if (StrAnnotToolChecked == "Signature")
  1057. {
  1058. AddAnnotSignature(editEvent.EditAnnotArgs);
  1059. }
  1060. //if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  1061. //{
  1062. // (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  1063. //}
  1064. break;
  1065. case ActionType.Modify:
  1066. //if (string.IsNullOrEmpty(StrAnnotToolChecked) == false)
  1067. //{
  1068. // List<AnnotHandlerEventArgs> selectedArgs = new List<AnnotHandlerEventArgs>() { annot };
  1069. // switch (annot.EventType)
  1070. // {
  1071. // case AnnotArgsType.AnnotFreeText://文本
  1072. // GetFreetext(selectedArgs);
  1073. // break;
  1074. // }
  1075. //}
  1076. if (viewModel != null)
  1077. {
  1078. int pageindex = editEvent.PageIndex;
  1079. int annotindex = editEvent.AnnotIndex;
  1080. viewModel.UpdateModifiedAnnot(pageindex, annotindex);
  1081. }
  1082. break;
  1083. case ActionType.Del:
  1084. //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1085. //if (viewContentViewModel.OpenBOTA == true && bOTAContent.TabItemAnnotation.IsSelected)
  1086. //{
  1087. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1088. #region//填写与签名 删除缓存信息列表
  1089. //if (Shape != "None")
  1090. //{
  1091. for (int j = 0; j < viewContentViewModel.FillAndSign.Count; j++)
  1092. {
  1093. if (viewContentViewModel.FillAndSign[j].PageIndex == editEvent.PageIndex && viewContentViewModel.FillAndSign[j].AnnotIndex == editEvent.AnnotIndex)
  1094. {
  1095. viewContentViewModel.FillAndSign.Remove(viewContentViewModel.FillAndSign[j]);
  1096. }
  1097. }
  1098. for (int j = 0; j < viewContentViewModel.AnnotSignatures.Count; j++)
  1099. {
  1100. if (viewContentViewModel.AnnotSignatures[j].Item1 == editEvent.PageIndex && viewContentViewModel.AnnotSignatures[j].Item2 == editEvent.AnnotIndex)
  1101. {
  1102. viewContentViewModel.AnnotSignatures.Remove(viewContentViewModel.AnnotSignatures[j]);
  1103. }
  1104. }
  1105. //}
  1106. #endregion PDFViewer事件
  1107. if (viewModel != null)
  1108. {
  1109. int pageindex = editEvent.PageIndex;
  1110. int annotindex = editEvent.AnnotIndex;
  1111. viewModel.DeleteModifiedAnnot(pageindex, annotindex);
  1112. }
  1113. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  1114. {
  1115. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  1116. {
  1117. //填写与签名在此区域不选中,不添加selectAnnotDicts词典当中
  1118. }
  1119. else
  1120. {
  1121. ExitAnnotationTool();
  1122. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1123. }
  1124. }
  1125. else
  1126. {
  1127. switch (StrAnnotToolChecked)
  1128. {
  1129. case "Link":
  1130. PropertyPanel.IsAddLink = true;
  1131. GetLink();
  1132. break;
  1133. }
  1134. }
  1135. break;
  1136. case ActionType.TextEdit:
  1137. break;
  1138. default:
  1139. break;
  1140. }
  1141. }
  1142. IsPasteShape = false;
  1143. if (isMultiple && selectAnnotDicts.Count >= 1)
  1144. {
  1145. //PDFViewer.DisableClearSelectAnnot(false);
  1146. PDFViewer.ClearSelectAnnots();
  1147. if (StrAnnotToolChecked != "Signature")
  1148. {
  1149. //PDFViewer.DisableClearSelectAnnot(true);
  1150. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1151. //禁止取消选中注释
  1152. //PDFViewer.DisableClearSelectAnnot(false);
  1153. }
  1154. }
  1155. //MultipleSelectionAnnot(e);
  1156. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  1157. if (IsNoSelectMenu && PropertyPanel.IsAddLink == false)
  1158. {
  1159. viewContentViewModel.ReadModeIsShowProperty = false;
  1160. IsNoSelectMenu = false;
  1161. ExitAnnotationTool();
  1162. }
  1163. if (viewContentViewModel.IsRightMenuSelectedTextAddLink == false)
  1164. {
  1165. viewContentViewModel.ReadModeIsShowProperty = false;
  1166. }
  1167. }
  1168. }
  1169. //复制多个注释,粘贴后,默认注释未选中状态
  1170. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  1171. {
  1172. bool isAdd = false;
  1173. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  1174. foreach (var item in e)
  1175. {
  1176. if (item.EditAction == ActionType.Add || item.EditAction == ActionType.Modify)
  1177. {
  1178. var annot = item.EditAnnotArgs;
  1179. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  1180. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText || annot.EventType == AnnotArgsType.AnnotFreehand)
  1181. {
  1182. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  1183. {
  1184. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  1185. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  1186. }
  1187. else
  1188. {
  1189. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  1190. }
  1191. isAdd = true;
  1192. }
  1193. }
  1194. }
  1195. if (isAdd && selectAnnotDicts.Count >= 1)
  1196. {
  1197. PDFViewer.ClearSelectAnnots();
  1198. if (StrAnnotToolChecked != "Signature")
  1199. {
  1200. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1201. }
  1202. }
  1203. }
  1204. //阅读页悬浮相应
  1205. /// <summary>
  1206. /// 阅读页鼠标悬浮在注释上的虚线
  1207. /// </summary>
  1208. /// <param name="sender"></param>
  1209. /// <param name="e"></param>
  1210. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1211. {
  1212. if (e != null && e.DrawContext != null)
  1213. {
  1214. if (StrAnnotToolChecked != "Link")
  1215. {
  1216. if (e.Annot is CPDFLinkAnnotation linkAnnotation)
  1217. {
  1218. return;
  1219. }
  1220. }
  1221. if (StrAnnotToolChecked == "Freehand" || (IsNoSelectMenu && isRightMenuAddAnnot))
  1222. {
  1223. return;
  1224. }
  1225. Rect hoverRect = new Rect(
  1226. e.PaintRect.Left - 2,
  1227. e.PaintRect.Top - 2,
  1228. e.PaintRect.Width + 4,
  1229. e.PaintRect.Height + 4);
  1230. if (e.Annot is CPDFTextAnnotation sticky)
  1231. {
  1232. hoverRect = new Rect(
  1233. e.PaintRect.Left - 2,
  1234. e.PaintRect.Top + 2,
  1235. e.PaintRect.Width + 5,
  1236. e.PaintRect.Height + 2);
  1237. }
  1238. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1239. hoverPen.DashStyle = DashStyles.Dash;
  1240. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1241. //便签,显示ToolTip内容
  1242. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  1243. {
  1244. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  1245. return;
  1246. }
  1247. }
  1248. CloseAnnotToolTip();
  1249. }
  1250. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1251. {
  1252. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1253. {
  1254. //鼠标移到注释之外,关闭ToolTip浮窗
  1255. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1256. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1257. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1258. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1259. {
  1260. CloseAnnotToolTip();
  1261. }
  1262. }
  1263. }
  1264. private Rect oldRect = new Rect(0, 0, 0, 0);
  1265. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  1266. {
  1267. //便签,显示ToolTip内容
  1268. if (PDFViewer.ToolTip == null)
  1269. {
  1270. if (string.IsNullOrEmpty(content) == false)
  1271. {
  1272. ToolTip TipChild = new ToolTip();
  1273. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  1274. TipChild.MaxWidth = 246;
  1275. TipChild.Content = content;
  1276. TipChild.Visibility = Visibility.Visible;
  1277. TipChild.IsOpen = true;
  1278. TipChild.Placement = PlacementMode.Right;
  1279. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  1280. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  1281. TipChild.Placement = PlacementMode.MousePoint;
  1282. PDFViewer.ToolTip = TipChild;
  1283. oldRect = hoverRect;
  1284. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1285. PDFViewer.MouseMove += PDFViewer_MouseMove;
  1286. }
  1287. }
  1288. }
  1289. //关闭ToolTip
  1290. private void CloseAnnotToolTip()
  1291. {
  1292. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1293. {
  1294. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1295. oldTips.IsOpen = false;
  1296. oldTips.Visibility = Visibility.Collapsed;
  1297. PDFViewer.ToolTip = null;
  1298. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1299. oldRect = new Rect(0, 0, 0, 0);
  1300. }
  1301. }
  1302. #endregion PDFViewer事件
  1303. #region BindingEvent事件
  1304. //同一属性面板,不同的注释类型
  1305. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1306. {
  1307. if (e != null && sender is SharpsAnnotPropertyViewModel sharpsAnnot)
  1308. {
  1309. AnnotHandlerEventArgs annotArgs = null;
  1310. //PropertyPanel.SaveLastAnnot();
  1311. List<AnnotHandlerEventArgs> annots = new List<AnnotHandlerEventArgs>();
  1312. foreach (AnnotArgsType argsType in e.Keys)
  1313. {
  1314. if (PropertyPanel.annot != null)
  1315. {
  1316. if (PropertyPanel.annot.EventType != argsType)
  1317. {
  1318. PDFViewer.DisableClearSelectAnnot(false);
  1319. PDFViewer.ClearSelectAnnots();
  1320. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1321. CurrentSelectedAnnot = null;
  1322. }
  1323. }
  1324. switch (argsType)
  1325. {
  1326. case AnnotArgsType.AnnotSquare:
  1327. #region TO DO
  1328. //选择一个形状注释A,在选择B(非多选),修改属性成功,以下操作的操作可以解决,
  1329. //可能会出现选择注释A,鼠标直接点击属性面板,注释A取消选中,但还可以对注释A更改属性的BUG
  1330. if (CurrentSelectedAnnot != null)
  1331. {
  1332. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotSquare)
  1333. {
  1334. CurrentSelectedAnnot.PageIndex = -1;
  1335. CurrentSelectedAnnot.AnnotIndex = -1;
  1336. CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1337. annots.Add(CurrentSelectedAnnot);
  1338. }
  1339. }
  1340. if (annots.Count > 0)
  1341. {
  1342. annotArgs = GetRect(annots);
  1343. }
  1344. else
  1345. {
  1346. annotArgs = GetRect();
  1347. }
  1348. #endregion TO DO
  1349. //annotArgs = GetRect();
  1350. break;
  1351. case AnnotArgsType.AnnotCircle:
  1352. #region TO DO
  1353. if (CurrentSelectedAnnot != null)
  1354. {
  1355. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotCircle)
  1356. {
  1357. CurrentSelectedAnnot.PageIndex = -1;
  1358. CurrentSelectedAnnot.AnnotIndex = -1;
  1359. CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1360. annots.Add(CurrentSelectedAnnot);
  1361. }
  1362. }
  1363. if (annots.Count > 0)
  1364. {
  1365. annotArgs = GetCircle(annots);
  1366. }
  1367. else
  1368. {
  1369. annotArgs = GetCircle();
  1370. }
  1371. #endregion TO DO
  1372. //annotArgs = GetCircle();
  1373. break;
  1374. case AnnotArgsType.AnnotLine:
  1375. var LineTag = e[argsType] as string;
  1376. #region TO DO
  1377. if (CurrentSelectedAnnot != null)
  1378. {
  1379. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotLine)
  1380. {
  1381. CurrentSelectedAnnot.PageIndex = -1;
  1382. CurrentSelectedAnnot.AnnotIndex = -1;
  1383. CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1384. if (CurrentSelectedAnnot is LineAnnotArgs lineAnnotArgs)
  1385. {
  1386. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  1387. {
  1388. if (LineTag == "Arrow")
  1389. {
  1390. annots.Add(CurrentSelectedAnnot);
  1391. }
  1392. }
  1393. else
  1394. {
  1395. if (LineTag == "Line")
  1396. {
  1397. annots.Add(CurrentSelectedAnnot);
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. if (annots.Count > 0)
  1404. {
  1405. annotArgs = GetArrowLine(LineTag, annots);
  1406. }
  1407. else
  1408. {
  1409. annotArgs = GetArrowLine(LineTag);
  1410. }
  1411. #endregion TO DO
  1412. //annotArgs = GetArrowLine(LineTag);
  1413. break;
  1414. }
  1415. ShowPropertyPanel();
  1416. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  1417. {
  1418. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  1419. return;
  1420. }
  1421. if (annotArgs != null)
  1422. {
  1423. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1424. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1425. PDFViewer.SetToolParam(annotArgs);
  1426. }
  1427. }
  1428. }
  1429. }
  1430. //来自属性面板的事件,更改颜色等属性而触发
  1431. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1432. {
  1433. if (e != null)
  1434. {
  1435. foreach (AnnotArgsType argsType in e.Keys)
  1436. {
  1437. var key = ToolExpandDict.FirstOrDefault(q => q.Value == argsType);
  1438. switch (argsType)
  1439. {
  1440. case AnnotArgsType.AnnotHighlight:
  1441. if (e[argsType] is Color)
  1442. {
  1443. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  1444. }
  1445. if (e[argsType] is double)
  1446. {
  1447. HighLightOpacity = (double)e[argsType];
  1448. }
  1449. //创建注释后,修改注释属性,可用于下次创建的注释
  1450. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1451. {
  1452. if (StrAnnotToolChecked == key.Key)
  1453. {
  1454. PDFViewer.SetToolParam(PropertyPanel.annot);
  1455. }
  1456. }
  1457. break;
  1458. case AnnotArgsType.AnnotUnderline:
  1459. if (e[argsType] is Color)
  1460. {
  1461. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  1462. }
  1463. if (e[argsType] is double)
  1464. {
  1465. underLineOpacity = (double)e[argsType];
  1466. }
  1467. //创建注释后,修改注释属性,可用于下次创建的注释
  1468. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1469. {
  1470. if (StrAnnotToolChecked == key.Key)
  1471. {
  1472. PDFViewer.SetToolParam(PropertyPanel.annot);
  1473. }
  1474. }
  1475. break;
  1476. case AnnotArgsType.AnnotSquiggly:
  1477. if (e[argsType] is Color)
  1478. {
  1479. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1480. }
  1481. if (e[argsType] is double)
  1482. {
  1483. SquigglyOpacity = (double)e[argsType];
  1484. }
  1485. //创建注释后,修改注释属性,可用于下次创建的注释
  1486. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1487. {
  1488. if (StrAnnotToolChecked == key.Key)
  1489. {
  1490. PDFViewer.SetToolParam(PropertyPanel.annot);
  1491. }
  1492. }
  1493. break;
  1494. case AnnotArgsType.AnnotStrikeout:
  1495. if (e[argsType] is Color)
  1496. {
  1497. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1498. }
  1499. if (e[argsType] is double)
  1500. {
  1501. StrikeoutOpacity = (double)e[argsType];
  1502. }
  1503. //创建注释后,修改注释属性,可用于下次创建的注释
  1504. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1505. {
  1506. if (StrAnnotToolChecked == key.Key)
  1507. {
  1508. PDFViewer.SetToolParam(PropertyPanel.annot);
  1509. }
  1510. }
  1511. break;
  1512. case AnnotArgsType.AnnotFreehand:
  1513. if (e[argsType] is FreehandAnnotArgs)
  1514. {
  1515. var annot = e[argsType] as FreehandAnnotArgs;
  1516. if (annot != null)
  1517. {
  1518. if (PropertyPanel != null)
  1519. {
  1520. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1521. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1522. PropertyPanel.AnnotEvent = AnnotEvent;
  1523. var AnnotEvents = new List<AnnotAttribEvent>();
  1524. AnnotEvents.Add(AnnotEvent);
  1525. PropertyPanel.AnnotEvents = AnnotEvents;
  1526. PropertyPanel.annot = annot;
  1527. //手绘注释工具按钮的属性
  1528. // FreehandPath.Opacity = annot.Transparency;
  1529. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1530. }
  1531. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1532. {
  1533. if (StrAnnotToolChecked == key.Key)
  1534. {
  1535. PDFViewer.SetToolParam(PropertyPanel.annot);
  1536. }
  1537. }
  1538. }
  1539. }
  1540. break;
  1541. case AnnotArgsType.AnnotErase:
  1542. if (e[argsType] is ToggleButton)
  1543. {
  1544. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1545. if (clickBtn.IsChecked == true)
  1546. {
  1547. if (clickBtn.Tag.ToString() != "PenBtn")
  1548. {
  1549. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1550. btn.Tag = "Freehand";
  1551. btn.IsChecked = true;
  1552. BtnMyTools_Click(btn);
  1553. break;
  1554. }
  1555. else
  1556. {
  1557. CreateEraseArgs();
  1558. }
  1559. }
  1560. }
  1561. break;
  1562. case AnnotArgsType.AnnotSquare:
  1563. case AnnotArgsType.AnnotCircle:
  1564. case AnnotArgsType.AnnotLine:
  1565. case AnnotArgsType.AnnotFreeText:
  1566. //创建注释后,修改注释属性,可用于下次创建的注释
  1567. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1568. {
  1569. if (StrAnnotToolChecked == "Rect" && PropertyPanel.SharpsAnnot == key.Key)
  1570. {
  1571. PDFViewer.SetToolParam(PropertyPanel.annot);
  1572. PropertyPanel.SaveLastAnnot();
  1573. }
  1574. }
  1575. break;
  1576. }
  1577. }
  1578. }
  1579. }
  1580. private void CreateEraseArgs()
  1581. {
  1582. EraseArgs eraseArgs = new EraseArgs();
  1583. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1584. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1585. eraseArgs.Thickness = 10;
  1586. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1587. if (annotProperty != null)
  1588. {
  1589. eraseArgs.Thickness = annotProperty.Thickness;
  1590. }
  1591. PDFViewer.ClearSelectAnnots(false);
  1592. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1593. PDFViewer.SetToolParam(eraseArgs);
  1594. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1595. if (eraseArgs != null)
  1596. eraseArgsList.Add(eraseArgs);
  1597. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1598. }
  1599. #endregion BindingEvent事件
  1600. }
  1601. }