FillAndSignContentViewModel.cs 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. using ComPDFKitViewer.AnnotEvent;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Office.Model;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using PDF_Office.ViewModels.Tools;
  15. using ComPDFKitViewer;
  16. using PDF_Office.Helper;
  17. using PDF_Office.Properties;
  18. using PDFSettings;
  19. using System.Windows.Media;
  20. using ComPDFKit.PDFDocument.Action;
  21. using ComPDFKit.PDFDocument;
  22. using System.Diagnostics;
  23. using ComPDFKit.PDFAnnotation;
  24. using PDF_Office.ViewModels.BOTA;
  25. using PDF_Office.Views.BOTA;
  26. using System.Windows.Forms;
  27. using Control = System.Windows.Controls.Control;
  28. using Microsoft.Office.Interop.Word;
  29. using Point = System.Windows.Point;
  30. using System.Windows.Ink;
  31. using PDF_Office.EventAggregators;
  32. using System.Management.Instrumentation;
  33. using Prism.Events;
  34. using System.Windows.Input;
  35. using ContextMenu = System.Windows.Controls.ContextMenu;
  36. using MenuItem = System.Windows.Controls.MenuItem;
  37. using System.Drawing;
  38. using Color = System.Windows.Media.Color;
  39. using Brush = System.Windows.Media.Brush;
  40. using FontFamily = System.Windows.Media.FontFamily;
  41. using ToolTip = System.Windows.Controls.ToolTip;
  42. using ContentControl = System.Windows.Controls.ContentControl;
  43. using MouseEventArgs = System.Windows.Input.MouseEventArgs;
  44. using Pen = System.Windows.Media.Pen;
  45. using PDF_Office.Model.PropertyPanel.AnnotPanel;
  46. using RadioButton = System.Windows.Controls.RadioButton;
  47. using Style = System.Windows.Style;
  48. using PDF_Office.CustomControl;
  49. using System.Windows.Controls.Primitives;
  50. using Window = System.Windows.Window;
  51. using Task = System.Threading.Tasks.Task;
  52. using Size = System.Windows.Size;
  53. namespace PDF_Office.ViewModels.FillAndSign
  54. {
  55. public class FillAndSignContentViewModel : BindableBase, INavigationAware
  56. {
  57. #region
  58. private CPDFViewer PDFViewer;
  59. private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
  60. private ViewContentViewModel viewContentViewModel;
  61. private bool isRightMenuAddAnnot = false;
  62. private IEventAggregator events;
  63. public List<List<Point>> ShapePoints = new List<List<Point>>();
  64. private string Shape = "HookShape";
  65. private PopMenu FreeHandAnnotPopMenu;
  66. private PopMenu FreeTextAnnotPopMenu;
  67. private PopMenu MultiAnnotPopMenu;
  68. private IRegionManager regions { get; set; }
  69. private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
  70. public static bool IsEdit = false;
  71. public static bool IsSignPoint = false;
  72. public Brush SelectColor = new SolidColorBrush(Colors.GreenYellow);
  73. public double FillOpacity = 1;
  74. public double LineWidth = 1;
  75. public double LineWidthMultiple = 1;
  76. private bool _HookShapeIsCheck = true;
  77. public bool HookShapeIsCheck
  78. {
  79. get { return _HookShapeIsCheck; }
  80. set { SetProperty(ref _HookShapeIsCheck, value); }
  81. }
  82. #endregion
  83. public DelegateCommand<object> AnnotDefaultValue_MenuCommand { get; set; }
  84. public DelegateCommand<object> FreeTextFontFamily_MenuCommand { get; set; }
  85. public DelegateCommand<object> AnnotColorPalette_MenuCommand { get; set; }
  86. public DelegateCommand<object> FreeTextAglin_MenuCommand { get; set; }
  87. #region Command
  88. public DelegateCommand<RoutedEventArgs> CheckCommand { get; set; }
  89. /// <summary>
  90. /// 按钮名称和属性面板映射字典
  91. /// </summary>
  92. public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
  93. #endregion
  94. public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events)
  95. {
  96. regions = regionManager;
  97. this.events = events;
  98. CheckCommand = new DelegateCommand<RoutedEventArgs>(CheckedEvent);
  99. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  100. InitDictionary();
  101. AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
  102. AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
  103. FreeTextFontFamily_MenuCommand = new DelegateCommand<object>(FreeTextFontFamily_Menu);
  104. FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
  105. InitSelectFreeHandAnnotMenu();
  106. InitSelectFreeTextAnnotMenu();
  107. }
  108. private System.Windows.Controls.Primitives.Popup popup = null;
  109. private async void AnnotColorPalette_Menu(object obj)
  110. {
  111. if (obj as CusMenuItem != null)
  112. {
  113. var menu = obj as CusMenuItem;
  114. var annot = menu.Parameter as AnnotHandlerEventArgs;
  115. if (annot != null)
  116. {
  117. var item = new ColorDropBoxPop();
  118. item.DataContext = menu;
  119. item.ColorSelected -= AnnotMenu_ColorSelected;
  120. item.ColorSelected += AnnotMenu_ColorSelected;
  121. if (popup == null)
  122. popup = new System.Windows.Controls.Primitives.Popup();
  123. ContentControl window = null;
  124. if (PDFViewer.Parent as ContentControl != null)
  125. window = PDFViewer.Parent as ContentControl;
  126. else
  127. window = App.Current.MainWindow;
  128. popup.Child = item;
  129. popup.PlacementRectangle = new Rect(Mouse.GetPosition(window), new Size(item.Width, item.Height));
  130. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
  131. popup.PlacementTarget = window;
  132. popup.IsOpen = true;
  133. Window parentWnd = Window.GetWindow(App.Current.MainWindow);
  134. if (parentWnd != null)
  135. {
  136. parentWnd.MouseDown -= parentWnd_MouseDown;
  137. parentWnd.MouseDown += parentWnd_MouseDown;
  138. }
  139. while (popup.IsOpen)
  140. await Task.Delay(20);
  141. parentWnd.MouseDown -= parentWnd_MouseDown;
  142. popup = null;
  143. }
  144. }
  145. }
  146. private void AnnotMenu_ColorSelected(object sender, Color e)
  147. {
  148. if (sender != null)
  149. {
  150. var menu = (sender as FrameworkElement).DataContext as CusMenuItem;
  151. if (menu == null) return;
  152. var annot = menu.Parameter as AnnotHandlerEventArgs;
  153. if (annot != null)
  154. {
  155. if (annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  156. {
  157. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  158. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  159. AnnotEvent?.UpdateAnnot();
  160. }
  161. else if (annot is FreeTextAnnotArgs)
  162. {
  163. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  164. if (menu.tag.ToString() == "FontColor")
  165. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  166. else
  167. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  168. AnnotEvent?.UpdateAnnot();
  169. }
  170. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  171. {
  172. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  173. if (menu.tag.ToString() == "FillColor")
  174. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  175. else
  176. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  177. AnnotEvent?.UpdateAnnot();
  178. }
  179. else if (annot is TextHighlightAnnotArgs || annot is TextUnderlineAnnotArgs || annot is TextStrikeoutAnnotArgs)
  180. {
  181. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  182. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  183. AnnotEvent?.UpdateAnnot();
  184. }
  185. }
  186. }
  187. }
  188. private void parentWnd_MouseDown(object sender, MouseButtonEventArgs e)
  189. {
  190. var ui = Mouse.DirectlyOver as FrameworkElement;
  191. if (ui != null)
  192. {
  193. if (popup != null)
  194. {
  195. popup.IsOpen = false;
  196. }
  197. }
  198. }
  199. private void FreeTextFontFamily_Menu(object obj)
  200. {
  201. if (obj as CusMenuItem != null)
  202. {
  203. var menu = obj as CusMenuItem;
  204. var annot = menu.Parameter as AnnotHandlerEventArgs;
  205. if (annot != null)
  206. {
  207. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  208. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontFamily, new FontFamily(menu.tag.ToString()));
  209. AnnotEvent?.UpdateAnnot();
  210. }
  211. }
  212. }
  213. private void FreeTextAglin_Menu(object obj)
  214. {
  215. if (obj as CusMenuItem != null)
  216. {
  217. var menu = obj as CusMenuItem;
  218. var annot = menu.Parameter as AnnotHandlerEventArgs;
  219. var tag = menu.control.Tag;
  220. if (annot != null && tag != null)
  221. {
  222. var strTag = tag.ToString();
  223. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  224. if (strTag == "Left")
  225. {
  226. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  227. }
  228. else if (strTag == "Center")
  229. {
  230. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  231. }
  232. else if (strTag == "Right")
  233. {
  234. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  235. }
  236. else if (strTag == "Justify")
  237. {
  238. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Justify);
  239. }
  240. AnnotEvent?.UpdateAnnot();
  241. }
  242. }
  243. }
  244. private void AnnotDefaultValues_Menu(object obj)
  245. {
  246. if (obj as CusMenuItem != null)
  247. {
  248. var menu = obj as CusMenuItem;
  249. var annot = menu.Parameter as AnnotHandlerEventArgs;
  250. if (annot != null)
  251. {
  252. if (annot is FreehandAnnotArgs)
  253. {
  254. var freeHand = annot as FreehandAnnotArgs;
  255. var color = freeHand.InkColor;
  256. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  257. var FreehandDefault = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  258. FreehandDefault.ForgoundColor = color;
  259. FreehandDefault.Opacity = freeHand.Transparency;
  260. FreehandDefault.Thickness = freeHand.LineWidth;
  261. var isSolid = AnnotPropertyPanel.IsSolidStyle(freeHand.LineDash);
  262. if (isSolid)
  263. {
  264. FreehandDefault.DashArray = null;
  265. }
  266. else
  267. {
  268. FreehandDefault.DashArray = new List<double>();
  269. foreach (var item in freeHand.LineDash.Dashes)
  270. {
  271. FreehandDefault.DashArray.Add(item);
  272. }
  273. }
  274. SettingHelper.SetAnnotDefaultProperty(FreehandDefault);
  275. }
  276. }
  277. }
  278. }
  279. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  280. {
  281. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  282. if (Annot == null)
  283. {
  284. Annot = new DefaultAnnotProperty();
  285. Annot.AnnotToolType = annotArgsType;
  286. }
  287. return Annot;
  288. }
  289. private void CheckedEvent(RoutedEventArgs e)
  290. {
  291. IsEdit = false;
  292. var control = e.OriginalSource as Control;
  293. //NavigateToProperty(control.Name);
  294. //不创建注释,属于注释模板
  295. bool isTemplateAnnot = false;
  296. bool isSnapshotEdit = false;
  297. AnnotHandlerEventArgs annotArgs = null;
  298. var tag = control.Name;
  299. FindAnnotTypeKey(control.Name, ref annotArgs);
  300. if (control.Name == "RbtnSign") { isTemplateAnnot = true; }
  301. if (tag == "SnapshotEdit")
  302. {
  303. isSnapshotEdit = true;
  304. }
  305. else if (tag == "Signature" || tag == "Stamp")
  306. {
  307. isTemplateAnnot = true;
  308. }
  309. if (annotArgs != null)
  310. {
  311. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  312. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  313. PDFViewer.SetToolParam(annotArgs);
  314. isRightMenuAddAnnot = false;
  315. }
  316. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  317. if (isTemplateAnnot == false && annotArgs == null)
  318. {
  319. PDFViewer.SetMouseMode(MouseModes.PanTool);
  320. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  321. }
  322. else
  323. {
  324. if (isSnapshotEdit == true)
  325. {
  326. ShowPropertyPanel(false);
  327. isSnapshotEdit = false;
  328. }
  329. else
  330. {
  331. ShowPropertyPanel(true);
  332. }
  333. }
  334. }
  335. private void InitCheckedEvent(string e)
  336. {
  337. IsEdit = false;
  338. //NavigateToProperty(control.Name);
  339. //不创建注释,属于注释模板
  340. bool isTemplateAnnot = false;
  341. bool isSnapshotEdit = false;
  342. AnnotHandlerEventArgs annotArgs = null;
  343. var tag = e;
  344. FindAnnotTypeKey(e, ref annotArgs);
  345. if (e == "RbtnSign") { isTemplateAnnot = true; }
  346. if (tag == "SnapshotEdit")
  347. {
  348. isSnapshotEdit = true;
  349. }
  350. else if (tag == "Signature" || tag == "Stamp")
  351. {
  352. isTemplateAnnot = true;
  353. }
  354. if (annotArgs != null)
  355. {
  356. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  357. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  358. PDFViewer.SetToolParam(annotArgs);
  359. isRightMenuAddAnnot = false;
  360. }
  361. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  362. if (isTemplateAnnot == false && annotArgs == null)
  363. {
  364. PDFViewer.SetMouseMode(MouseModes.PanTool);
  365. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  366. }
  367. else
  368. {
  369. if (isSnapshotEdit == true)
  370. {
  371. ShowPropertyPanel(false);
  372. isSnapshotEdit = false;
  373. }
  374. else
  375. {
  376. ShowPropertyPanel(true);
  377. }
  378. }
  379. }
  380. //注释工具
  381. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  382. {
  383. LineWidthMultiple = 1;
  384. IsSignPoint = false;
  385. switch (tag)
  386. {
  387. case "RbtnDate":
  388. case "RbtnText"://文本
  389. annotArgs = GetFreetext();
  390. break;
  391. case "Freetext"://文本
  392. annotArgs = GetFreetext();
  393. break;
  394. case "RbtnSign"://签名
  395. annotArgs = GetSignature();
  396. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  397. break;
  398. case "RbtnTick"://勾
  399. Shape = "HookShape";
  400. ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
  401. annotArgs = GetStamp();
  402. break;
  403. case "RbtnFork"://叉
  404. Shape = "ForkShape";
  405. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(12.8, 12.8) }, new List<Point> { new Point(12.8, 3.20001), new Point(3.20005, 12.8) } };
  406. annotArgs = GetStamp();
  407. break;
  408. case "RbtnRectangle"://矩形
  409. Shape = "RectShape";
  410. ShapePoints = new List<List<Point>> { new List<Point> { new Point(5, 5), new Point(28, 5) }, new List<Point> { new Point(28, 5), new Point(28, 27) }, new List<Point> { new Point(28, 27), new Point(5, 27) }, new List<Point> { new Point(5, 27), new Point(5, 5) } };
  411. annotArgs = GetStamp();
  412. break;
  413. case "RbtnLine"://下划线
  414. Shape = "LineShape";
  415. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(28, 3.20001) } };
  416. annotArgs = GetStamp();
  417. break;
  418. case "RbtnPoint":
  419. IsSignPoint = true;
  420. Shape = "DotShape";
  421. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.19995), new Point(3.19995, 3.19995) } };
  422. LineWidthMultiple = 5;
  423. annotArgs = GetStamp();
  424. break;
  425. default://图章
  426. break;
  427. }
  428. }
  429. /// <summary>
  430. /// 签名
  431. /// </summary>
  432. /// <returns></returns>
  433. private AnnotHandlerEventArgs GetSignature()
  434. {
  435. AddToPropertyPanel("SignatureAnnotProperty");
  436. return null;
  437. }
  438. /// <summary>
  439. /// 图章
  440. /// </summary>
  441. /// <returns></returns>
  442. private AnnotHandlerEventArgs GetStamp(List<AnnotHandlerEventArgs> selectedArgs = null)
  443. {
  444. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  445. stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  446. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  447. //PDFViewer.SetToolParam(stampArgs);
  448. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  449. //stampAnnotArgs.Opacity = 1;
  450. //stampAnnotArgs.StampText = "APPROVED";
  451. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  452. // stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  453. stampAnnotArgs.IsContinueMode = true;
  454. stampAnnotArgs.IsSignPoint = IsSignPoint;
  455. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  456. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  457. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  458. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  459. if (stampAnnotArgs != null)
  460. stampAnnotArgsList.Add(stampAnnotArgs);
  461. //if (selectedArgs != null) {
  462. //var annot = selectedArgs[0];
  463. //if (annot != null)
  464. //{
  465. // foreach (var item in selectedArgs)
  466. // {
  467. // selectedArgs[selectedArgs.IndexOf(item)] = stampAnnotArgs;
  468. // }
  469. // AddToPropertyPanel("ShapFillProperty", "", selectedArgs, annotAttribsList);
  470. // return stampAnnotArgs;
  471. //}
  472. // }
  473. AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  474. return stampAnnotArgs;
  475. }
  476. public void SetStamp()
  477. {
  478. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  479. stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  480. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  481. //PDFViewer.SetToolParam(stampArgs);
  482. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  483. //stampAnnotArgs.Opacity = 1;
  484. //stampAnnotArgs.StampText = "APPROVED";
  485. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  486. stampAnnotArgs.IsContinueMode = true;
  487. stampAnnotArgs.IsSignPoint = IsSignPoint;
  488. stampAnnotArgs.Opacity = FillOpacity;
  489. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  490. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  491. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  492. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  493. if (stampAnnotArgs != null)
  494. stampAnnotArgsList.Add(stampAnnotArgs);
  495. AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  496. bool isTemplateAnnot = false;
  497. bool isSnapshotEdit = false;
  498. AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
  499. if (annotArgs != null)
  500. {
  501. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  502. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  503. PDFViewer.SetToolParam(annotArgs);
  504. isRightMenuAddAnnot = false;
  505. }
  506. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  507. if (isTemplateAnnot == false && annotArgs == null)
  508. {
  509. PDFViewer.SetMouseMode(MouseModes.PanTool);
  510. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  511. }
  512. else
  513. {
  514. if (isSnapshotEdit == true)
  515. {
  516. ShowPropertyPanel(false);
  517. isSnapshotEdit = false;
  518. }
  519. else
  520. {
  521. ShowPropertyPanel(true);
  522. }
  523. }
  524. }
  525. /// <summary>
  526. /// 手绘
  527. /// </summary>
  528. /// <param name="selectedArgs"></param>
  529. /// <returns></returns>
  530. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  531. {
  532. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  533. List<AnnotHandlerEventArgs> newSelectedArgs = new List<AnnotHandlerEventArgs>();
  534. FreehandAnnotArgs freehandArgs = null;
  535. if (selectedArgs == null || selectedArgs.Count == 0)
  536. {
  537. freehandArgs = new FreehandAnnotArgs();
  538. var annotate = Settings.Default.AppProperties.Annotate;
  539. if (annotate != null)
  540. {
  541. freehandArgs.InkColor = annotate.FreeHandColor;
  542. }
  543. else
  544. {
  545. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  546. }
  547. freehandArgs.RawPointList = new List<List<Point>> { new List<Point> { new Point(0.599976, 7.0286), new Point(5.57775, 11.8), new Point(13.4, 1.40002) } };
  548. freehandArgs.Transparency = 1;
  549. freehandArgs.LineWidth = 2;
  550. if (freehandArgs != null)
  551. {
  552. selectedArgs = new List<AnnotHandlerEventArgs>();
  553. selectedArgs.Add(freehandArgs);
  554. }
  555. }
  556. else
  557. {
  558. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  559. foreach (var item in selectedArgs)
  560. {
  561. //if (ListPoint((item as FreehandAnnotArgs).RawPointList, ShapePoints)){
  562. foreach (var point in viewContentViewModel.FillAndSign)
  563. {
  564. if ((item as FreehandAnnotArgs).PageIndex == point.X && (item as FreehandAnnotArgs).AnnotIndex == point.Y)
  565. {
  566. newSelectedArgs.Add(item);
  567. }
  568. }
  569. }
  570. freehandArgs.RawPointList = ShapePoints;
  571. freehandArgs.InkColor = (SelectColor as SolidColorBrush).Color;
  572. freehandArgs.Transparency = 1;
  573. freehandArgs.LineWidth = LineWidth;
  574. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  575. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  576. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  577. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  578. annotAttribsList[AnnotAttrib.Path] = freehandArgs.RawPointList;
  579. annotAttribsList[AnnotAttrib.Width] = freehandArgs.Width;
  580. annotAttribsList[AnnotAttrib.Height] = freehandArgs.Height;
  581. AddToPropertyPanel("ShapFillProperty", "Freehand", newSelectedArgs, annotAttribsList);
  582. //GetStamp();
  583. return freehandArgs;
  584. }
  585. //annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  586. //annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  587. //annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  588. //annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  589. //AddToPropertyPanel("ShapFillProperty", "Freehand", selectedArgs, annotAttribsList);
  590. return freehandArgs;
  591. }
  592. private bool ListPoint(List<List<Point>> leftpoints, List<List<Point>> rightpoints)
  593. {
  594. if (leftpoints.Count == rightpoints.Count)
  595. {
  596. if (leftpoints[0][0].X == rightpoints[0][0].X) { return true; }
  597. }
  598. return false;
  599. }
  600. /// <summary>
  601. /// 文本
  602. /// </summary>
  603. /// <param name="selectedfreetextArgs"></param>
  604. /// <returns></returns>
  605. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  606. {
  607. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  608. FreeTextAnnotArgs freetextArgs = null;
  609. TextAlignment textAlignment;
  610. if (selectedArgs == null || selectedArgs.Count == 0)
  611. {
  612. freetextArgs = new FreeTextAnnotArgs();
  613. freetextArgs.Align = TextAlignment.Left;
  614. freetextArgs.BgColor = Colors.Transparent;
  615. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  616. freetextArgs.FontColor = Colors.Black;
  617. freetextArgs.FontSize = 14;
  618. freetextArgs.Transparency = 1;
  619. freetextArgs.LineColor = Colors.Black;
  620. freetextArgs.LineWidth = 0;
  621. freetextArgs.TextContent = string.Empty;
  622. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  623. if (annotProperty != null)
  624. {
  625. freetextArgs.Align = annotProperty.TextAlign;
  626. freetextArgs.BgColor = annotProperty.BackgroundColor;
  627. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  628. freetextArgs.FontColor = annotProperty.ForgoundColor;
  629. freetextArgs.FontSize = annotProperty.FontSize;
  630. freetextArgs.Transparency = annotProperty.Opacity;
  631. freetextArgs.LineColor = annotProperty.BorderColor;
  632. freetextArgs.LineWidth = annotProperty.Thickness;
  633. freetextArgs.TextContent = annotProperty.NoteText;
  634. freetextArgs.FontWeight = annotProperty.FontWeight;
  635. freetextArgs.FontStyle = annotProperty.FontStyle;
  636. }
  637. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  638. if (align == 0)
  639. textAlignment = TextAlignment.Left;
  640. else if (align == 1)
  641. textAlignment = TextAlignment.Center;
  642. else
  643. textAlignment = TextAlignment.Right;
  644. if (freetextArgs != null)
  645. {
  646. selectedArgs = new List<AnnotHandlerEventArgs>();
  647. selectedArgs.Add(freetextArgs);
  648. }
  649. }
  650. else
  651. {
  652. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  653. textAlignment = freetextArgs.Align;
  654. }
  655. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  656. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  657. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  658. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  659. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  660. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  661. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  662. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  663. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  664. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  665. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  666. annotAttribsList[AnnotAttrib.Text] = freetextArgs.TextContent;
  667. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
  668. return freetextArgs;
  669. }
  670. /// <summary>
  671. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  672. /// </summary>
  673. /// <param name="viewContent">对应的注释面板</param>
  674. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  675. /// <param name="annot">注释</param>
  676. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  677. private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
  678. {
  679. if (annots != null && annots.Count != 0)
  680. {
  681. propertyPanel.annotlists = annots;
  682. propertyPanel.annot = annots[0];
  683. }
  684. else
  685. {
  686. propertyPanel.annotlists = null;
  687. propertyPanel.annot = null;
  688. }
  689. if (annotAttribsList != null && annotAttribsList.Count != 0 && annots != null && annots.Count != 0)
  690. {
  691. if (annots.Count > 1)
  692. {
  693. if (propertyPanel.AnnotEvents == null)
  694. propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
  695. propertyPanel.AnnotEvents.Clear();
  696. foreach (var itemAnnot in annots)
  697. {
  698. var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
  699. propertyPanel.AnnotEvents.Add(eventitem);
  700. }
  701. }
  702. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
  703. if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
  704. {
  705. propertyPanel.AnnotEvent = annotAttribEvent;
  706. }
  707. }
  708. if (toolTag == "Freetext")
  709. {
  710. propertyPanel.SetIsTextFill(true);
  711. }
  712. else
  713. {
  714. propertyPanel.SetIsTextFill(false);
  715. }
  716. if (string.IsNullOrEmpty(viewContent) == false)
  717. {
  718. if (isUpData) { return; }
  719. if (viewContent == "ShapFillProperty") { NavigateToProperty(viewContent, propertyPanel); return; }
  720. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  721. }
  722. }
  723. private void NavigateToProperty(string btnName, AnnotPropertyPanel annotPropertyPanel)
  724. {
  725. NavigationParameters values = new NavigationParameters();
  726. values.Add(ParameterNames.PDFViewer, PDFViewer);
  727. values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  728. values.Add("Shape", Shape);
  729. values.Add("FillAndSignContentViewModel", this);
  730. regions.RequestNavigate(RegionNames.PropertyRegionName, btnName, values);
  731. viewContentViewModel.IsPropertyOpen = true;
  732. }
  733. /// <summary>
  734. /// 初始化按钮名称-属性面板字典
  735. /// </summary>
  736. private void InitDictionary()
  737. {
  738. btnToProperty["RbtnText"] = "TextFillProperty";
  739. btnToProperty["RbtnTick"] = "ShapFillProperty";
  740. btnToProperty["RbtnFork"] = "ShapFillProperty";
  741. btnToProperty["RbtnRectangle"] = "ShapFillProperty";
  742. btnToProperty["RbtnLine"] = "ShapFillProperty";
  743. btnToProperty["RbtnPoint"] = "ShapFillProperty";
  744. btnToProperty["RbtnDate"] = "DateFillProperty";
  745. btnToProperty["RbtnSign"] = "";
  746. }
  747. /// <summary>
  748. /// 手绘
  749. /// </summary>
  750. private void InitSelectFreeHandAnnotMenu()
  751. {
  752. var popMenu = new ContextMenu();
  753. PopMenu pop = new PopMenu(popMenu);
  754. var menuItem = new MenuItem();
  755. menuItem.Name = "FreeHandCopy";
  756. menuItem.Header = "复制";
  757. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  758. menuItem = new MenuItem();
  759. menuItem.Name = "FreeHandCut";
  760. menuItem.Header = "剪切";
  761. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  762. menuItem = new MenuItem();
  763. menuItem.Name = "FreeHandPaste";
  764. menuItem.Header = "粘贴";
  765. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  766. menuItem = new MenuItem();
  767. menuItem.Name = "FreeHandDelete";
  768. menuItem.Header = "删除";
  769. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  770. pop.AddItem(GetSeparator());
  771. menuItem = new MenuItem();
  772. menuItem.Name = "FreeHandDefault";
  773. menuItem.Header = "设置当前属性为默认值";
  774. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  775. FreeHandAnnotPopMenu = pop;
  776. }
  777. /// <summary>
  778. /// 文本
  779. /// </summary>
  780. private void InitSelectFreeTextAnnotMenu()
  781. {
  782. var popMenu = new ContextMenu();
  783. PopMenu pop = new PopMenu(popMenu);
  784. var menuItem = new MenuItem();
  785. menuItem.Name = "FreeTextCopy";
  786. menuItem.Header = "复制";
  787. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  788. menuItem = new MenuItem();
  789. menuItem.Name = "FreeTextCut";
  790. menuItem.Header = "剪切";
  791. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  792. menuItem = new MenuItem();
  793. menuItem.Name = "FreeTextPaste";
  794. menuItem.Header = "粘贴";
  795. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  796. menuItem = new MenuItem();
  797. menuItem.Name = "FreeTextDelete";
  798. menuItem.Header = "删除";
  799. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  800. pop.AddItem(GetSeparator());
  801. menuItem = new MenuItem();
  802. menuItem.Name = "FreeTextColor";
  803. menuItem.Header = "字体颜色";
  804. menuItem.Tag = "FontColor";
  805. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  806. menuItem = new MenuItem();
  807. menuItem.Name = "FreeTextColor";
  808. menuItem.Header = "填充颜色";
  809. menuItem.Tag = "FillColor";
  810. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  811. menuItem = new MenuItem();
  812. menuItem.Name = "FreeTextFontFamily";
  813. menuItem.Header = "字体";
  814. pop.AddItem(menuItem);
  815. var family = TextFont.GetFamily();
  816. foreach (var item in family)
  817. {
  818. RadioButton familyRdioBtn = new RadioButton();
  819. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  820. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  821. familyRdioBtn.Name = item.ValueStr;
  822. familyRdioBtn.Tag = item.ValueStr;
  823. familyRdioBtn.GroupName = "FontFamily";
  824. familyRdioBtn.Content = item.Content;
  825. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  826. }
  827. menuItem = new MenuItem();
  828. menuItem.Name = "FreeTextAglin";
  829. menuItem.Header = "文本对齐";
  830. pop.AddItem(menuItem);
  831. var radioButton = new RadioButton();
  832. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  833. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  834. radioButton.Name = "FreeTextAglinLeft";
  835. radioButton.Tag = "Left";
  836. radioButton.GroupName = "Aglin";
  837. radioButton.Content = "左对齐";
  838. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  839. radioButton = new RadioButton();
  840. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  841. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  842. radioButton.Name = "FreeTextAglinCenter";
  843. radioButton.Tag = "Center";
  844. radioButton.GroupName = "Aglin";
  845. radioButton.Content = "居中对齐";
  846. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  847. radioButton = new RadioButton();
  848. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  849. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  850. radioButton.Name = "FreeTextAglinRight";
  851. radioButton.Tag = "Right";
  852. radioButton.GroupName = "Aglin";
  853. radioButton.Content = "右对齐";
  854. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  855. radioButton = new RadioButton();
  856. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  857. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  858. radioButton.Name = "FreeTextAglinJustify";
  859. radioButton.Tag = "Justify";
  860. radioButton.GroupName = "Aglin";
  861. radioButton.Content = "两端对齐";
  862. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  863. menuItem = new MenuItem();
  864. menuItem.Name = "FreeHandDefault";
  865. menuItem.Header = "设置当前属性为默认值";
  866. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  867. FreeTextAnnotPopMenu = pop;
  868. }
  869. private Separator GetSeparator()
  870. {
  871. Separator separator = new Separator();
  872. separator.Height = 1;
  873. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  874. separator.BorderThickness = new Thickness(1);
  875. return separator;
  876. }
  877. private void BindingPDFViewerHandler()
  878. {
  879. //来自PDFViewer的响应事件
  880. if (PDFViewer != null)
  881. {
  882. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  883. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  884. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  885. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  886. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  887. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  888. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  889. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  890. }
  891. }
  892. private void UnBindingPDFViewerHandler()
  893. {
  894. if (PDFViewer != null)
  895. {
  896. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  897. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  898. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  899. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  900. }
  901. }
  902. //在注释工具的状态下,右键菜单
  903. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  904. {
  905. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  906. return;
  907. switch (e.CommandType)
  908. {
  909. case CommandType.Context:
  910. if (e.AnnotEventArgsList.Count > 0)
  911. {
  912. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  913. {
  914. //绑定标记密文处右键菜单
  915. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  916. }
  917. else
  918. {
  919. if (e.AnnotEventArgsList.Count == 1)
  920. {
  921. var selectedAnnot = e.AnnotEventArgsList[0];
  922. switch (selectedAnnot.EventType)
  923. {
  924. case AnnotArgsType.AnnotFreehand:
  925. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  926. break;
  927. case AnnotArgsType.AnnotFreeText:
  928. e.PopupMenu= FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  929. break;
  930. }
  931. }
  932. else
  933. {
  934. bool isHigh = true;//是否为高亮
  935. foreach (var item in e.AnnotEventArgsList)
  936. {
  937. if (isHightAnnot(item) == false)
  938. {
  939. isHigh = false;
  940. break;
  941. }
  942. }
  943. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  944. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  945. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  946. }
  947. }
  948. if (e.PopupMenu != null)
  949. {
  950. e.Handle = true;
  951. }
  952. }
  953. else
  954. {
  955. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  956. {
  957. if (e.PopupMenu != null)
  958. {
  959. e.Handle = true;
  960. }
  961. }
  962. else
  963. {
  964. e.PopupMenu = ViewerContextMenu(sender);
  965. if (e.PopupMenu != null)
  966. {
  967. e.Handle = true;
  968. }
  969. }
  970. }
  971. break;
  972. }
  973. }
  974. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  975. {
  976. if (e != null && e.DrawContext != null)
  977. {
  978. Rect hoverRect = new Rect(
  979. e.PaintRect.Left - 2,
  980. e.PaintRect.Top - 2,
  981. e.PaintRect.Width + 4,
  982. e.PaintRect.Height + 4);
  983. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  984. hoverPen.DashStyle = DashStyles.Dash;
  985. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  986. //Todo:目前ComPDFKit.Viewer没有e.Annot参数
  987. //便签,显示ToolTip内容
  988. //if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  989. //{
  990. // if (PDFViewer.ToolTip == null)
  991. // {
  992. // var content = e.Annot.GetContent();
  993. // if (string.IsNullOrEmpty(content) == false)
  994. // {
  995. // ToolTip TipChild = new ToolTip();
  996. // TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  997. // TipChild.MaxWidth = 246;
  998. // TipChild.Content = content;
  999. // TipChild.Visibility = Visibility.Visible;
  1000. // TipChild.IsOpen = true;
  1001. // TipChild.Placement = PlacementMode.Right;
  1002. // var rec = e.Annot.GetRect();
  1003. // TipChild.PlacementRectangle = new Rect(rec.left, rec.top, rec.right, rec.bottom);
  1004. // TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  1005. // TipChild.Placement = PlacementMode.MousePoint;
  1006. // PDFViewer.ToolTip = TipChild;
  1007. // oldRect = hoverRect;
  1008. // PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1009. // PDFViewer.MouseMove += PDFViewer_MouseMove;
  1010. // return;
  1011. // }
  1012. // }
  1013. //}
  1014. }
  1015. CloseAnnotToolTip();
  1016. }
  1017. private Rect oldRect = new Rect(0, 0, 0, 0);
  1018. private void CloseAnnotToolTip()
  1019. {
  1020. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1021. {
  1022. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1023. oldTips.IsOpen = false;
  1024. oldTips.Visibility = Visibility.Collapsed;
  1025. PDFViewer.ToolTip = null;
  1026. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1027. oldRect = new Rect(0, 0, 0, 0);
  1028. }
  1029. }
  1030. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1031. {
  1032. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1033. {
  1034. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1035. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1036. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1037. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1038. {
  1039. CloseAnnotToolTip();
  1040. }
  1041. }
  1042. }
  1043. private ContextMenu ViewerContextMenu(object sender)
  1044. {
  1045. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1046. ViewerContextMenu_Loaded(contextMenu, sender);
  1047. return contextMenu;
  1048. }
  1049. private void ViewerContextMenu_Loaded(object sender, object e, Visibility visibility = Visibility.Collapsed)
  1050. {
  1051. ContextMenu contextMenu = sender as ContextMenu;
  1052. if (contextMenu.Items.Count > 0)
  1053. {
  1054. int index = PDFViewer.CurrentIndex;
  1055. //检测是否已存在相同数据
  1056. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  1057. foreach (var item in contextMenu.Items)
  1058. {
  1059. if (item is Separator separator)
  1060. {
  1061. separator.Visibility = visibility;
  1062. }
  1063. if (item is MenuItem menuItem1)
  1064. {
  1065. //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
  1066. //{
  1067. // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  1068. //}
  1069. switch (menuItem1.Tag.ToString())
  1070. {
  1071. case "Paste":
  1072. //粘贴
  1073. //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
  1074. //{
  1075. // menuItem1.IsEnabled = false;
  1076. // menuItem1.Opacity = 0.5;
  1077. //}
  1078. //else
  1079. //{
  1080. // menuItem1.IsEnabled = true;
  1081. // menuItem1.Opacity = 1;
  1082. //}
  1083. menuItem1.CommandTarget = (UIElement)e;
  1084. menuItem1.Command = ApplicationCommands.Paste;
  1085. break;
  1086. case "AddAnnotation":
  1087. menuItem1.Visibility = visibility;
  1088. break;
  1089. case "HiddenAnnot":
  1090. menuItem1.Visibility = visibility;
  1091. break;
  1092. case "DisplayAnnot":
  1093. menuItem1.Visibility = visibility;
  1094. break;
  1095. case "AddBookMark":
  1096. menuItem1.Visibility = visibility;
  1097. break;
  1098. case "DelBookMark":
  1099. menuItem1.Visibility = visibility;
  1100. break;
  1101. case "ToolMode":
  1102. menuItem1.Visibility = visibility;
  1103. break;
  1104. case "ReadModel":
  1105. menuItem1.Visibility = visibility;
  1106. break;
  1107. case "UnReadModel":
  1108. menuItem1.Visibility = visibility;
  1109. break;
  1110. case "ViewZoom":
  1111. menuItem1.Visibility = visibility;
  1112. break;
  1113. case "PageDisplay":
  1114. menuItem1.Visibility = visibility;
  1115. break;
  1116. case "Select":
  1117. menuItem1.Click -= Select_Click;
  1118. menuItem1.Click += Select_Click;
  1119. break;
  1120. case "Print":
  1121. menuItem1.Command = viewContentViewModel.PrintCommand;
  1122. break;
  1123. }
  1124. }
  1125. }
  1126. }
  1127. }
  1128. private void Select_Click(object sender, RoutedEventArgs e)
  1129. {
  1130. if (viewContentViewModel.OpenBOTA == false)
  1131. {
  1132. viewContentViewModel.OpenBOTA = true;
  1133. }
  1134. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1135. if (isBook == false)
  1136. {
  1137. bOTAContent.TabItemSearch.IsSelected = true;
  1138. }
  1139. }
  1140. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1141. {
  1142. bool isTabItem = false;
  1143. bOTAContentViewModel = null;
  1144. bOTAContent = null;
  1145. if (regions.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  1146. {
  1147. var views = regions.Regions[viewContentViewModel.BOTARegionName].Views;
  1148. var model = views.FirstOrDefault(q => q is BOTAContent);
  1149. if (model is BOTAContent bOTAContent1)
  1150. {
  1151. bOTAContent = bOTAContent1;
  1152. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1153. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1154. {
  1155. isTabItem = true;
  1156. }
  1157. }
  1158. //foreach (var item in views)
  1159. //{
  1160. // if (item is BOTAContent bOTAContent1)
  1161. // {
  1162. // bOTAContent = bOTAContent1;
  1163. // bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1164. // if (bOTAContentViewModel.CurrentBar == tabItemText)
  1165. // {
  1166. // isTabItem = true;
  1167. // break;
  1168. // }
  1169. // }
  1170. //}
  1171. }
  1172. return isTabItem;
  1173. }
  1174. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  1175. {
  1176. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  1177. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  1178. annot.EventType == AnnotArgsType.AnnotHighlight ||
  1179. annot.EventType == AnnotArgsType.AnnotStrikeout
  1180. )
  1181. {
  1182. return true;
  1183. }
  1184. else
  1185. {
  1186. return false;
  1187. }
  1188. }
  1189. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1190. {
  1191. if (e != null && e.Count > 0)
  1192. {
  1193. for (int i = 0; i < e.Count; i++)
  1194. {
  1195. AnnotEditEvent editEvent = e[i];
  1196. switch (editEvent.EditAction)
  1197. {
  1198. case ActionType.Add:
  1199. int pageindex = editEvent.PageIndex;
  1200. int annotindex = editEvent.AnnotIndex;
  1201. viewContentViewModel.FillAndSign.Add(new Point(pageindex, annotindex));
  1202. break;
  1203. }
  1204. }
  1205. }
  1206. }
  1207. //选中和非选中注释,右键菜单
  1208. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  1209. {
  1210. if (e != null)
  1211. {
  1212. var annot = e.AnnotItemsList[0];
  1213. if (annot != null)
  1214. {
  1215. if (e.AnnotItemsList.Count == 1)
  1216. {
  1217. //IsEdit = false;
  1218. //IsAnnotCreateReset:是否为创建注释的状态
  1219. if (e.IsAnnotCreateReset == false)
  1220. {
  1221. GetSelectedAnnots(e);
  1222. //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
  1223. //PDFViewer.SetToolParam(annot);
  1224. }
  1225. else
  1226. {
  1227. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  1228. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  1229. annot.EventType != AnnotArgsType.AnnotUnderline &&
  1230. annot.EventType != AnnotArgsType.AnnotHighlight &&
  1231. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  1232. annot.EventType != AnnotArgsType.AnnotLink &&
  1233. annot.EventType != AnnotArgsType.AnnotFreehand &&
  1234. annot.EventType != AnnotArgsType.AnnotSticky
  1235. )
  1236. {
  1237. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  1238. {
  1239. foreach (var item in ToolExpandDict)
  1240. {
  1241. if (item.Value == e.AnnotItemsList[0].EventType)
  1242. {
  1243. annot = null;//新建注释时,回到默认值
  1244. FindAnnotTypeKey(item.Key, ref annot);
  1245. break;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. //else
  1251. //PDFViewer.SetToolParam(annot);
  1252. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  1253. if (isRightMenuAddAnnot)
  1254. {
  1255. ShowPropertyPanel(false);
  1256. }
  1257. else
  1258. {
  1259. ShowPropertyPanel();
  1260. }
  1261. }
  1262. }
  1263. else
  1264. {
  1265. bool isDifferentAnnotTyle = false;
  1266. var lastAnnot = annot;
  1267. foreach (var item in e.AnnotItemsList)
  1268. {
  1269. if (lastAnnot.EventType != item.EventType)
  1270. {
  1271. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  1272. {
  1273. lastAnnot = item;
  1274. continue;
  1275. }
  1276. lastAnnot = item;
  1277. isDifferentAnnotTyle = true;
  1278. break;
  1279. }
  1280. }
  1281. if (isDifferentAnnotTyle)
  1282. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1283. else
  1284. GetSelectedAnnots(e);
  1285. }
  1286. }
  1287. }
  1288. else
  1289. {
  1290. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1291. }
  1292. }
  1293. //private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1294. //{
  1295. // if (e != null && e.Count > 0)
  1296. // {
  1297. // for (int i = 0; i < e.Count; i++)
  1298. // {
  1299. // AnnotEditEvent editEvent = e[i];
  1300. // switch (editEvent.EditAction)
  1301. // {
  1302. // case ActionType.Add:
  1303. // // bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1304. // if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  1305. // {
  1306. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1307. // if (viewModel != null)
  1308. // {
  1309. // int pageindex = editEvent.PageIndex;
  1310. // int annotindex = editEvent.AnnotIndex;
  1311. // viewModel.UpdateAddedAnnot(pageindex, annotindex);
  1312. // }
  1313. // }
  1314. // break;
  1315. // case ActionType.Del:
  1316. // //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1317. // if (isTabItemAnnotation)
  1318. // {
  1319. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1320. // if (viewModel != null)
  1321. // {
  1322. // int pageindex = editEvent.PageIndex;
  1323. // int annotindex = editEvent.AnnotIndex;
  1324. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  1325. // }
  1326. // }
  1327. // break;
  1328. // case ActionType.Modify:
  1329. // isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1330. // if (bOTAContent.TabItemAnnotation.IsSelected)
  1331. // {
  1332. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1333. // if (viewModel != null)
  1334. // {
  1335. // int pageindex = editEvent.PageIndex;
  1336. // int annotindex = editEvent.AnnotIndex;
  1337. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  1338. // }
  1339. // }
  1340. // break;
  1341. // case ActionType.TextEdit:
  1342. // break;
  1343. // default:
  1344. // break;
  1345. // }
  1346. // }
  1347. // }
  1348. //}
  1349. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  1350. {
  1351. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  1352. annot.EventType == AnnotArgsType.AnnotSquare ||
  1353. annot.EventType == AnnotArgsType.AnnotLine
  1354. )
  1355. {
  1356. return true;
  1357. }
  1358. else
  1359. {
  1360. return false;
  1361. }
  1362. }
  1363. private void GetSelectedAnnots(AnnotAttribEvent e)
  1364. {
  1365. IsEdit = true;
  1366. var annot = e.AnnotItemsList[0];
  1367. switch (annot.EventType)
  1368. {
  1369. case AnnotArgsType.AnnotFreeText:
  1370. GetFreetext(e.AnnotItemsList);
  1371. break;
  1372. case AnnotArgsType.AnnotFreehand:
  1373. GetFreehand(e.AnnotItemsList);
  1374. break;
  1375. }
  1376. }
  1377. private void ShowPropertyPanel(bool show = true)
  1378. {
  1379. viewContentViewModel.IsPropertyOpen = show;
  1380. }
  1381. #region Navigation
  1382. public bool IsNavigationTarget(NavigationContext navigationContext)
  1383. {
  1384. return true;
  1385. }
  1386. public void OnNavigatedFrom(NavigationContext navigationContext)
  1387. {
  1388. UnBindingPDFViewerHandler();
  1389. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1390. ViewerContextMenu_Loaded(contextMenu, null, Visibility.Visible);
  1391. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1392. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1393. ShowPropertyPanel(false);
  1394. }
  1395. public void OnNavigatedTo(NavigationContext navigationContext)
  1396. {
  1397. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1398. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1399. BindingPDFViewerHandler();
  1400. HookShapeIsCheck = true;
  1401. InitCheckedEvent("RbtnTick");
  1402. IsEdit = false;
  1403. }
  1404. #endregion
  1405. }
  1406. }