AnnotToolContentViewModel.Command.cs 67 KB

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