AnnotToolContentViewModel.Command.cs 86 KB

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