AnnotToolContentViewModel.Command.cs 91 KB

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