AnnotToolContentViewModel.Command.cs 72 KB

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