AnnotToolContentViewModel.Command.cs 72 KB

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