AnnotToolContentViewModel.Command.cs 92 KB

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