AnnotToolContentViewModel.Command.cs 82 KB

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