AnnotToolContentViewModel.Command.cs 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument.Action;
  3. using ComPDFKit.PDFDocument;
  4. using ComPDFKitViewer;
  5. using ComPDFKitViewer.AnnotEvent;
  6. using ComPDFKitViewer.PdfViewer;
  7. using PDF_Office.CustomControl;
  8. using PDF_Office.EventAggregators;
  9. using PDF_Office.Helper;
  10. using PDF_Office.Properties;
  11. using PDF_Office.ViewModels.BOTA;
  12. using PDF_Office.Views.BOTA;
  13. using PDFSettings;
  14. using Prism.Mvvm;
  15. using Prism.Regions;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Linq;
  19. using System.Text;
  20. using System.Threading.Tasks;
  21. using System.Windows;
  22. using System.Windows.Controls;
  23. using System.Windows.Controls.Primitives;
  24. using System.Windows.Media;
  25. using System.Diagnostics;
  26. using PDF_Office.Model.AnnotPanel;
  27. using System.Windows.Input;
  28. using PDF_Office.ViewModels.Tools.AnnotManager;
  29. using ComPDFKit.Import;
  30. using System.Windows.Markup;
  31. namespace PDF_Office.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. }
  75. }
  76. private void UnBindingPDFViewerHandler()
  77. {
  78. if (PDFViewer != null)
  79. {
  80. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  81. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  82. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  83. PDFViewer.SnapshotCommandHandler -= PDFViewer_SnapshotCommandHandler;
  84. PDFViewer.PDFActionHandler -= PDFViewer_PDFActionHandler;
  85. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  86. PDFViewer.PreviewMouseLeftButtonDown -= PDFViewer_PreviewMouseLeftButtonDown;
  87. }
  88. }
  89. #endregion 事件绑定和解绑
  90. #region 与触发事件调用相关的函数
  91. //鼠标左键双击注释
  92. private void PDFViewer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  93. {
  94. if (e.ClickCount == 1)
  95. {
  96. //if (sender is CPDFViewer pDFViewer)
  97. //{
  98. // if (pDFViewer.ToolManager.CurrentAnnotArgs != null)
  99. // {
  100. // if (pDFViewer.ToolManager.CurrentAnnotArgs is FreehandAnnotArgs freehand)
  101. // {
  102. // PDFViewer.SelectAnnotation(freehand.PageIndex, freehand.AnnotIndex);
  103. // }
  104. // }
  105. //}
  106. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemBookMark");
  107. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemBookMark.IsSelected == true)
  108. {
  109. this.events.GetEvent<CleanSelectAllEvent>().Publish(new CleanSelectAllArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsCleanSelectAll = true });
  110. }
  111. }
  112. if (e.ClickCount == 2)
  113. {
  114. if (CurrentSelectedAnnot != null)
  115. {
  116. var type = CurrentSelectedAnnot.EventType;
  117. if (type != AnnotArgsType.AnnotSticky && type != AnnotArgsType.AnnotFreeText &&
  118. type != AnnotArgsType.AnnotHighlight && type != AnnotArgsType.AnnotUnderline && type != AnnotArgsType.AnnotStrikeout)
  119. {
  120. int dpi = DpiHelpers.Dpi;
  121. var rect = CurrentSelectedAnnot.ClientRect;
  122. //rect = new Rect(
  123. // rect.Left / 72D * dpi,
  124. // rect.Top / 72D * dpi,
  125. // rect.Width / 72D * dpi,
  126. // rect.Height / 72D * dpi);
  127. var ui = PDFViewer.Parent as ContentControl;
  128. if (ui != null)
  129. {
  130. var point = e.GetPosition(ui);
  131. double x = point.X / 72D * dpi;
  132. double y = point.Y / 72D * dpi;
  133. point = new Point(x, y);
  134. //if (rect.Contains(point))
  135. //{
  136. PopAnnotNoteText(CurrentSelectedAnnot);
  137. //}
  138. //if (rect.Left <= x && rect.Right >= x && rect.Top <= y && rect.Bottom >= y)
  139. ////if (rect.Left < x && rect.Top > y && (rect.Width + rect.X) >= x && (rect.Height + rect.Y) >= y)
  140. //{
  141. // PopAnnotNoteText(CurrentSelectedAnnot);
  142. //}
  143. }
  144. }
  145. if (type == AnnotArgsType.AnnotSticky)
  146. {
  147. (CurrentSelectedAnnot as StickyAnnotArgs).PopupEditWnd();
  148. }
  149. }
  150. }
  151. }
  152. //超链接跳转
  153. private void PDFViewer_PDFActionHandler(object sender, ComPDFKit.PDFDocument.Action.CPDFAction action)
  154. {
  155. if (action == null)
  156. {
  157. return;
  158. }
  159. switch (action.ActionType)
  160. {
  161. case C_ACTION_TYPE.ACTION_TYPE_GOTO:
  162. if (PDFViewer != null)
  163. {
  164. CPDFGoToAction gotoAction = action as CPDFGoToAction;
  165. CPDFDestination dest = gotoAction.GetDestination(PDFViewer.Document);
  166. if (dest != null)
  167. {
  168. PDFViewer.GoToPage(dest.PageIndex, new System.Windows.Point(0, 0));
  169. }
  170. }
  171. break;
  172. case C_ACTION_TYPE.ACTION_TYPE_URI:
  173. {
  174. CPDFUriAction uriAction = action as CPDFUriAction;
  175. string uri = uriAction.GetUri();
  176. try
  177. {
  178. if (!string.IsNullOrEmpty(uri))
  179. {
  180. Process.Start(uri);
  181. }
  182. }
  183. catch (Exception ex)
  184. {
  185. }
  186. }
  187. break;
  188. }
  189. }
  190. private void GetSelectedAnnots(AnnotAttribEvent e)
  191. {
  192. var annot = e.AnnotItemsList[0];
  193. switch (annot.EventType)
  194. {
  195. case AnnotArgsType.AnnotHighlight:
  196. GetHighLight(e.AnnotItemsList);
  197. break;
  198. case AnnotArgsType.AnnotUnderline:
  199. GetUnderLine(e.AnnotItemsList);
  200. break;
  201. case AnnotArgsType.AnnotStrikeout:
  202. GetStrikeout(e.AnnotItemsList);
  203. break;
  204. case AnnotArgsType.AnnotSquiggly:
  205. GetSquiggly(e.AnnotItemsList);
  206. break;
  207. case AnnotArgsType.AnnotFreehand:
  208. GetFreehand(e.AnnotItemsList);
  209. break;
  210. case AnnotArgsType.AnnotFreeText:
  211. GetFreetext(e.AnnotItemsList);
  212. break;
  213. case AnnotArgsType.AnnotSquare:
  214. GetRect(e.AnnotItemsList);
  215. break;
  216. case AnnotArgsType.AnnotCircle:
  217. GetCircle(e.AnnotItemsList);
  218. break;
  219. case AnnotArgsType.AnnotLine:
  220. bool isLine = true;
  221. if (e.Attribs.ContainsKey(AnnotAttrib.LineStart))
  222. {
  223. 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)
  224. {
  225. isLine = false;
  226. }
  227. }
  228. if (e.Attribs.ContainsKey(AnnotAttrib.LineEnd))
  229. {
  230. 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)
  231. {
  232. isLine = false;
  233. }
  234. }
  235. if (isLine)
  236. GetArrowLine("Line", e.AnnotItemsList);
  237. else
  238. GetArrowLine("Arrow", e.AnnotItemsList);
  239. break;
  240. case AnnotArgsType.AnnotLink:
  241. //viewContentViewModel.IsCreateLink = false;
  242. //e.IsAnnotCreateReset= true;
  243. if (btnLinkIsChecked == false)
  244. {
  245. propertyPanel.IsAddLink = false;
  246. }
  247. GetLink(e.AnnotItemsList, e);
  248. break;
  249. case AnnotArgsType.AnnotSticky:
  250. GetStickyNote(e.AnnotItemsList);
  251. customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  252. customStickyPopup.GetPDFViewer = PDFViewer;
  253. break;
  254. case AnnotArgsType.AnnotStamp:
  255. GetStamp();
  256. break;
  257. }
  258. }
  259. private void SelectedSignature(List<AnnotHandlerEventArgs> annotlist)
  260. {
  261. if (annotlist == null || annotlist.Count == 0)
  262. return;
  263. var annot = annotlist[0];
  264. if (annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand)
  265. return;
  266. if (annot.PageIndex < 0 || annot.AnnotIndex < 0)
  267. return;
  268. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  269. if (signAnnot == null)
  270. {
  271. if (annot.EventType == AnnotArgsType.AnnotStamp)
  272. {
  273. StrAnnotToolChecked = "Stamp";
  274. }
  275. //else
  276. //{
  277. // StrAnnotToolChecked = "";
  278. //}
  279. }
  280. else
  281. {
  282. GetSignature();
  283. StrAnnotToolChecked = "Signature";
  284. }
  285. }
  286. private void AddAnnotSignature(AnnotHandlerEventArgs annot)
  287. {
  288. if ((annot.EventType != AnnotArgsType.AnnotStamp && annot.EventType != AnnotArgsType.AnnotFreehand) ||
  289. (annot.PageIndex < 0 || annot.AnnotIndex < 0)) return;
  290. if (StrAnnotToolChecked == "Signature")
  291. {
  292. if (viewContentViewModel.AnnotSignatures == null)
  293. viewContentViewModel.AnnotSignatures = new List<Tuple<int, int>>();
  294. var signAnnot = viewContentViewModel.AnnotSignatures.FirstOrDefault(temp => temp.Item1 == annot.PageIndex && temp.Item2 == annot.AnnotIndex);
  295. if (signAnnot == null)
  296. {
  297. viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(annot.PageIndex, annot.AnnotIndex));
  298. }
  299. }
  300. }
  301. #endregion 与触发事件调用相关的函数
  302. #region PDFViewer事件
  303. private AnnotHandlerEventArgs CurrentSelectedAnnot = null;
  304. //选中和非选中注释
  305. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  306. {
  307. if (e != null)
  308. {
  309. CurrentSelectedAnnot = null;
  310. var annot = e.AnnotItemsList[0];
  311. if (annot != null)
  312. {
  313. if (e.AnnotItemsList.Count == 1)
  314. {
  315. //IsAnnotCreateReset:是否为创建注释的状态
  316. if (e.IsAnnotCreateReset == false)
  317. {
  318. GetSelectedAnnots(e);
  319. SelectedSignature(e.AnnotItemsList);
  320. CurrentSelectedAnnot = annot;
  321. if (Settings.Default.AppProperties.InitialVIew.AutoExpandProperty)
  322. ShowPropertyPanel(true);
  323. }
  324. else
  325. {
  326. switch (annot.EventType)
  327. {
  328. case AnnotArgsType.AnnotSticky:
  329. customStickyPopup.GetCurrentAnnot = e.AnnotItemsList[0] as StickyAnnotArgs;
  330. customStickyPopup.GetPDFViewer = PDFViewer;
  331. break;
  332. case AnnotArgsType.AnnotLink:
  333. //viewContentViewModel.IsCreateLink = false;
  334. GetLink(e.AnnotItemsList, e);
  335. PDFViewer.SetToolParam(annot);
  336. break;
  337. }
  338. #region //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  339. //注释代码原因:设计已经重新调整逻辑:所有注释创建后,编辑属性,所有属性会作用于下次创建的注释中。
  340. //if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  341. //annot.EventType != AnnotArgsType.AnnotUnderline &&
  342. //annot.EventType != AnnotArgsType.AnnotHighlight &&
  343. //annot.EventType != AnnotArgsType.AnnotSquiggly &&
  344. //annot.EventType != AnnotArgsType.AnnotLink &&
  345. //annot.EventType != AnnotArgsType.AnnotFreehand &&
  346. //annot.EventType != AnnotArgsType.AnnotSticky &&
  347. //)
  348. //{
  349. // if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  350. // {
  351. // var strLineAnnotTag = "";
  352. // if (e.AnnotItemsList[0] is LineAnnotArgs)
  353. // {
  354. // var lineAnnot = e.AnnotItemsList[0] as LineAnnotArgs;
  355. // if (lineAnnot.HeadLineType == C_LINE_TYPE.LINETYPE_NONE && lineAnnot.TailLineType == C_LINE_TYPE.LINETYPE_NONE)
  356. // {
  357. // strLineAnnotTag = "Line";
  358. // }
  359. // else
  360. // {
  361. // strLineAnnotTag = "Arrow";
  362. // }
  363. // }
  364. // foreach (var item in ToolExpandDict)
  365. // {
  366. // if (item.Value == e.AnnotItemsList[0].EventType)
  367. // {
  368. // annot = null;//新建注释时,回到默认值
  369. // if (string.IsNullOrEmpty(strLineAnnotTag))
  370. // {
  371. // FindAnnotTypeKey(item.Key, ref annot);
  372. // break;
  373. // }
  374. // else
  375. // {
  376. // if (strLineAnnotTag == item.Key)
  377. // {
  378. // FindAnnotTypeKey(item.Key, ref annot);
  379. // break;
  380. // }
  381. // }
  382. // }
  383. // }
  384. // PDFViewer.SetToolParam(annot);
  385. // }
  386. //}
  387. //设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  388. //if (isRightMenuAddAnnot && annot.EventType!=AnnotArgsType.AnnotLink)
  389. //{
  390. // ShowPropertyPanel(false);
  391. //}
  392. //else
  393. //{
  394. // ShowPropertyPanel();
  395. //}
  396. #endregion //TODO: 修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  397. }
  398. }
  399. else
  400. {
  401. bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
  402. if (isDifferentAnnotTyle)
  403. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  404. else
  405. GetSelectedAnnots(e);
  406. }
  407. }
  408. //注释列表同步选中
  409. var list = e.GetPageAnnotsIndex();
  410. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  411. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
  412. {
  413. if (list.Keys.Count == 0)
  414. {
  415. return;
  416. }
  417. var pageindex = new List<int>(list.Keys);
  418. List<int> annotes = new List<int>();
  419. list.TryGetValue(pageindex[0], out annotes);
  420. int annoteindex = annotes[0];
  421. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  422. if (viewModel != null)
  423. {
  424. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  425. }
  426. }
  427. }
  428. else
  429. {
  430. if (BtnLinkIsChecked == false)
  431. {
  432. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  433. {
  434. if (PDFViewer.MouseMode == MouseModes.PanTool && propertyPanel.IsAddLink == false && propertyPanel.IsLocationLink == false)
  435. {
  436. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  437. }
  438. }
  439. }
  440. }
  441. }
  442. //在注释工具的状态下,右键菜单
  443. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  444. {
  445. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  446. return;
  447. switch (e.CommandType)
  448. {
  449. case CommandType.Context:
  450. if (e.AnnotEventArgsList.Count > 0)
  451. {
  452. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  453. {
  454. //绑定标记密文处右键菜单
  455. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  456. }
  457. else
  458. {
  459. if (e.AnnotEventArgsList.Count == 1)
  460. {
  461. var selectedAnnot = e.AnnotEventArgsList[0];
  462. PopMenuCheckedLineDash(selectedAnnot);
  463. PopMenuCheckedFontFamily(selectedAnnot);
  464. PopMenuCheckedTextAglin(selectedAnnot);
  465. switch (selectedAnnot.EventType)
  466. {
  467. case AnnotArgsType.AnnotHighlight:
  468. case AnnotArgsType.AnnotUnderline:
  469. case AnnotArgsType.AnnotStrikeout:
  470. case AnnotArgsType.AnnotSquiggly:
  471. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  472. {
  473. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  474. }
  475. else
  476. {
  477. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  478. }
  479. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  480. break;
  481. case AnnotArgsType.AnnotFreehand:
  482. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  483. break;
  484. case AnnotArgsType.AnnotFreeText:
  485. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  486. break;
  487. case AnnotArgsType.AnnotSticky:
  488. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  489. break;
  490. case AnnotArgsType.AnnotSquare:
  491. case AnnotArgsType.AnnotCircle:
  492. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  493. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  494. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  495. break;
  496. case AnnotArgsType.AnnotLine:
  497. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  498. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  499. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  500. break;
  501. case AnnotArgsType.AnnotLink:
  502. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  503. break;
  504. case AnnotArgsType.AnnotStamp:
  505. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  506. break;
  507. }
  508. }
  509. else
  510. {
  511. bool isHigh = true;//是否为高亮
  512. foreach (var item in e.AnnotEventArgsList)
  513. {
  514. if (AnnotTransfer.IsHightAnnot(item) == false)
  515. {
  516. isHigh = false;
  517. break;
  518. }
  519. }
  520. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  521. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  522. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  523. }
  524. }
  525. if (e.PopupMenu != null)
  526. {
  527. e.Handle = true;
  528. }
  529. }
  530. else
  531. {
  532. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  533. {
  534. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  535. if (e.PopupMenu != null)
  536. {
  537. e.Handle = true;
  538. }
  539. }
  540. else
  541. {
  542. e.PopupMenu = ViewerContextMenu(sender);
  543. if (e.PopupMenu != null)
  544. {
  545. e.Handle = true;
  546. }
  547. }
  548. }
  549. break;
  550. }
  551. }
  552. //右键菜单,选中字体样式按钮状态
  553. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  554. {
  555. if (annot != null)
  556. {
  557. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  558. {
  559. var freeText = annot as FreeTextAnnotArgs;
  560. FreeTextAnnotPopMenu.SetIsChecked(freeText.FontFamily.ToString(), true);
  561. }
  562. }
  563. }
  564. //右键菜单,选中文本内容对齐按钮状态
  565. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  566. {
  567. if (annot != null)
  568. {
  569. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  570. {
  571. var freeText = annot as FreeTextAnnotArgs;
  572. switch (freeText.Align)
  573. {
  574. case TextAlignment.Left:
  575. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  576. break;
  577. case TextAlignment.Center:
  578. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  579. break;
  580. case TextAlignment.Right:
  581. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  582. break;
  583. case TextAlignment.Justify:
  584. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  585. break;
  586. default:
  587. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  588. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  589. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  590. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  591. break;
  592. }
  593. }
  594. }
  595. }
  596. //右键菜单,选中虚实线按钮状态
  597. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  598. {
  599. if (annot != null)
  600. {
  601. bool isSolidLineDash = true;
  602. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  603. {
  604. var freeHand = annot as FreehandAnnotArgs;
  605. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  606. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  607. }
  608. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  609. {
  610. var square = annot as SquareAnnotArgs;
  611. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  612. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  613. }
  614. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  615. {
  616. var circle = annot as CircleAnnotArgs;
  617. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  618. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  619. }
  620. else if (annot.EventType == AnnotArgsType.AnnotLine)
  621. {
  622. var line = annot as LineAnnotArgs;
  623. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  624. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  625. }
  626. }
  627. }
  628. /// <summary>
  629. /// 内容选择工具
  630. /// </summary>
  631. /// <param name="sender"></param>
  632. /// <param name="e"></param>
  633. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  634. {
  635. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  636. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  637. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  638. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  639. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  640. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  641. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  642. {
  643. e.PopupMenu = popMenu;
  644. e.Handle = true;
  645. if (popMenu != null && popMenu.Items.Count == 5)
  646. {
  647. //复制
  648. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  649. menuItem.CommandTarget = PDFViewer;
  650. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  651. //导出
  652. menuItem = popMenu.Items[1] as MenuItem;
  653. menuItem.CommandTarget = PDFViewer;
  654. if (menuItem.Items.Count == 3)
  655. {
  656. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  657. menuItem1.CommandTarget = PDFViewer;
  658. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  659. menuItem1 = menuItem.Items[1] as MenuItem;
  660. menuItem1.CommandTarget = PDFViewer;
  661. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  662. menuItem1 = menuItem.Items[2] as MenuItem;
  663. menuItem1.CommandTarget = PDFViewer;
  664. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  665. }
  666. //裁剪
  667. menuItem = popMenu.Items[2] as MenuItem;
  668. menuItem.CommandTarget = PDFViewer;
  669. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  670. //缩放至所选区域
  671. menuItem = popMenu.Items[3] as MenuItem;
  672. menuItem.CommandTarget = PDFViewer;
  673. menuItem.Visibility = Visibility.Collapsed;
  674. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  675. //打印
  676. menuItem = popMenu.Items[4] as MenuItem;
  677. menuItem.CommandTarget = PDFViewer;
  678. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  679. }
  680. }
  681. }
  682. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  683. {
  684. switch (e.Key)
  685. {
  686. case "CloseSnap":
  687. {
  688. #region to do
  689. //var item = PDFViewerTab.SelectedItem as TabItem;
  690. //if (item == null)
  691. //{
  692. // ClearSelectedToolPanel();
  693. // return;
  694. //}
  695. //Grid grid = item.Content as Grid;
  696. //if (grid == null || grid.Children.Count == 0)
  697. //{
  698. // ClearSelectedToolPanel();
  699. // return;
  700. //}
  701. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  702. //if (pdfViewer == null)
  703. //{
  704. // ClearSelectedToolPanel();
  705. // return;
  706. //}
  707. #endregion to do
  708. switch (PDFViewer.MouseMode)
  709. {
  710. case MouseModes.SelectTextTool:
  711. break;
  712. default:
  713. BtnSelecttoolIsChecked = false;
  714. BtnHandIsChecked = true;
  715. PDFViewer.EnableZoom(true);
  716. PDFViewer.EnableScroll(true);
  717. break;
  718. }
  719. }
  720. break;
  721. default:
  722. break;
  723. }
  724. }
  725. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  726. {
  727. if (e != null && e.Count > 0)
  728. {
  729. MultipleSelectionAnnot(e);
  730. for (int i = 0; i < e.Count; i++)
  731. {
  732. AnnotEditEvent editEvent = e[i];
  733. switch (editEvent.EditAction)
  734. {
  735. case ActionType.Add:
  736. //BOTA
  737. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  738. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  739. {
  740. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  741. if (viewModel != null)
  742. {
  743. int pageindex = editEvent.PageIndex;
  744. int annotindex = editEvent.AnnotIndex;
  745. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  746. }
  747. }
  748. //添加书签注释,用于未保存前跟图章手绘注释的区分
  749. if (StrAnnotToolChecked == "Signature")
  750. {
  751. AddAnnotSignature(editEvent.EditAnnotArgs);
  752. }
  753. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  754. {
  755. (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  756. }
  757. break;
  758. case ActionType.Del:
  759. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  760. if (isTabItemAnnotation)
  761. {
  762. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  763. if (viewModel != null)
  764. {
  765. int pageindex = editEvent.PageIndex;
  766. int annotindex = editEvent.AnnotIndex;
  767. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  768. }
  769. }
  770. break;
  771. case ActionType.Modify:
  772. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  773. if (bOTAContent.TabItemAnnotation.IsSelected)
  774. {
  775. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  776. if (viewModel != null)
  777. {
  778. int pageindex = editEvent.PageIndex;
  779. int annotindex = editEvent.AnnotIndex;
  780. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  781. }
  782. }
  783. break;
  784. case ActionType.TextEdit:
  785. break;
  786. default:
  787. break;
  788. }
  789. }
  790. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  791. if (IsNoSelectMenu)
  792. {
  793. IsNoSelectMenu = false;
  794. PDFViewer.SetMouseMode(MouseModes.PanTool);
  795. }
  796. }
  797. }
  798. //复制多个注释,粘贴后,默认注释未选中状态
  799. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  800. {
  801. bool isAdd = false;
  802. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  803. foreach (var item in e)
  804. {
  805. if (item.EditAction == ActionType.Add || item.EditAction == ActionType.Modify)
  806. {
  807. var annot = item.EditAnnotArgs;
  808. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  809. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText)
  810. {
  811. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  812. {
  813. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  814. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  815. }
  816. else
  817. {
  818. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  819. }
  820. isAdd = true;
  821. }
  822. }
  823. }
  824. if (isAdd)
  825. {
  826. PDFViewer.ClearSelectAnnots();
  827. PDFViewer.SelectAnnotation(selectAnnotDicts);
  828. }
  829. }
  830. //阅读页悬浮相应
  831. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  832. {
  833. if (e != null && e.DrawContext != null)
  834. {
  835. Rect hoverRect = new Rect(
  836. e.PaintRect.Left - 2,
  837. e.PaintRect.Top - 2,
  838. e.PaintRect.Width + 4,
  839. e.PaintRect.Height + 4);
  840. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  841. hoverPen.DashStyle = DashStyles.Dash;
  842. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  843. //便签,显示ToolTip内容
  844. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  845. {
  846. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  847. return;
  848. }
  849. }
  850. CloseAnnotToolTip();
  851. }
  852. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  853. {
  854. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  855. {
  856. //鼠标移到注释之外,关闭ToolTip浮窗
  857. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  858. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  859. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  860. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  861. {
  862. CloseAnnotToolTip();
  863. }
  864. }
  865. }
  866. private Rect oldRect = new Rect(0, 0, 0, 0);
  867. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  868. {
  869. //便签,显示ToolTip内容
  870. if (PDFViewer.ToolTip == null)
  871. {
  872. if (string.IsNullOrEmpty(content) == false)
  873. {
  874. ToolTip TipChild = new ToolTip();
  875. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  876. TipChild.MaxWidth = 246;
  877. TipChild.Content = content;
  878. TipChild.Visibility = Visibility.Visible;
  879. TipChild.IsOpen = true;
  880. TipChild.Placement = PlacementMode.Right;
  881. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  882. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  883. TipChild.Placement = PlacementMode.MousePoint;
  884. PDFViewer.ToolTip = TipChild;
  885. oldRect = hoverRect;
  886. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  887. PDFViewer.MouseMove += PDFViewer_MouseMove;
  888. }
  889. }
  890. }
  891. //关闭ToolTip
  892. private void CloseAnnotToolTip()
  893. {
  894. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  895. {
  896. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  897. oldTips.IsOpen = false;
  898. oldTips.Visibility = Visibility.Collapsed;
  899. PDFViewer.ToolTip = null;
  900. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  901. oldRect = new Rect(0, 0, 0, 0);
  902. }
  903. }
  904. #endregion PDFViewer事件
  905. #region BindingEvent事件
  906. //同一属性面板,不同的注释类型
  907. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  908. {
  909. if (e != null)
  910. {
  911. AnnotHandlerEventArgs annotArgs = null;
  912. propertyPanel.SaveLastAnnot();
  913. foreach (AnnotArgsType argsType in e.Keys)
  914. {
  915. if (propertyPanel.annot.EventType != argsType)
  916. {
  917. PDFViewer.SetMouseMode(MouseModes.PanTool);
  918. }
  919. switch (argsType)
  920. {
  921. case AnnotArgsType.AnnotSquare:
  922. annotArgs = GetRect();
  923. break;
  924. case AnnotArgsType.AnnotCircle:
  925. annotArgs = GetCircle();
  926. break;
  927. case AnnotArgsType.AnnotLine:
  928. var LineTag = e[argsType] as string;
  929. annotArgs = GetArrowLine(LineTag);
  930. break;
  931. }
  932. ShowPropertyPanel();
  933. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  934. {
  935. PDFViewer.SetMouseMode(MouseModes.PanTool);
  936. return;
  937. }
  938. if (annotArgs != null)
  939. {
  940. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  941. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  942. PDFViewer.SetToolParam(annotArgs);
  943. }
  944. }
  945. }
  946. }
  947. //来自属性面板的事件,更改颜色等属性而触发
  948. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  949. {
  950. if (e != null)
  951. {
  952. foreach (AnnotArgsType argsType in e.Keys)
  953. {
  954. switch (argsType)
  955. {
  956. case AnnotArgsType.AnnotHighlight:
  957. if (e[argsType] is Color)
  958. {
  959. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  960. }
  961. if (e[argsType] is double)
  962. {
  963. HighLightOpacity = (double)e[argsType];
  964. }
  965. //创建注释后,修改注释属性,可用于下次创建的注释
  966. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  967. {
  968. PDFViewer.SetToolParam(propertyPanel.annot);
  969. }
  970. break;
  971. case AnnotArgsType.AnnotUnderline:
  972. if (e[argsType] is Color)
  973. {
  974. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  975. }
  976. if (e[argsType] is double)
  977. {
  978. underLineOpacity = (double)e[argsType];
  979. }
  980. //创建注释后,修改注释属性,可用于下次创建的注释
  981. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  982. {
  983. PDFViewer.SetToolParam(propertyPanel.annot);
  984. }
  985. break;
  986. case AnnotArgsType.AnnotSquiggly:
  987. if (e[argsType] is Color)
  988. {
  989. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  990. }
  991. if (e[argsType] is double)
  992. {
  993. SquigglyOpacity = (double)e[argsType];
  994. }
  995. //创建注释后,修改注释属性,可用于下次创建的注释
  996. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  997. {
  998. PDFViewer.SetToolParam(propertyPanel.annot);
  999. }
  1000. break;
  1001. case AnnotArgsType.AnnotStrikeout:
  1002. if (e[argsType] is Color)
  1003. {
  1004. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1005. }
  1006. if (e[argsType] is double)
  1007. {
  1008. StrikeoutOpacity = (double)e[argsType];
  1009. }
  1010. //创建注释后,修改注释属性,可用于下次创建的注释
  1011. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1012. {
  1013. PDFViewer.SetToolParam(propertyPanel.annot);
  1014. }
  1015. break;
  1016. case AnnotArgsType.AnnotFreehand:
  1017. if (e[argsType] is FreehandAnnotArgs)
  1018. {
  1019. var annot = e[argsType] as FreehandAnnotArgs;
  1020. if (annot != null)
  1021. {
  1022. if (propertyPanel != null)
  1023. {
  1024. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1025. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1026. propertyPanel.AnnotEvent = AnnotEvent;
  1027. var AnnotEvents = new List<AnnotAttribEvent>();
  1028. AnnotEvents.Add(AnnotEvent);
  1029. propertyPanel.AnnotEvents = AnnotEvents;
  1030. propertyPanel.annot = annot;
  1031. //手绘注释工具按钮的属性
  1032. // FreehandPath.Opacity = annot.Transparency;
  1033. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1034. }
  1035. PDFViewer.SetToolParam(annot);
  1036. }
  1037. }
  1038. break;
  1039. case AnnotArgsType.AnnotErase:
  1040. if (e[argsType] is ToggleButton)
  1041. {
  1042. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1043. if (clickBtn.IsChecked == true)
  1044. {
  1045. if (clickBtn.Tag.ToString() == "PenBtn")
  1046. {
  1047. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1048. btn.Tag = "Freehand"; btn.IsChecked = true;
  1049. BtnMyTools_Click(btn);
  1050. break;
  1051. }
  1052. EraseArgs eraseArgs = new EraseArgs();
  1053. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1054. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1055. eraseArgs.Thickness = 10;
  1056. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1057. if (annotProperty != null)
  1058. {
  1059. eraseArgs.Thickness = annotProperty.Thickness;
  1060. }
  1061. PDFViewer.ClearSelectAnnots(false);
  1062. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1063. PDFViewer.SetToolParam(eraseArgs);
  1064. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1065. if (eraseArgs != null)
  1066. eraseArgsList.Add(eraseArgs);
  1067. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1068. }
  1069. }
  1070. break;
  1071. case AnnotArgsType.AnnotSquare:
  1072. case AnnotArgsType.AnnotCircle:
  1073. case AnnotArgsType.AnnotLine:
  1074. case AnnotArgsType.AnnotFreeText:
  1075. //创建注释后,修改注释属性,可用于下次创建的注释
  1076. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1077. {
  1078. PDFViewer.SetToolParam(propertyPanel.annot);
  1079. }
  1080. break;
  1081. }
  1082. }
  1083. }
  1084. }
  1085. #endregion BindingEvent事件
  1086. }
  1087. }