AnnotToolContentViewModel.Command.cs 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977
  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. {
  672. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  673. }
  674. else
  675. {
  676. GetSelectedAnnots(e);
  677. }
  678. #endregion MVP 在对多选注释做处理
  679. if (viewContentViewModel.mainViewModel.IsBookMode)
  680. {
  681. ShowPropertyPanel(false);
  682. }
  683. else
  684. {
  685. ShowPropertyPanel(true);
  686. }
  687. }
  688. }
  689. }
  690. }
  691. private void CleanPropertyPanel()
  692. {
  693. PropertyPanel.annot = null;
  694. PropertyPanel.AnnotEvents = null;
  695. PropertyPanel.AnnotEvent = null;
  696. PropertyPanel.annotlists = null;
  697. }
  698. /// <summary>
  699. /// 注释列表同步选中
  700. /// </summary>
  701. /// <param name="e"></param>
  702. private void SelectedBotaAnnotationList(AnnotAttribEvent e)
  703. {
  704. var list = e.GetPageAnnotsIndex();
  705. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  706. //if (viewContentViewModel.OpenBOTA == false || isTabItemAnnotation == false || bOTAContent.TabItemAnnotation.IsSelected == false)
  707. //{
  708. // viewContentViewModel.OpenBOTA = true;
  709. // bOTAContent.TabItemAnnotation.IsSelected = true;
  710. //}
  711. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true /*&& bOTAContent.TabItemAnnotation.IsSelected == true*/ && list != null && list.Count > 0)
  712. {
  713. if (list.Keys.Count == 0)
  714. {
  715. return;
  716. }
  717. var pageindex = new List<int>(list.Keys);
  718. List<int> annotes = new List<int>();
  719. list.TryGetValue(pageindex[0], out annotes);
  720. int annoteindex = annotes[0];
  721. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  722. if (viewModel != null)
  723. {
  724. selectedAnnotation = viewModel.AnnotationListItems.FindFirst(a => a.PageIndex == pageindex[0] && a.AnnotIndex == annoteindex);
  725. viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
  726. }
  727. }
  728. }
  729. //在注释工具的状态下,右键菜单
  730. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  731. {
  732. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  733. return;
  734. if ((UIElement)sender != null)
  735. {
  736. //绑定命令执行前的拦截事件,对于未解密权限的文档进行复制限制
  737. CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  738. }
  739. switch (e.CommandType)
  740. {
  741. case CommandType.Context:
  742. if (e.AnnotEventArgsList.Count > 0)
  743. {
  744. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  745. {
  746. //绑定标记密文处右键菜单
  747. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  748. }
  749. else
  750. {
  751. if (e.AnnotEventArgsList.Count == 1)
  752. {
  753. var selectedAnnot = e.AnnotEventArgsList[0];
  754. PopMenuCheckedLineDash(selectedAnnot);
  755. PopMenuCheckedFontFamily(selectedAnnot);
  756. PopMenuCheckedTextAglin(selectedAnnot);
  757. switch (selectedAnnot.EventType)
  758. {
  759. case AnnotArgsType.AnnotHighlight:
  760. case AnnotArgsType.AnnotUnderline:
  761. case AnnotArgsType.AnnotStrikeout:
  762. case AnnotArgsType.AnnotSquiggly:
  763. if (selectedAnnot.EventType == AnnotArgsType.AnnotHighlight)
  764. {
  765. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Highlight);
  766. }
  767. else
  768. {
  769. colorContent.ItemSource = AnnotColorList.GetColorList(ColorSelectorType.Border);
  770. }
  771. e.PopupMenu = HightAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  772. break;
  773. case AnnotArgsType.AnnotFreehand:
  774. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  775. break;
  776. case AnnotArgsType.AnnotFreeText:
  777. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  778. break;
  779. case AnnotArgsType.AnnotSticky:
  780. e.PopupMenu = StrickNoteAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  781. break;
  782. case AnnotArgsType.AnnotSquare:
  783. case AnnotArgsType.AnnotCircle:
  784. ShapeAnnotPopMenu.SetVisual("ShapeDirect", false);
  785. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", true);
  786. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  787. break;
  788. case AnnotArgsType.AnnotLine:
  789. ShapeAnnotPopMenu.SetVisual("ShapeFillColor", false);
  790. ShapeAnnotPopMenu.SetVisual("ShapeDirect", true);
  791. e.PopupMenu = ShapeAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  792. break;
  793. case AnnotArgsType.AnnotLink:
  794. e.PopupMenu = LinkAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  795. break;
  796. case AnnotArgsType.AnnotStamp:
  797. e.PopupMenu = StampAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  798. break;
  799. }
  800. }
  801. else
  802. {
  803. bool isHigh = true;//是否为高亮
  804. foreach (var item in e.AnnotEventArgsList)
  805. {
  806. if (AnnotTransfer.IsHightAnnot(item) == false)
  807. {
  808. isHigh = false;
  809. break;
  810. }
  811. }
  812. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  813. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  814. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);
  815. }
  816. }
  817. if (e.PopupMenu != null)
  818. {
  819. e.Handle = true;
  820. }
  821. }
  822. else
  823. {
  824. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  825. {
  826. e.PopupMenu = SelectedTextOrImageContextMenu(sender, e);
  827. if (e.PopupMenu != null)
  828. {
  829. e.Handle = true;
  830. }
  831. }
  832. else
  833. {
  834. e.PopupMenu = ViewerContextMenu(sender);
  835. if (e.PopupMenu != null)
  836. {
  837. e.Handle = true;
  838. }
  839. }
  840. }
  841. break;
  842. }
  843. }
  844. private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  845. {
  846. if (e.Command == ApplicationCommands.Copy || e.Command == ApplicationCommands.Cut)
  847. {
  848. if (!viewContentViewModel.CheckPermissionBeforeOption())
  849. {
  850. //没有权限,或者权限解密不成功时,拦截该命令
  851. e.Handled = true;
  852. }
  853. }
  854. }
  855. /// <summary>
  856. /// 右键菜单,选中字体样式按钮状态
  857. /// </summary>
  858. /// <param name="annot"></param>
  859. private void PopMenuCheckedFontFamily(AnnotHandlerEventArgs annot)
  860. {
  861. if (annot != null)
  862. {
  863. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  864. {
  865. var freeText = annot as FreeTextAnnotArgs;
  866. string fontFamily = freeText.FontFamily.ToString();
  867. if (fontFamily == "Arial")
  868. {
  869. fontFamily = "Helvetica";
  870. }
  871. if (fontFamily == "Courier New")
  872. {
  873. fontFamily = "Courier";
  874. }
  875. if (fontFamily == "Times New Roman")
  876. {
  877. fontFamily = "Times";
  878. }
  879. FreeTextAnnotPopMenu.SetIsChecked(fontFamily, true);
  880. }
  881. }
  882. }
  883. /// <summary>
  884. /// 右键菜单,选中文本内容对齐按钮状态
  885. /// </summary>
  886. /// <param name="annot"></param>
  887. private void PopMenuCheckedTextAglin(AnnotHandlerEventArgs annot)
  888. {
  889. if (annot != null)
  890. {
  891. if (annot.EventType == AnnotArgsType.AnnotFreeText)
  892. {
  893. var freeText = annot as FreeTextAnnotArgs;
  894. switch (freeText.Align)
  895. {
  896. case TextAlignment.Left:
  897. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", true);
  898. break;
  899. case TextAlignment.Center:
  900. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", true);
  901. break;
  902. case TextAlignment.Right:
  903. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", true);
  904. break;
  905. case TextAlignment.Justify:
  906. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", true);
  907. break;
  908. default:
  909. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinLeft", false);
  910. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinCenter", false);
  911. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinRight", false);
  912. FreeTextAnnotPopMenu.SetIsChecked("FreeTextAglinJustify", false);
  913. break;
  914. }
  915. }
  916. }
  917. }
  918. //右键菜单,选中虚实线按钮状态
  919. private void PopMenuCheckedLineDash(AnnotHandlerEventArgs annot)
  920. {
  921. if (annot != null)
  922. {
  923. bool isSolidLineDash = true;
  924. if (annot.EventType == AnnotArgsType.AnnotFreehand)
  925. {
  926. var freeHand = annot as FreehandAnnotArgs;
  927. isSolidLineDash = AnnotTransfer.IsSolidStyle(freeHand.LineDash);
  928. FreeHandAnnotPopMenu.SetIsChecked(isSolidLineDash ? "FreeHandSolid" : "FreeHandDash", true);
  929. }
  930. else if (annot.EventType == AnnotArgsType.AnnotSquare)
  931. {
  932. var square = annot as SquareAnnotArgs;
  933. isSolidLineDash = AnnotTransfer.IsSolidStyle(square.LineDash);
  934. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  935. }
  936. else if (annot.EventType == AnnotArgsType.AnnotCircle)
  937. {
  938. var circle = annot as CircleAnnotArgs;
  939. isSolidLineDash = AnnotTransfer.IsSolidStyle(circle.LineDash);
  940. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  941. }
  942. else if (annot.EventType == AnnotArgsType.AnnotLine)
  943. {
  944. var line = annot as LineAnnotArgs;
  945. isSolidLineDash = AnnotTransfer.IsSolidStyle(line.LineDash);
  946. ShapeAnnotPopMenu.SetIsChecked(isSolidLineDash ? "ShapeSolid" : "ShapeDash", true);
  947. }
  948. }
  949. }
  950. /// <summary>
  951. /// 内容选择工具
  952. /// </summary>
  953. /// <param name="sender"></param>
  954. /// <param name="e"></param>
  955. private void PDFViewer_SnapshotCommandHandler(object sender, SnapshotCommandArgs e)
  956. {
  957. SnapshotEditToolArgs snapToolArgs = new SnapshotEditToolArgs();
  958. if (PDFViewer.ToolManager.CurrentAnnotArgs is SnapshotEditToolArgs)
  959. {
  960. snapToolArgs = (SnapshotEditToolArgs)PDFViewer.ToolManager.CurrentAnnotArgs;
  961. SnapshotEditMenuViewModel.SnapToolArgs = snapToolArgs;
  962. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  963. SnapshotEditMenuViewModel.areaCropPageUndoManager = new AreaCropPageUndoManager(PDFViewer);
  964. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent; ;
  965. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  966. var popMenu = App.Current.FindResource("SnapshotContextMenu") as ContextMenu;
  967. if (e.HitSnapshotTool && e.SnapshotRect.Width > 0 && e.SnapshotRect.Height > 0)
  968. {
  969. e.PopupMenu = popMenu;
  970. e.Handle = true;
  971. if (popMenu != null && popMenu.Items.Count == 5)
  972. {
  973. //复制
  974. MenuItem menuItem = popMenu.Items[0] as MenuItem;
  975. menuItem.CommandTarget = PDFViewer;
  976. menuItem.Command = SnapshotEditMenuViewModel.SnapCopyCommand;
  977. //导出
  978. menuItem = popMenu.Items[1] as MenuItem;
  979. menuItem.CommandTarget = PDFViewer;
  980. if (menuItem.Items.Count == 3)
  981. {
  982. MenuItem menuItem1 = menuItem.Items[0] as MenuItem;
  983. menuItem1.CommandTarget = PDFViewer;
  984. menuItem1.Command = SnapshotEditMenuViewModel.ExportPNGCommand;
  985. menuItem1 = menuItem.Items[1] as MenuItem;
  986. menuItem1.CommandTarget = PDFViewer;
  987. menuItem1.Command = SnapshotEditMenuViewModel.ExportJPGCommand;
  988. menuItem1 = menuItem.Items[2] as MenuItem;
  989. menuItem1.CommandTarget = PDFViewer;
  990. menuItem1.Command = SnapshotEditMenuViewModel.ExportPDFCommand;
  991. }
  992. //裁剪
  993. menuItem = popMenu.Items[2] as MenuItem;
  994. menuItem.CommandTarget = PDFViewer;
  995. menuItem.Command = SnapshotEditMenuViewModel.CroppingCommand;
  996. //缩放至所选区域
  997. menuItem = popMenu.Items[3] as MenuItem;
  998. menuItem.CommandTarget = PDFViewer;
  999. menuItem.Visibility = Visibility.Collapsed;
  1000. //menuItem.Command = snapshotEditMenuViewModel.CroppingCommand;
  1001. //打印
  1002. menuItem = popMenu.Items[4] as MenuItem;
  1003. menuItem.CommandTarget = PDFViewer;
  1004. menuItem.Command = SnapshotEditMenuViewModel.PrintCommand;
  1005. }
  1006. }
  1007. }
  1008. }
  1009. private void SnapshotEditMenuViewModel_SnapToolEvent(object sender, KeyValuePair<string, object> e)
  1010. {
  1011. switch (e.Key)
  1012. {
  1013. case "CloseSnap":
  1014. {
  1015. #region to do
  1016. //var item = PDFViewerTab.SelectedItem as TabItem;
  1017. //if (item == null)
  1018. //{
  1019. // ClearSelectedToolPanel();
  1020. // return;
  1021. //}
  1022. //Grid grid = item.Content as Grid;
  1023. //if (grid == null || grid.Children.Count == 0)
  1024. //{
  1025. // ClearSelectedToolPanel();
  1026. // return;
  1027. //}
  1028. //PDFViewerCtrl pdfViewer = grid.Children[0] as PDFViewerCtrl;
  1029. //if (pdfViewer == null)
  1030. //{
  1031. // ClearSelectedToolPanel();
  1032. // return;
  1033. //}
  1034. #endregion to do
  1035. switch (PDFViewer.MouseMode)
  1036. {
  1037. case MouseModes.SelectTextTool:
  1038. break;
  1039. default:
  1040. BtnSelecttoolIsChecked = false;
  1041. //BtnHandIsChecked = true;
  1042. PDFViewer.EnableZoom(true);
  1043. PDFViewer.EnableScroll(true);
  1044. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1045. HandToolIsCheckedEvent(false);
  1046. break;
  1047. }
  1048. }
  1049. break;
  1050. default:
  1051. break;
  1052. }
  1053. }
  1054. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1055. {
  1056. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1057. AnnotationContentViewModel viewModel = null;
  1058. AnnotationContent annotation = null;
  1059. //OpenBOTA关闭时也要进入
  1060. //if (viewContentViewModel.OpenBOTA == false)
  1061. //{
  1062. viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out annotation);
  1063. //}
  1064. bool isMultiple = false;
  1065. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  1066. Dictionary<int, List<int>> selectFreehandDicts = new Dictionary<int, List<int>>();
  1067. if (e != null && e.Count > 0)
  1068. {
  1069. for (int i = 0; i < e.Count; i++)
  1070. {
  1071. AnnotEditEvent editEvent = e[i];
  1072. bool isVisible = PDFViewer.CheckAnnotVisible(editEvent.PageIndex, editEvent.AnnotIndex);
  1073. var annot = editEvent.EditAnnotArgs;
  1074. switch (editEvent.EditAction)
  1075. {
  1076. case ActionType.Add:
  1077. #region 区分复制填写签名图形
  1078. if (IsPasteShape)
  1079. {
  1080. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreehand)
  1081. {
  1082. if (ShapeNames.Count != 0 && ShapeNames[i] != "Annot")
  1083. {
  1084. try
  1085. {
  1086. viewContentViewModel.FillAndSign.Add(new FillAndSignIsShape(editEvent.PageIndex, editEvent.AnnotIndex, ShapeNames[i]));
  1087. }
  1088. catch { }
  1089. }
  1090. }
  1091. }
  1092. #endregion 区分复制填写签名图形
  1093. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  1094. {
  1095. //填写与签名在此区域不选中,不添加selectAnnotDicts词典当中
  1096. }
  1097. else
  1098. {
  1099. if (PropertyPanel.IsMultiSelected)
  1100. {
  1101. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  1102. {
  1103. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  1104. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1105. }
  1106. else
  1107. {
  1108. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1109. }
  1110. isMultiple = true;
  1111. }
  1112. else
  1113. {
  1114. if (
  1115. annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  1116. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp
  1117. /*|| annot.EventType == AnnotArgsType.AnnotSticky ||annot.EventType == AnnotArgsType.AnnotFreeText */)
  1118. {
  1119. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  1120. {
  1121. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  1122. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1123. }
  1124. else
  1125. {
  1126. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1127. }
  1128. isMultiple = true;
  1129. }
  1130. //添加后不选中的注释,需要额外处理
  1131. if (annot.EventType == AnnotArgsType.AnnotFreehand || annot.EventType == AnnotArgsType.AnnotSticky || annot.EventType == AnnotArgsType.AnnotFreeText)
  1132. {
  1133. if (selectFreehandDicts.ContainsKey(editEvent.PageIndex) == false)
  1134. {
  1135. selectFreehandDicts.Add(editEvent.PageIndex, new List<int>());
  1136. selectFreehandDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1137. }
  1138. else
  1139. {
  1140. selectFreehandDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1141. }
  1142. isMultiple = true;
  1143. }
  1144. }
  1145. }
  1146. if (viewModel != null)
  1147. {
  1148. int pageindex = editEvent.PageIndex;
  1149. int annotindex = editEvent.AnnotIndex;
  1150. viewModel.UpdateAddedAnnot(pageindex, annotindex);
  1151. }
  1152. //添加书签注释,用于未保存前跟图章手绘注释的区分
  1153. if (StrAnnotToolChecked == "Signature")
  1154. {
  1155. AddAnnotSignature(editEvent.EditAnnotArgs);
  1156. }
  1157. //if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreeText)
  1158. //{
  1159. // (editEvent.EditAnnotArgs as FreeTextAnnotArgs).LineWidth = 0;
  1160. //}
  1161. break;
  1162. case ActionType.Modify:
  1163. //if (string.IsNullOrEmpty(StrAnnotToolChecked) == false)
  1164. //{
  1165. // List<AnnotHandlerEventArgs> selectedArgs = new List<AnnotHandlerEventArgs>() { annot };
  1166. // switch (annot.EventType)
  1167. // {
  1168. // case AnnotArgsType.AnnotFreeText://文本
  1169. // GetFreetext(selectedArgs);
  1170. // break;
  1171. // }
  1172. //}
  1173. if (viewModel != null)
  1174. {
  1175. int pageindex = editEvent.PageIndex;
  1176. int annotindex = editEvent.AnnotIndex;
  1177. viewModel.UpdateModifiedAnnot(pageindex, annotindex);
  1178. }
  1179. break;
  1180. case ActionType.Del:
  1181. //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1182. //if (viewContentViewModel.OpenBOTA == true && bOTAContent.TabItemAnnotation.IsSelected)
  1183. //{
  1184. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  1185. #region//填写与签名 删除缓存信息列表
  1186. //if (Shape != "None")
  1187. //{
  1188. for (int j = 0; j < viewContentViewModel.FillAndSign.Count; j++)
  1189. {
  1190. if (viewContentViewModel.FillAndSign[j].PageIndex == editEvent.PageIndex && viewContentViewModel.FillAndSign[j].AnnotIndex == editEvent.AnnotIndex)
  1191. {
  1192. viewContentViewModel.FillAndSign.Remove(viewContentViewModel.FillAndSign[j]);
  1193. }
  1194. }
  1195. for (int j = 0; j < viewContentViewModel.AnnotSignatures.Count; j++)
  1196. {
  1197. if (viewContentViewModel.AnnotSignatures[j].Item1 == editEvent.PageIndex && viewContentViewModel.AnnotSignatures[j].Item2 == editEvent.AnnotIndex)
  1198. {
  1199. viewContentViewModel.AnnotSignatures.Remove(viewContentViewModel.AnnotSignatures[j]);
  1200. }
  1201. }
  1202. //}
  1203. #endregion PDFViewer事件
  1204. if (viewModel != null)
  1205. {
  1206. int pageindex = editEvent.PageIndex;
  1207. int annotindex = editEvent.AnnotIndex;
  1208. viewModel.DeleteModifiedAnnot(pageindex, annotindex);
  1209. }
  1210. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  1211. {
  1212. if (viewContentViewModel.CurrentBar != "TabItemAnnotation")
  1213. {
  1214. //填写与签名在此区域不选中,不添加selectAnnotDicts词典当中
  1215. }
  1216. else
  1217. {
  1218. ExitAnnotationTool();
  1219. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1220. }
  1221. }
  1222. else
  1223. {
  1224. switch (StrAnnotToolChecked)
  1225. {
  1226. case "Link":
  1227. PropertyPanel.IsAddLink = true;
  1228. GetLink();
  1229. events.GetEvent<LinkAnnotTipCloseEvent>().Publish(new LinkAnnotTipCloseArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode });
  1230. break;
  1231. }
  1232. }
  1233. break;
  1234. case ActionType.TextEdit:
  1235. break;
  1236. default:
  1237. break;
  1238. }
  1239. }
  1240. IsPasteShape = false;
  1241. SetMultipleAnnot(isMultiple, selectAnnotDicts, selectFreehandDicts);
  1242. //MultipleSelectionAnnot(e);
  1243. //空白处 右键菜单 添加注释 为单次添加,不连续添加
  1244. if (IsNoSelectMenu && PropertyPanel.IsAddLink == false)
  1245. {
  1246. viewContentViewModel.ReadModeIsShowProperty = false;
  1247. IsNoSelectMenu = false;
  1248. ExitAnnotationTool();
  1249. }
  1250. if (viewContentViewModel.IsRightMenuSelectedTextAddLink == false)
  1251. {
  1252. viewContentViewModel.ReadModeIsShowProperty = false;
  1253. }
  1254. }
  1255. }
  1256. /// <summary>
  1257. /// 设置多选注释
  1258. /// </summary>
  1259. /// <param name="isMultiple"></param>
  1260. /// <param name="selectAnnotDicts">添加后选中的注释</param>
  1261. /// <param name="selectFreehandDicts">添加后不选中的注释,需要额外处理</param>
  1262. private void SetMultipleAnnot(bool isMultiple, Dictionary<int, List<int>> selectAnnotDicts, Dictionary<int, List<int>> selectFreehandDicts)
  1263. {
  1264. if (isMultiple)
  1265. {
  1266. Dictionary<int, List<int>> dict = new Dictionary<int, List<int>>();
  1267. //阅读页多选注释,只能在当前页多选,不可以跨页多选
  1268. if (selectAnnotDicts.Count >= 1)
  1269. {
  1270. PDFViewer.ClearSelectAnnots();
  1271. //if (StrAnnotToolChecked != "Signature")
  1272. //{
  1273. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1274. if (selectFreehandDicts.Count >= 1)
  1275. {
  1276. if (selectFreehandDicts.FirstOrDefault().Value.Count > 1)
  1277. {
  1278. //先把键都合并到dict中,值都是新创建的
  1279. foreach (var key in selectAnnotDicts.Keys)
  1280. {
  1281. if (!dict.ContainsKey(key))
  1282. {
  1283. dict.Add(key, new List<int>());
  1284. }
  1285. }
  1286. foreach (var key in selectFreehandDicts.Keys)
  1287. {
  1288. if (!dict.ContainsKey(key))
  1289. {
  1290. dict.Add(key, new List<int>());
  1291. }
  1292. }
  1293. //分别将值添加进去
  1294. foreach (var ele in selectAnnotDicts)
  1295. {
  1296. dict[ele.Key].AddRange(ele.Value);
  1297. }
  1298. foreach (var ele in selectFreehandDicts)
  1299. {
  1300. dict[ele.Key].AddRange(ele.Value);
  1301. }
  1302. //Dictionary<int, List<int>> items2 = selectAnnotDicts.Union(selectFreehandDicts).ToDictionary(k => k.Key, v => v.Value);
  1303. PDFViewer.ClearSelectAnnots();
  1304. PDFViewer.SelectAnnotation(dict);
  1305. }
  1306. //}
  1307. }
  1308. }
  1309. else
  1310. {
  1311. if (selectFreehandDicts.Count >= 1)
  1312. {
  1313. if (selectFreehandDicts.FirstOrDefault().Value.Count > 1)
  1314. {
  1315. PDFViewer.ClearSelectAnnots();
  1316. PDFViewer.SelectAnnotation(selectFreehandDicts);
  1317. }
  1318. }
  1319. }
  1320. }
  1321. #region 之前版本
  1322. //if (isMultiple && selectAnnotDicts.Count >= 1)
  1323. //{
  1324. // //PDFViewer.DisableClearSelectAnnot(false);
  1325. // PDFViewer.ClearSelectAnnots();
  1326. // if (StrAnnotToolChecked != "Signature")
  1327. // {
  1328. // //PDFViewer.DisableClearSelectAnnot(true);
  1329. // PDFViewer.SelectAnnotation(selectAnnotDicts);
  1330. // //禁止取消选中注释
  1331. // //PDFViewer.DisableClearSelectAnnot(false);
  1332. // }
  1333. //}
  1334. //if (isMultiple && selectFreehandDicts.Count >= 1)
  1335. //{
  1336. // PDFViewer.ClearSelectAnnots();
  1337. // if (selectFreehandDicts.FirstOrDefault().Value.Count >= 1)
  1338. // {
  1339. // PDFViewer.SelectAnnotation(selectFreehandDicts);
  1340. // }
  1341. //}
  1342. #endregion 之前版本
  1343. }
  1344. //复制多个注释,粘贴后,默认注释未选中状态
  1345. private void MultipleSelectionAnnot(List<AnnotEditEvent> e)
  1346. {
  1347. bool isAdd = false;
  1348. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  1349. foreach (var item in e)
  1350. {
  1351. if (item.EditAction == ActionType.Add || item.EditAction == ActionType.Modify)
  1352. {
  1353. var annot = item.EditAnnotArgs;
  1354. if (annot.EventType == AnnotArgsType.AnnotSquare || annot.EventType == AnnotArgsType.AnnotCircle ||
  1355. annot.EventType == AnnotArgsType.AnnotLine || annot.EventType == AnnotArgsType.AnnotStamp || annot.EventType == AnnotArgsType.AnnotFreeText || annot.EventType == AnnotArgsType.AnnotFreehand)
  1356. {
  1357. if (selectAnnotDicts.ContainsKey(item.PageIndex) == false)
  1358. {
  1359. selectAnnotDicts.Add(item.PageIndex, new List<int>());
  1360. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  1361. }
  1362. else
  1363. {
  1364. selectAnnotDicts[item.PageIndex].Add(item.AnnotIndex);
  1365. }
  1366. isAdd = true;
  1367. }
  1368. }
  1369. }
  1370. if (isAdd && selectAnnotDicts.Count >= 1)
  1371. {
  1372. PDFViewer.ClearSelectAnnots();
  1373. if (StrAnnotToolChecked != "Signature")
  1374. {
  1375. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1376. }
  1377. }
  1378. }
  1379. //阅读页悬浮相应
  1380. /// <summary>
  1381. /// 阅读页鼠标悬浮在注释上的虚线
  1382. /// </summary>
  1383. /// <param name="sender"></param>
  1384. /// <param name="e"></param>
  1385. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1386. {
  1387. if (e != null && e.DrawContext != null)
  1388. {
  1389. if (StrAnnotToolChecked != "Link")
  1390. {
  1391. if (e.Annot is CPDFLinkAnnotation linkAnnotation)
  1392. {
  1393. return;
  1394. }
  1395. }
  1396. if (StrAnnotToolChecked == "Freehand" || (IsNoSelectMenu && isRightMenuAddAnnot))
  1397. {
  1398. return;
  1399. }
  1400. Rect hoverRect = new Rect(
  1401. e.PaintRect.Left - 2,
  1402. e.PaintRect.Top - 2,
  1403. e.PaintRect.Width + 4,
  1404. e.PaintRect.Height + 4);
  1405. if (e.Annot is CPDFTextAnnotation sticky)
  1406. {
  1407. hoverRect = new Rect(
  1408. e.PaintRect.Left - 2,
  1409. e.PaintRect.Top + 2,
  1410. e.PaintRect.Width + 5,
  1411. e.PaintRect.Height + 2);
  1412. }
  1413. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1414. hoverPen.DashStyle = DashStyles.Dash;
  1415. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1416. //便签,显示ToolTip内容
  1417. if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  1418. {
  1419. PopAnnotToolTip(e.Annot.GetRect(), hoverRect, e.Annot.GetContent());
  1420. return;
  1421. }
  1422. }
  1423. CloseAnnotToolTip();
  1424. }
  1425. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1426. {
  1427. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1428. {
  1429. //鼠标移到注释之外,关闭ToolTip浮窗
  1430. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1431. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1432. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1433. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1434. {
  1435. CloseAnnotToolTip();
  1436. }
  1437. }
  1438. }
  1439. private Rect oldRect = new Rect(0, 0, 0, 0);
  1440. private void PopAnnotToolTip(CRect placementRect, Rect hoverRect, string content)
  1441. {
  1442. //便签,显示ToolTip内容
  1443. if (PDFViewer.ToolTip == null)
  1444. {
  1445. if (string.IsNullOrEmpty(content) == false)
  1446. {
  1447. ToolTip TipChild = new ToolTip();
  1448. TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  1449. TipChild.MaxWidth = 246;
  1450. TipChild.Content = content;
  1451. TipChild.Visibility = Visibility.Visible;
  1452. TipChild.IsOpen = true;
  1453. TipChild.Placement = PlacementMode.Right;
  1454. TipChild.PlacementRectangle = new Rect(placementRect.left, placementRect.top, placementRect.right, placementRect.bottom);
  1455. TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  1456. TipChild.Placement = PlacementMode.MousePoint;
  1457. PDFViewer.ToolTip = TipChild;
  1458. oldRect = hoverRect;
  1459. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1460. PDFViewer.MouseMove += PDFViewer_MouseMove;
  1461. }
  1462. }
  1463. }
  1464. //关闭ToolTip
  1465. private void CloseAnnotToolTip()
  1466. {
  1467. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1468. {
  1469. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1470. oldTips.IsOpen = false;
  1471. oldTips.Visibility = Visibility.Collapsed;
  1472. PDFViewer.ToolTip = null;
  1473. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1474. oldRect = new Rect(0, 0, 0, 0);
  1475. }
  1476. }
  1477. #endregion PDFViewer事件
  1478. #region BindingEvent事件
  1479. //同一属性面板,不同的注释类型
  1480. private void AnnotPropertyPanel_AnnotTypeChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1481. {
  1482. if (e != null && sender is SharpsAnnotPropertyViewModel sharpsAnnot)
  1483. {
  1484. AnnotHandlerEventArgs annotArgs = null;
  1485. //PropertyPanel.SaveLastAnnot();
  1486. List<AnnotHandlerEventArgs> annots = new List<AnnotHandlerEventArgs>();
  1487. foreach (AnnotArgsType argsType in e.Keys)
  1488. {
  1489. if (PropertyPanel.annot != null)
  1490. {
  1491. if (PropertyPanel.annot.EventType != argsType)
  1492. {
  1493. PDFViewer.DisableClearSelectAnnot(false);
  1494. PDFViewer.ClearSelectAnnots();
  1495. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1496. CurrentSelectedAnnot = null;
  1497. }
  1498. }
  1499. switch (argsType)
  1500. {
  1501. case AnnotArgsType.AnnotSquare:
  1502. #region TO DO
  1503. //选择一个形状注释A,在选择B(非多选),修改属性成功,以下操作的操作可以解决,
  1504. //可能会出现选择注释A,鼠标直接点击属性面板,注释A取消选中,但还可以对注释A更改属性的BUG
  1505. if (CurrentSelectedAnnot != null)
  1506. {
  1507. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotSquare)
  1508. {
  1509. //CurrentSelectedAnnot.PageIndex = -1;
  1510. //CurrentSelectedAnnot.AnnotIndex = -1;
  1511. CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1512. annots.Add(CurrentSelectedAnnot);
  1513. }
  1514. }
  1515. if (annots.Count > 0)
  1516. {
  1517. annotArgs = GetRect(annots);
  1518. }
  1519. else
  1520. {
  1521. annotArgs = GetRect();
  1522. }
  1523. #endregion TO DO
  1524. //annotArgs = GetRect();
  1525. break;
  1526. case AnnotArgsType.AnnotCircle:
  1527. #region TO DO
  1528. if (CurrentSelectedAnnot != null)
  1529. {
  1530. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotCircle)
  1531. {
  1532. //CurrentSelectedAnnot.PageIndex = -1;
  1533. //CurrentSelectedAnnot.AnnotIndex = -1;
  1534. CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1535. annots.Add(CurrentSelectedAnnot);
  1536. }
  1537. }
  1538. if (annots.Count > 0)
  1539. {
  1540. annotArgs = GetCircle(annots);
  1541. }
  1542. else
  1543. {
  1544. annotArgs = GetCircle();
  1545. }
  1546. #endregion TO DO
  1547. //annotArgs = GetCircle();
  1548. break;
  1549. case AnnotArgsType.AnnotLine:
  1550. var LineTag = e[argsType] as string;
  1551. #region TO DO
  1552. if (CurrentSelectedAnnot != null)
  1553. {
  1554. if (CurrentSelectedAnnot.EventType == AnnotArgsType.AnnotLine)
  1555. {
  1556. //CurrentSelectedAnnot.PageIndex = -1;
  1557. //CurrentSelectedAnnot.AnnotIndex = -1;
  1558. CurrentSelectedAnnot.ClientRect = Rect.Empty;
  1559. if (CurrentSelectedAnnot is LineAnnotArgs lineAnnotArgs)
  1560. {
  1561. if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
  1562. {
  1563. if (LineTag == "Arrow")
  1564. {
  1565. annots.Add(CurrentSelectedAnnot);
  1566. }
  1567. }
  1568. else
  1569. {
  1570. if (LineTag == "Line")
  1571. {
  1572. annots.Add(CurrentSelectedAnnot);
  1573. }
  1574. }
  1575. }
  1576. }
  1577. }
  1578. if (annots.Count > 0)
  1579. {
  1580. annotArgs = GetArrowLine(LineTag, annots);
  1581. }
  1582. else
  1583. {
  1584. annotArgs = GetArrowLine(LineTag);
  1585. }
  1586. #endregion TO DO
  1587. //annotArgs = GetArrowLine(LineTag);
  1588. break;
  1589. }
  1590. ShowPropertyPanel();
  1591. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Rect")
  1592. {
  1593. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  1594. return;
  1595. }
  1596. if (annotArgs != null)
  1597. {
  1598. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  1599. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1600. PDFViewer.SetToolParam(annotArgs);
  1601. }
  1602. }
  1603. }
  1604. }
  1605. //来自属性面板的事件,更改颜色等属性而触发
  1606. private void AnnotPropertyPanel_DataChanged(object sender, Dictionary<AnnotArgsType, object> e)
  1607. {
  1608. if (e != null)
  1609. {
  1610. foreach (AnnotArgsType argsType in e.Keys)
  1611. {
  1612. var key = ToolExpandDict.FirstOrDefault(q => q.Value == argsType);
  1613. switch (argsType)
  1614. {
  1615. case AnnotArgsType.AnnotHighlight:
  1616. if (e[argsType] is Color)
  1617. {
  1618. HighLightColor = new SolidColorBrush((Color)e[argsType]);
  1619. }
  1620. if (e[argsType] is double)
  1621. {
  1622. HighLightOpacity = (double)e[argsType];
  1623. }
  1624. //创建注释后,修改注释属性,可用于下次创建的注释
  1625. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1626. {
  1627. if (StrAnnotToolChecked == key.Key)
  1628. {
  1629. PDFViewer.SetToolParam(PropertyPanel.annot);
  1630. }
  1631. }
  1632. break;
  1633. case AnnotArgsType.AnnotUnderline:
  1634. if (e[argsType] is Color)
  1635. {
  1636. UnderLineColor = new SolidColorBrush((Color)e[argsType]);
  1637. }
  1638. if (e[argsType] is double)
  1639. {
  1640. UnderLineOpacity = (double)e[argsType];
  1641. }
  1642. //创建注释后,修改注释属性,可用于下次创建的注释
  1643. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1644. {
  1645. if (StrAnnotToolChecked == key.Key)
  1646. {
  1647. PDFViewer.SetToolParam(PropertyPanel.annot);
  1648. }
  1649. }
  1650. break;
  1651. case AnnotArgsType.AnnotSquiggly:
  1652. if (e[argsType] is Color)
  1653. {
  1654. SquigglyColor = new SolidColorBrush((Color)e[argsType]);
  1655. }
  1656. if (e[argsType] is double)
  1657. {
  1658. SquigglyOpacity = (double)e[argsType];
  1659. }
  1660. //创建注释后,修改注释属性,可用于下次创建的注释
  1661. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1662. {
  1663. if (StrAnnotToolChecked == key.Key)
  1664. {
  1665. PDFViewer.SetToolParam(PropertyPanel.annot);
  1666. }
  1667. }
  1668. break;
  1669. case AnnotArgsType.AnnotStrikeout:
  1670. if (e[argsType] is Color)
  1671. {
  1672. StrikeoutColor = new SolidColorBrush((Color)e[argsType]);
  1673. }
  1674. if (e[argsType] is double)
  1675. {
  1676. StrikeoutOpacity = (double)e[argsType];
  1677. }
  1678. //创建注释后,修改注释属性,可用于下次创建的注释
  1679. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1680. {
  1681. if (StrAnnotToolChecked == key.Key)
  1682. {
  1683. PDFViewer.SetToolParam(PropertyPanel.annot);
  1684. }
  1685. }
  1686. break;
  1687. case AnnotArgsType.AnnotFreehand:
  1688. if (e[argsType] is FreehandAnnotArgs)
  1689. {
  1690. var annot = e[argsType] as FreehandAnnotArgs;
  1691. if (annot != null)
  1692. {
  1693. if (PropertyPanel != null)
  1694. {
  1695. //属性面板,切换橡皮擦后,再回到画笔时,需要恢复最近画笔的属性值
  1696. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib(), PDFViewer);
  1697. PropertyPanel.AnnotEvent = AnnotEvent;
  1698. var AnnotEvents = new List<AnnotAttribEvent>();
  1699. AnnotEvents.Add(AnnotEvent);
  1700. PropertyPanel.AnnotEvents = AnnotEvents;
  1701. PropertyPanel.annot = annot;
  1702. //手绘注释工具按钮的属性
  1703. // FreehandPath.Opacity = annot.Transparency;
  1704. // FreehandPath.Fill = new SolidColorBrush(annot.InkColor);
  1705. }
  1706. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1707. {
  1708. if (StrAnnotToolChecked == key.Key)
  1709. {
  1710. PDFViewer.SetToolParam(PropertyPanel.annot);
  1711. }
  1712. }
  1713. }
  1714. }
  1715. break;
  1716. case AnnotArgsType.AnnotErase:
  1717. if (e[argsType] is ToggleButton)
  1718. {
  1719. ToggleButton clickBtn = e[argsType] as ToggleButton;
  1720. if (clickBtn.IsChecked == true)
  1721. {
  1722. if (clickBtn.Tag.ToString() != "PenBtn")
  1723. {
  1724. CustomIconToggleBtn btn = new CustomIconToggleBtn();
  1725. btn.Tag = "Freehand";
  1726. btn.IsChecked = true;
  1727. BtnMyTools_Click(btn);
  1728. break;
  1729. }
  1730. else
  1731. {
  1732. CreateEraseArgs();
  1733. }
  1734. }
  1735. }
  1736. break;
  1737. case AnnotArgsType.AnnotSquare:
  1738. case AnnotArgsType.AnnotCircle:
  1739. case AnnotArgsType.AnnotLine:
  1740. //创建注释后,修改注释属性,可用于下次创建的注释
  1741. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1742. {
  1743. if (StrAnnotToolChecked == "Rect")
  1744. {
  1745. if (PropertyPanel.SharpsAnnot == key.Key || (PropertyPanel.SharpsAnnot != key.Key && key.Key == "Arrow"))
  1746. PDFViewer.SetToolParam(PropertyPanel.annot);
  1747. PropertyPanel.SaveLastAnnot();
  1748. }
  1749. }
  1750. break;
  1751. case AnnotArgsType.AnnotFreeText:
  1752. if (PropertyPanel != null && PropertyPanel.annot != null && PDFViewer.MouseMode == MouseModes.AnnotCreate)
  1753. {
  1754. if (StrAnnotToolChecked == key.Key)
  1755. {
  1756. PDFViewer.SetToolParam(PropertyPanel.annot);
  1757. }
  1758. }
  1759. break;
  1760. }
  1761. }
  1762. }
  1763. }
  1764. private void CreateEraseArgs()
  1765. {
  1766. EraseArgs eraseArgs = new EraseArgs();
  1767. eraseArgs.UIBorderColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1768. eraseArgs.UIFillColor = Color.FromArgb(0x1A, 0x00, 0x00, 0x00);
  1769. eraseArgs.Thickness = 10;
  1770. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotErase);
  1771. if (annotProperty != null)
  1772. {
  1773. eraseArgs.Thickness = annotProperty.Thickness;
  1774. }
  1775. PDFViewer.ClearSelectAnnots(false);
  1776. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1777. PDFViewer.SetToolParam(eraseArgs);
  1778. List<AnnotHandlerEventArgs> eraseArgsList = new List<AnnotHandlerEventArgs>();
  1779. if (eraseArgs != null)
  1780. eraseArgsList.Add(eraseArgs);
  1781. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", eraseArgsList);
  1782. }
  1783. #endregion BindingEvent事件
  1784. }
  1785. }