AnnotToolContentViewModel.Command.cs 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253
  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_Master.CustomControl;
  8. using PDF_Master.EventAggregators;
  9. using PDF_Master.Helper;
  10. using PDF_Master.Properties;
  11. using PDF_Master.ViewModels.BOTA;
  12. using PDF_Master.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_Master.Model.AnnotPanel;
  27. using System.Windows.Input;
  28. using PDF_Master.ViewModels.Tools.AnnotManager;
  29. using ComPDFKit.Import;
  30. using System.Windows.Markup;
  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. }
  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. if ((UIElement)sender != null)
  448. {
  449. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  450. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  451. }
  452. switch (e.CommandType)
  453. {
  454. case CommandType.Context:
  455. if (e.AnnotEventArgsList.Count > 0)
  456. {
  457. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  458. {
  459. //绑定标记密文处右键菜单
  460. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  461. }
  462. else
  463. {
  464. if (e.AnnotEventArgsList.Count == 1)
  465. {
  466. var selectedAnnot = e.AnnotEventArgsList[0];
  467. PopMenuCheckedLineDash(selectedAnnot);
  468. PopMenuCheckedFontFamily(selectedAnnot);
  469. PopMenuCheckedTextAglin(selectedAnnot);
  470. switch (selectedAnnot.EventType)
  471. {
  472. case AnnotArgsType.AnnotHighlight:
  473. case AnnotArgsType.AnnotUnderline:
  474. case AnnotArgsType.AnnotStrikeout:
  475. case AnnotArgsType.AnnotSquiggly:
  476. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  477. {
  478. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  479. }
  480. else
  481. {
  482. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  483. }
  484. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  485. break;
  486. case AnnotArgsType.AnnotFreehand:
  487. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  488. break;
  489. case AnnotArgsType.AnnotFreeText:
  490. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  491. break;
  492. case AnnotArgsType.AnnotSticky:
  493. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  494. break;
  495. case AnnotArgsType.AnnotSquare:
  496. case AnnotArgsType.AnnotCircle:
  497. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  498. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  499. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  500. break;
  501. case AnnotArgsType.AnnotLine:
  502. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  503. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  504. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  505. break;
  506. case AnnotArgsType.AnnotLink:
  507. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  508. break;
  509. case AnnotArgsType.AnnotStamp:
  510. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  511. break;
  512. }
  513. }
  514. else
  515. {
  516. bool isHigh = true;//是否为高亮
  517. foreach (var item in e.AnnotEventArgsList)
  518. {
  519. if (AnnotTransfer.IsHightAnnot(item) == false)
  520. {
  521. isHigh = false;
  522. break;
  523. }
  524. }
  525. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  526. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  527. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  528. }
  529. }
  530. if (e.PopupMenu != null)
  531. {
  532. e.Handle = true;
  533. }
  534. }
  535. else
  536. {
  537. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  538. {
  539. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  540. if (e.PopupMenu != null)
  541. {
  542. e.Handle = true;
  543. }
  544. }
  545. else
  546. {
  547. e.PopupMenu = ViewerContextMenu(sender);
  548. if (e.PopupMenu != null)
  549. {
  550. e.Handle = true;
  551. }
  552. }
  553. }
  554. break;
  555. }
  556. }
  557. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  558. {
  559. if (e.Command == ApplicationCommands.Copy)
  560. {
  561. VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsPrinting, dialogs);
  562. if (result.IsDiscryptied)
  563. {
  564. if (result.Password != null)
  565. {
  566. string filePath = PDFViewer.Document.FilePath;
  567. var unlockresult = PDFViewer.Document.UnlockWithPassword(result.Password);
  568. }
  569. }
  570. else
  571. {
  572. e.Handled = true;
  573. }
  574. }
  575. }
  576. //右键菜单,选中字体样式按钮状态
  577. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  578. {
  579. if (annot != null)
  580. {
  581. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  582. {
  583. var freeText = annot as FreeTextAnnotArgs;
  584. FreeTextAnnotPopMenu.SetIsChecked(freeText.FontFamily.ToString(), true);
  585. }
  586. }
  587. }
  588. //右键菜单,选中文本内容对齐按钮状态
  589. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  590. {
  591. if (annot != null)
  592. {
  593. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  594. {
  595. var freeText = annot as FreeTextAnnotArgs;
  596. switch (freeText.Align)
  597. {
  598. case TextAlignment.Left:
  599. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  600. break;
  601. case TextAlignment.Center:
  602. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  603. break;
  604. case TextAlignment.Right:
  605. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  606. break;
  607. case TextAlignment.Justify:
  608. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  609. break;
  610. default:
  611. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  612. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  613. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  614. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  615. break;
  616. }
  617. }
  618. }
  619. }
  620. //右键菜单,选中虚实线按钮状态
  621. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  622. {
  623. if (annot != null)
  624. {
  625. bool isSolidLineDash = true;
  626. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  627. {
  628. var freeHand = annot as FreehandAnnotArgs;
  629. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  630. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  631. }
  632. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  633. {
  634. var square = annot as SquareAnnotArgs;
  635. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  636. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  637. }
  638. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  639. {
  640. var circle = annot as CircleAnnotArgs;
  641. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  642. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  643. }
  644. else if (annot.EventType == AnnotArgsType.AnnotLine)
  645. {
  646. var line = annot as LineAnnotArgs;
  647. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  648. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  649. }
  650. }
  651. }
  652. /// <summary>
  653. /// 内容选择工具
  654. /// </summary>
  655. /// <param name="sender"></param>
  656. /// <param name="e"></param>
  657. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  658. {
  659. SnapshotEditToolArgs snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  660. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  661. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  662. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  663. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  664. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  665. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  666. {
  667. e.PopupMenu = popMenu;
  668. e.Handle = true;
  669. if (popMenu != null && popMenu.Items.Count == 5)
  670. {
  671. //复制
  672. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  673. menuItem.CommandTarget = PDFViewer;
  674. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  675. //导出
  676. menuItem = popMenu.Items[1] as MenuItem;
  677. menuItem.CommandTarget = PDFViewer;
  678. if (menuItem.Items.Count == 3)
  679. {
  680. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  681. menuItem1.CommandTarget = PDFViewer;
  682. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  683. menuItem1 = menuItem.Items[1] as MenuItem;
  684. menuItem1.CommandTarget = PDFViewer;
  685. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  686. menuItem1 = menuItem.Items[2] as MenuItem;
  687. menuItem1.CommandTarget = PDFViewer;
  688. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  689. }
  690. //裁剪
  691. menuItem = popMenu.Items[2] as MenuItem;
  692. menuItem.CommandTarget = PDFViewer;
  693. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  694. //缩放至所选区域
  695. menuItem = popMenu.Items[3] as MenuItem;
  696. menuItem.CommandTarget = PDFViewer;
  697. menuItem.Visibility = Visibility.Collapsed;
  698. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  699. //打印
  700. menuItem = popMenu.Items[4] as MenuItem;
  701. menuItem.CommandTarget = PDFViewer;
  702. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  703. }
  704. }
  705. }
  706. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  707. {
  708. switch (e.Key)
  709. {
  710. case "CloseSnap":
  711. {
  712. #region to do
  713. //var item = PDFViewerTab.SelectedItem as TabItem;
  714. //if (item == null)
  715. //{
  716. // ClearSelectedToolPanel();
  717. // return;
  718. //}
  719. //Grid grid = item.Content as Grid;
  720. //if (grid == null || grid.Children.Count == 0)
  721. //{
  722. // ClearSelectedToolPanel();
  723. // return;
  724. //}
  725. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  726. //if (pdfViewer == null)
  727. //{
  728. // ClearSelectedToolPanel();
  729. // return;
  730. //}
  731. #endregion to do
  732. switch (PDFViewer.MouseMode)
  733. {
  734. case MouseModes.SelectTextTool:
  735. break;
  736. default:
  737. BtnSelecttoolIsChecked = false;
  738. BtnHandIsChecked = true;
  739. PDFViewer.EnableZoom(true);
  740. PDFViewer.EnableScroll(true);
  741. break;
  742. }
  743. }
  744. break;
  745. default:
  746. break;
  747. }
  748. }
  749. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  750. {
  751. if (e != null && e.Count > 0)
  752. {
  753. MultipleSelectionAnnot(e);
  754. for (int i = 0; i < e.Count; i++)
  755. {
  756. AnnotEditEvent editEvent = e[i];
  757. switch (editEvent.EditAction)
  758. {
  759. case ActionType.Add:
  760. //BOTA
  761. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  762. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  763. {
  764. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  765. if (viewModel != null)
  766. {
  767. int pageindex = editEvent.PageIndex;
  768. int annotindex = editEvent.AnnotIndex;
  769. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  770. }
  771. }
  772. //添加书签注释,用于未保存前跟图章手绘注释的区分
  773. if (StrAnnotToolChecked == "Signature")
  774. {
  775. AddAnnotSignature(editEvent.EditAnnotArgs);
  776. }
  777. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  778. {
  779. (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  780. }
  781. break;
  782. case ActionType.Del:
  783. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  784. if (isTabItemAnnotation)
  785. {
  786. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  787. if (viewModel != null)
  788. {
  789. int pageindex = editEvent.PageIndex;
  790. int annotindex = editEvent.AnnotIndex;
  791. viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  792. }
  793. }
  794. break;
  795. case ActionType.Modify:
  796. isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  797. if (bOTAContent.TabItemAnnotation.IsSelected)
  798. {
  799. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  800. if (viewModel != null)
  801. {
  802. int pageindex = editEvent.PageIndex;
  803. int annotindex = editEvent.AnnotIndex;
  804. viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  805. }
  806. }
  807. break;
  808. case ActionType.TextEdit:
  809. break;
  810. default:
  811. break;
  812. }
  813. }
  814. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  815. if (IsNoSelectMenu)
  816. {
  817. IsNoSelectMenu = false;
  818. PDFViewer.SetMouseMode(MouseModes.PanTool);
  819. }
  820. }
  821. }
  822. //复制多个注释,粘贴后,默认注释未选中状态
  823. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  824. {
  825. bool isAdd = false;
  826. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  827. foreach (var item in e)
  828. {
  829. if (item.EditAction == ActionType.Add || item.EditAction == ActionType.Modify)
  830. {
  831. var annot = item.EditAnnotArgs;
  832. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  833. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText)
  834. {
  835. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  836. {
  837. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  838. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  839. }
  840. else
  841. {
  842. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  843. }
  844. isAdd = true;
  845. }
  846. }
  847. }
  848. if (isAdd)
  849. {
  850. PDFViewer.ClearSelectAnnots();
  851. PDFViewer.SelectAnnotation(selectAnnotDicts);
  852. }
  853. }
  854. //阅读页悬浮相应
  855. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  856. {
  857. if (e != null && e.DrawContext != null)
  858. {
  859. Rect hoverRect = new Rect(
  860. e.PaintRect.Left - 2,
  861. e.PaintRect.Top - 2,
  862. e.PaintRect.Width + 4,
  863. e.PaintRect.Height + 4);
  864. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  865. hoverPen.DashStyle = DashStyles.Dash;
  866. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  867. //便签,显示ToolTip内容
  868. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  869. {
  870. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  871. return;
  872. }
  873. }
  874. CloseAnnotToolTip();
  875. }
  876. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  877. {
  878. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  879. {
  880. //鼠标移到注释之外,关闭ToolTip浮窗
  881. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  882. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  883. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  884. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  885. {
  886. CloseAnnotToolTip();
  887. }
  888. }
  889. }
  890. private Rect oldRect = new Rect(0, 0, 0, 0);
  891. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  892. {
  893. //便签,显示ToolTip内容
  894. if (PDFViewer.ToolTip == null)
  895. {
  896. if (string.IsNullOrEmpty(content) == false)
  897. {
  898. ToolTip TipChild = new ToolTip();
  899. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  900. TipChild.MaxWidth = 246;
  901. TipChild.Content = content;
  902. TipChild.Visibility = Visibility.Visible;
  903. TipChild.IsOpen = true;
  904. TipChild.Placement = PlacementMode.Right;
  905. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  906. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  907. TipChild.Placement = PlacementMode.MousePoint;
  908. PDFViewer.ToolTip = TipChild;
  909. oldRect = hoverRect;
  910. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  911. PDFViewer.MouseMove += PDFViewer_MouseMove;
  912. }
  913. }
  914. }
  915. //关闭ToolTip
  916. private void CloseAnnotToolTip()
  917. {
  918. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  919. {
  920. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  921. oldTips.IsOpen = false;
  922. oldTips.Visibility = Visibility.Collapsed;
  923. PDFViewer.ToolTip = null;
  924. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  925. oldRect = new Rect(0, 0, 0, 0);
  926. }
  927. }
  928. #endregion PDFViewer事件
  929. #region BindingEvent事件
  930. //同一属性面板,不同的注释类型
  931. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  932. {
  933. if (e != null)
  934. {
  935. AnnotHandlerEventArgs annotArgs = null;
  936. propertyPanel.SaveLastAnnot();
  937. foreach (AnnotArgsType argsType in e.Keys)
  938. {
  939. if (propertyPanel.annot.EventType != argsType)
  940. {
  941. PDFViewer.SetMouseMode(MouseModes.PanTool);
  942. }
  943. switch (argsType)
  944. {
  945. case AnnotArgsType.AnnotSquare:
  946. annotArgs = GetRect();
  947. break;
  948. case AnnotArgsType.AnnotCircle:
  949. annotArgs = GetCircle();
  950. break;
  951. case AnnotArgsType.AnnotLine:
  952. var LineTag = e[argsType] as string;
  953. annotArgs = GetArrowLine(LineTag);
  954. break;
  955. }
  956. ShowPropertyPanel();
  957. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  958. {
  959. PDFViewer.SetMouseMode(MouseModes.PanTool);
  960. return;
  961. }
  962. if (annotArgs != null)
  963. {
  964. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  965. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  966. PDFViewer.SetToolParam(annotArgs);
  967. }
  968. }
  969. }
  970. }
  971. //来自属性面板的事件,更改颜色等属性而触发
  972. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  973. {
  974. if (e != null)
  975. {
  976. foreach (AnnotArgsType argsType in e.Keys)
  977. {
  978. switch (argsType)
  979. {
  980. case AnnotArgsType.AnnotHighlight:
  981. if (e[argsType] is Color)
  982. {
  983. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  984. }
  985. if (e[argsType] is double)
  986. {
  987. HighLightOpacity = (double)e[argsType];
  988. }
  989. //创建注释后,修改注释属性,可用于下次创建的注释
  990. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  991. {
  992. PDFViewer.SetToolParam(propertyPanel.annot);
  993. }
  994. break;
  995. case AnnotArgsType.AnnotUnderline:
  996. if (e[argsType] is Color)
  997. {
  998. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  999. }
  1000. if (e[argsType] is double)
  1001. {
  1002. underLineOpacity = (double)e[argsType];
  1003. }
  1004. //创建注释后,修改注释属性,可用于下次创建的注释
  1005. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1006. {
  1007. PDFViewer.SetToolParam(propertyPanel.annot);
  1008. }
  1009. break;
  1010. case AnnotArgsType.AnnotSquiggly:
  1011. if (e[argsType] is Color)
  1012. {
  1013. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1014. }
  1015. if (e[argsType] is double)
  1016. {
  1017. SquigglyOpacity = (double)e[argsType];
  1018. }
  1019. //创建注释后,修改注释属性,可用于下次创建的注释
  1020. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1021. {
  1022. PDFViewer.SetToolParam(propertyPanel.annot);
  1023. }
  1024. break;
  1025. case AnnotArgsType.AnnotStrikeout:
  1026. if (e[argsType] is Color)
  1027. {
  1028. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1029. }
  1030. if (e[argsType] is double)
  1031. {
  1032. StrikeoutOpacity = (double)e[argsType];
  1033. }
  1034. //创建注释后,修改注释属性,可用于下次创建的注释
  1035. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1036. {
  1037. PDFViewer.SetToolParam(propertyPanel.annot);
  1038. }
  1039. break;
  1040. case AnnotArgsType.AnnotFreehand:
  1041. if (e[argsType] is FreehandAnnotArgs)
  1042. {
  1043. var annot = e[argsType] as FreehandAnnotArgs;
  1044. if (annot != null)
  1045. {
  1046. if (propertyPanel != null)
  1047. {
  1048. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1049. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1050. propertyPanel.AnnotEvent = AnnotEvent;
  1051. var AnnotEvents = new List<AnnotAttribEvent>();
  1052. AnnotEvents.Add(AnnotEvent);
  1053. propertyPanel.AnnotEvents = AnnotEvents;
  1054. propertyPanel.annot = annot;
  1055. //手绘注释工具按钮的属性
  1056. // FreehandPath.Opacity = annot.Transparency;
  1057. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1058. }
  1059. PDFViewer.SetToolParam(annot);
  1060. }
  1061. }
  1062. break;
  1063. case AnnotArgsType.AnnotErase:
  1064. if (e[argsType] is ToggleButton)
  1065. {
  1066. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1067. if (clickBtn.IsChecked == true)
  1068. {
  1069. if (clickBtn.Tag.ToString() == "PenBtn")
  1070. {
  1071. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1072. btn.Tag = "Freehand"; btn.IsChecked = true;
  1073. BtnMyTools_Click(btn);
  1074. break;
  1075. }
  1076. EraseArgs eraseArgs = new EraseArgs();
  1077. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1078. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1079. eraseArgs.Thickness = 10;
  1080. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1081. if (annotProperty != null)
  1082. {
  1083. eraseArgs.Thickness = annotProperty.Thickness;
  1084. }
  1085. PDFViewer.ClearSelectAnnots(false);
  1086. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1087. PDFViewer.SetToolParam(eraseArgs);
  1088. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1089. if (eraseArgs != null)
  1090. eraseArgsList.Add(eraseArgs);
  1091. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1092. }
  1093. }
  1094. break;
  1095. case AnnotArgsType.AnnotSquare:
  1096. case AnnotArgsType.AnnotCircle:
  1097. case AnnotArgsType.AnnotLine:
  1098. case AnnotArgsType.AnnotFreeText:
  1099. //创建注释后,修改注释属性,可用于下次创建的注释
  1100. if (propertyPanel != null && propertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1101. {
  1102. PDFViewer.SetToolParam(propertyPanel.annot);
  1103. }
  1104. break;
  1105. }
  1106. }
  1107. }
  1108. }
  1109. #endregion BindingEvent事件
  1110. }
  1111. }