AnnotToolContentViewModel.Command.cs 58 KB

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