AnnotToolContentViewModel.Command.cs 86 KB

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