AnnotToolContentViewModel.Command.cs 84 KB

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