AnnotToolContentViewModel.Command.cs 83 KB

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