FillAndSignContentViewModel.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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. namespace PDF_Office.ViewModels.FillAndSign
  38. {
  39. public class FillAndSignContentViewModel : BindableBase, INavigationAware
  40. {
  41. #region
  42. private CPDFViewer PDFViewer;
  43. private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
  44. private ViewContentViewModel viewContentViewModel;
  45. private bool isRightMenuAddAnnot = false;
  46. private IEventAggregator events;
  47. public List<List<Point>> ShapePoints = new List<List<Point>>();
  48. private string Shape = "HookShape";
  49. private PopMenu HightAnnotPopMenu;
  50. private PopMenu FreeHandAnnotPopMenu;
  51. private PopMenu FreeTextAnnotPopMenu;
  52. private PopMenu StrickNoteAnnotPopMenu;
  53. private PopMenu ShapeAnnotPopMenu;
  54. private PopMenu LinkAnnotPopMenu;
  55. private PopMenu StampAnnotPopMenu;
  56. private PopMenu MultiAnnotPopMenu;
  57. private IRegionManager regions { get; set; }
  58. private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
  59. public static bool IsEdit = false;
  60. public Brush SelectColor = new SolidColorBrush(Colors.GreenYellow);
  61. public double FillOpacity = 1;
  62. public double LineWidth = 1;
  63. #endregion
  64. #region Command
  65. public DelegateCommand<RoutedEventArgs> CheckCommand { get; set; }
  66. /// <summary>
  67. /// 按钮名称和属性面板映射字典
  68. /// </summary>
  69. public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
  70. #endregion
  71. public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events)
  72. {
  73. regions = regionManager;
  74. this.events = events;
  75. CheckCommand = new DelegateCommand<RoutedEventArgs>(CheckedEvent);
  76. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  77. InitDictionary();
  78. InitSelectFreeHandAnnotMenu();
  79. }
  80. private void CheckedEvent(RoutedEventArgs e)
  81. {
  82. IsEdit = false;
  83. var control = e.OriginalSource as Control;
  84. //NavigateToProperty(control.Name);
  85. //不创建注释,属于注释模板
  86. bool isTemplateAnnot = false;
  87. bool isSnapshotEdit = false;
  88. AnnotHandlerEventArgs annotArgs = null;
  89. var tag = control.Name;
  90. FindAnnotTypeKey(control.Name, ref annotArgs);
  91. if (control.Name == "RbtnSign") { isTemplateAnnot = true; }
  92. if (tag == "SnapshotEdit")
  93. {
  94. isSnapshotEdit = true;
  95. }
  96. else if (tag == "Signature" || tag == "Stamp")
  97. {
  98. isTemplateAnnot = true;
  99. }
  100. if (annotArgs != null)
  101. {
  102. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  103. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  104. PDFViewer.SetToolParam(annotArgs);
  105. isRightMenuAddAnnot = false;
  106. }
  107. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  108. if (isTemplateAnnot == false && annotArgs == null)
  109. {
  110. PDFViewer.SetMouseMode(MouseModes.PanTool);
  111. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  112. }
  113. else
  114. {
  115. if (isSnapshotEdit == true)
  116. {
  117. ShowPropertyPanel(false);
  118. isSnapshotEdit = false;
  119. }
  120. else
  121. {
  122. ShowPropertyPanel(true);
  123. }
  124. }
  125. }
  126. //注释工具
  127. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  128. {
  129. switch (tag)
  130. {
  131. case "RbtnDate":
  132. case "RbtnText"://文本
  133. annotArgs = GetFreetext();
  134. break;
  135. case "Freetext"://文本
  136. annotArgs = GetFreetext();
  137. break;
  138. case "RbtnSign"://签名
  139. annotArgs = GetSignature();
  140. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  141. break;
  142. case "RbtnTick"://勾
  143. Shape = "HookShape";
  144. 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) } };
  145. annotArgs = GetStamp();
  146. break;
  147. case "RbtnFork"://叉
  148. Shape = "ForkShape";
  149. 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) } };
  150. annotArgs = GetStamp();
  151. break;
  152. case "RbtnRectangle"://矩形
  153. Shape = "RectShape";
  154. ShapePoints = new List<List<Point>> { new List<Point> { new Point(0.19995, 5), new Point(28, 5), new Point(28, 27), new Point(0.19995, 27), new Point(0.19995, 5) } };
  155. annotArgs = GetStamp();
  156. break;
  157. case "RbtnLine"://下划线
  158. Shape = "LineShape";
  159. ShapePoints = new List<List<Point>> { new List<Point> { new Point(12.19995, 10), new Point(36, 10) } };
  160. annotArgs = GetStamp();
  161. break;
  162. case "RbtnPoint":
  163. Shape = "DotShape";
  164. ShapePoints = new List<List<Point>> { new List<Point> { new Point(0, 1), new Point(0, 0) }, new List<Point> { new Point(0.5, 0.86602), new Point(0, 0) }, new List<Point> { new Point(0.7071, 0.7071), new Point(0, 0) }, new List<Point> { new Point(0.86602, 0.5), new Point(0, 0) }, new List<Point> { new Point(1, 0), new Point(0, 0) }, new List<Point> { new Point(0.86602, -0.5), new Point(0, 0) }, new List<Point> { new Point(0.7071, -0.7071), new Point(0, 0) }, new List<Point> { new Point(0.5, -0.86602), new Point(0, 0) }, new List<Point> { new Point(0, -1), new Point(0, 0) }, new List<Point> { new Point(-0.5, 0.86602), new Point(0, 0) }, new List<Point> { new Point(-0.7071, 0.7071), new Point(0, 0) }, new List<Point> { new Point(-0.86602, 0.5), new Point(0, 0) }, new List<Point> { new Point(-1, 0), new Point(0, 0) }, new List<Point> { new Point(-0.86602, -0.5), new Point(0, 0) }, new List<Point> { new Point(-0.7071, -0.7071), new Point(0, 0) }, new List<Point> { new Point(-0.5, -0.86602), new Point(0, 0) } };
  165. annotArgs = GetStamp();
  166. break;
  167. default://图章
  168. break;
  169. }
  170. }
  171. /// <summary>
  172. /// 签名
  173. /// </summary>
  174. /// <returns></returns>
  175. private AnnotHandlerEventArgs GetSignature()
  176. {
  177. AddToPropertyPanel("SignatureAnnotProperty");
  178. return null;
  179. }
  180. /// <summary>
  181. /// 图章
  182. /// </summary>
  183. /// <returns></returns>
  184. private AnnotHandlerEventArgs GetStamp(List<AnnotHandlerEventArgs> selectedArgs = null)
  185. {
  186. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  187. stampAnnotArgs.SetInkData(ShapePoints, LineWidth, (SelectColor as SolidColorBrush).Color);
  188. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  189. //PDFViewer.SetToolParam(stampArgs);
  190. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  191. //stampAnnotArgs.Opacity = 1;
  192. //stampAnnotArgs.StampText = "APPROVED";
  193. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  194. // stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  195. stampAnnotArgs.IsContinueMode = true;
  196. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  197. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  198. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  199. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  200. if (stampAnnotArgs != null)
  201. stampAnnotArgsList.Add(stampAnnotArgs);
  202. //if (selectedArgs != null) {
  203. //var annot = selectedArgs[0];
  204. //if (annot != null)
  205. //{
  206. // foreach (var item in selectedArgs)
  207. // {
  208. // selectedArgs[selectedArgs.IndexOf(item)] = stampAnnotArgs;
  209. // }
  210. // AddToPropertyPanel("ShapFillProperty", "", selectedArgs, annotAttribsList);
  211. // return stampAnnotArgs;
  212. //}
  213. // }
  214. AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  215. return stampAnnotArgs;
  216. }
  217. public void SetStamp()
  218. {
  219. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  220. stampAnnotArgs.SetInkData(ShapePoints, LineWidth, (SelectColor as SolidColorBrush).Color);
  221. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  222. //PDFViewer.SetToolParam(stampArgs);
  223. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  224. //stampAnnotArgs.Opacity = 1;
  225. //stampAnnotArgs.StampText = "APPROVED";
  226. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  227. stampAnnotArgs.IsContinueMode = true;
  228. stampAnnotArgs.Opacity = FillOpacity;
  229. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  230. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  231. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  232. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  233. if (stampAnnotArgs != null)
  234. stampAnnotArgsList.Add(stampAnnotArgs);
  235. AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  236. bool isTemplateAnnot = false;
  237. bool isSnapshotEdit = false;
  238. AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
  239. if (annotArgs != null)
  240. {
  241. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  242. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  243. PDFViewer.SetToolParam(annotArgs);
  244. isRightMenuAddAnnot = false;
  245. }
  246. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  247. if (isTemplateAnnot == false && annotArgs == null)
  248. {
  249. PDFViewer.SetMouseMode(MouseModes.PanTool);
  250. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  251. }
  252. else
  253. {
  254. if (isSnapshotEdit == true)
  255. {
  256. ShowPropertyPanel(false);
  257. isSnapshotEdit = false;
  258. }
  259. else
  260. {
  261. ShowPropertyPanel(true);
  262. }
  263. }
  264. }
  265. /// <summary>
  266. /// 手绘
  267. /// </summary>
  268. /// <param name="selectedArgs"></param>
  269. /// <returns></returns>
  270. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  271. {
  272. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  273. List<AnnotHandlerEventArgs> newSelectedArgs= new List<AnnotHandlerEventArgs>();
  274. FreehandAnnotArgs freehandArgs = null;
  275. if (selectedArgs == null || selectedArgs.Count == 0)
  276. {
  277. freehandArgs = new FreehandAnnotArgs();
  278. var annotate = Settings.Default.AppProperties.Annotate;
  279. if (annotate != null)
  280. {
  281. freehandArgs.InkColor = annotate.FreeHandColor;
  282. }
  283. else
  284. {
  285. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  286. }
  287. freehandArgs.Transparency = 1;
  288. freehandArgs.LineWidth = 2;
  289. if (freehandArgs != null)
  290. {
  291. selectedArgs = new List<AnnotHandlerEventArgs>();
  292. selectedArgs.Add(freehandArgs);
  293. }
  294. }
  295. else
  296. {
  297. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  298. foreach (var item in selectedArgs)
  299. {
  300. //if (ListPoint((item as FreehandAnnotArgs).RawPointList, ShapePoints)){
  301. foreach (var point in viewContentViewModel.FillAndSign)
  302. {
  303. if ((item as FreehandAnnotArgs).PageIndex == point.X && (item as FreehandAnnotArgs).AnnotIndex == point.Y)
  304. {
  305. newSelectedArgs.Add(item);
  306. }
  307. }
  308. }
  309. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  310. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  311. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  312. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  313. AddToPropertyPanel("ShapFillProperty", "Freehand", newSelectedArgs, annotAttribsList);
  314. //GetStamp();
  315. return freehandArgs;
  316. }
  317. //annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  318. //annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  319. //annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  320. //annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  321. //AddToPropertyPanel("ShapFillProperty", "Freehand", selectedArgs, annotAttribsList);
  322. return freehandArgs;
  323. }
  324. private bool ListPoint(List<List<Point>> leftpoints, List<List<Point>> rightpoints)
  325. {
  326. if (leftpoints.Count == rightpoints.Count)
  327. {
  328. if (leftpoints[0][0].X == rightpoints[0][0].X) { return true; }
  329. }
  330. return false;
  331. }
  332. /// <summary>
  333. /// 文本
  334. /// </summary>
  335. /// <param name="selectedfreetextArgs"></param>
  336. /// <returns></returns>
  337. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  338. {
  339. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  340. FreeTextAnnotArgs freetextArgs = null;
  341. TextAlignment textAlignment;
  342. if (selectedArgs == null || selectedArgs.Count == 0)
  343. {
  344. freetextArgs = new FreeTextAnnotArgs();
  345. freetextArgs.Align = TextAlignment.Left;
  346. freetextArgs.BgColor = Colors.Transparent;
  347. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  348. freetextArgs.FontColor = Colors.Black;
  349. freetextArgs.FontSize = 14;
  350. freetextArgs.Transparency = 1;
  351. freetextArgs.LineColor = Colors.Black;
  352. freetextArgs.LineWidth = 0;
  353. freetextArgs.TextContent = string.Empty;
  354. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  355. if (annotProperty != null)
  356. {
  357. freetextArgs.Align = annotProperty.TextAlign;
  358. freetextArgs.BgColor = annotProperty.BackgroundColor;
  359. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  360. freetextArgs.FontColor = annotProperty.ForgoundColor;
  361. freetextArgs.FontSize = annotProperty.FontSize;
  362. freetextArgs.Transparency = annotProperty.Opacity;
  363. freetextArgs.LineColor = annotProperty.BorderColor;
  364. freetextArgs.LineWidth = annotProperty.Thickness;
  365. freetextArgs.TextContent = annotProperty.NoteText;
  366. freetextArgs.FontWeight = annotProperty.FontWeight;
  367. freetextArgs.FontStyle = annotProperty.FontStyle;
  368. }
  369. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  370. if (align == 0)
  371. textAlignment = TextAlignment.Left;
  372. else if (align == 1)
  373. textAlignment = TextAlignment.Center;
  374. else
  375. textAlignment = TextAlignment.Right;
  376. if (freetextArgs != null)
  377. {
  378. selectedArgs = new List<AnnotHandlerEventArgs>();
  379. selectedArgs.Add(freetextArgs);
  380. }
  381. }
  382. else
  383. {
  384. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  385. textAlignment = freetextArgs.Align;
  386. }
  387. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  388. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  389. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  390. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  391. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  392. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  393. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  394. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  395. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  396. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  397. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  398. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
  399. return freetextArgs;
  400. }
  401. /// <summary>
  402. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  403. /// </summary>
  404. /// <param name="viewContent">对应的注释面板</param>
  405. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  406. /// <param name="annot">注释</param>
  407. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  408. private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
  409. {
  410. if (annots != null&& annots.Count!=0)
  411. {
  412. propertyPanel.annotlists = annots;
  413. propertyPanel.annot = annots[0];
  414. }
  415. else
  416. {
  417. propertyPanel.annotlists = null;
  418. propertyPanel.annot = null;
  419. return;
  420. }
  421. if (annotAttribsList != null && annotAttribsList.Count != 0)
  422. {
  423. if (annots.Count > 1)
  424. {
  425. if (propertyPanel.AnnotEvents == null)
  426. propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
  427. propertyPanel.AnnotEvents.Clear();
  428. foreach (var itemAnnot in annots)
  429. {
  430. var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
  431. propertyPanel.AnnotEvents.Add(eventitem);
  432. }
  433. }
  434. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
  435. if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
  436. {
  437. propertyPanel.AnnotEvent = annotAttribEvent;
  438. }
  439. }
  440. if (string.IsNullOrEmpty(viewContent) == false)
  441. {
  442. if (isUpData) { return; }
  443. if (viewContent == "ShapFillProperty") { NavigateToProperty(viewContent, propertyPanel); return; }
  444. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  445. }
  446. }
  447. private void NavigateToProperty(string btnName, AnnotPropertyPanel annotPropertyPanel)
  448. {
  449. NavigationParameters values = new NavigationParameters();
  450. values.Add(ParameterNames.PDFViewer, PDFViewer);
  451. values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  452. values.Add("Shape", Shape);
  453. values.Add("FillAndSignContentViewModel", this);
  454. regions.RequestNavigate(RegionNames.PropertyRegionName, btnName, values);
  455. viewContentViewModel.IsPropertyOpen = true;
  456. }
  457. /// <summary>
  458. /// 初始化按钮名称-属性面板字典
  459. /// </summary>
  460. private void InitDictionary()
  461. {
  462. btnToProperty["RbtnText"] = "TextFillProperty";
  463. btnToProperty["RbtnTick"] = "ShapFillProperty";
  464. btnToProperty["RbtnFork"] = "ShapFillProperty";
  465. btnToProperty["RbtnRectangle"] = "ShapFillProperty";
  466. btnToProperty["RbtnLine"] = "ShapFillProperty";
  467. btnToProperty["RbtnPoint"] = "ShapFillProperty";
  468. btnToProperty["RbtnDate"] = "DateFillProperty";
  469. btnToProperty["RbtnSign"] = "";
  470. }
  471. /// <summary>
  472. /// 手绘
  473. /// </summary>
  474. private void InitSelectFreeHandAnnotMenu()
  475. {
  476. var popMenu = new ContextMenu();
  477. PopMenu pop = new PopMenu(popMenu);
  478. var menuItem = new MenuItem();
  479. menuItem.Name = "FreeHandCopy";
  480. menuItem.Header = "复制";
  481. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  482. menuItem = new MenuItem();
  483. menuItem.Name = "FreeHandCut";
  484. menuItem.Header = "剪切";
  485. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  486. menuItem = new MenuItem();
  487. menuItem.Name = "FreeHandPaste";
  488. menuItem.Header = "粘贴";
  489. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  490. menuItem = new MenuItem();
  491. menuItem.Name = "FreeHandDelete";
  492. menuItem.Header = "删除";
  493. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  494. pop.AddItem(GetSeparator());
  495. FreeHandAnnotPopMenu = pop;
  496. }
  497. private Separator GetSeparator()
  498. {
  499. Separator separator = new Separator();
  500. separator.Height = 1;
  501. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  502. separator.BorderThickness = new Thickness(1);
  503. return separator;
  504. }
  505. private void BindingPDFViewerHandler()
  506. {
  507. //来自PDFViewer的响应事件
  508. if (PDFViewer != null)
  509. {
  510. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  511. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  512. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  513. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  514. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  515. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  516. }
  517. }
  518. private void UnBindingPDFViewerHandler()
  519. {
  520. if (PDFViewer != null)
  521. {
  522. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  523. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  524. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  525. }
  526. }
  527. //在注释工具的状态下,右键菜单
  528. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  529. {
  530. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  531. return;
  532. switch (e.CommandType)
  533. {
  534. case CommandType.Context:
  535. if (e.AnnotEventArgsList.Count > 0)
  536. {
  537. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  538. {
  539. //绑定标记密文处右键菜单
  540. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  541. }
  542. else
  543. {
  544. if (e.AnnotEventArgsList.Count == 1)
  545. {
  546. var selectedAnnot = e.AnnotEventArgsList[0];
  547. switch (selectedAnnot.EventType)
  548. {
  549. case AnnotArgsType.AnnotFreehand:
  550. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  551. break;
  552. }
  553. }
  554. else
  555. {
  556. bool isHigh = true;//是否为高亮
  557. foreach (var item in e.AnnotEventArgsList)
  558. {
  559. if (isHightAnnot(item) == false)
  560. {
  561. isHigh = false;
  562. break;
  563. }
  564. }
  565. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  566. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  567. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  568. }
  569. }
  570. if (e.PopupMenu != null)
  571. {
  572. e.Handle = true;
  573. }
  574. }
  575. else
  576. {
  577. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  578. {
  579. if (e.PopupMenu != null)
  580. {
  581. e.Handle = true;
  582. }
  583. }
  584. else
  585. {
  586. if (e.PopupMenu != null)
  587. {
  588. e.Handle = true;
  589. }
  590. }
  591. }
  592. break;
  593. }
  594. }
  595. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  596. {
  597. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  598. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  599. annot.EventType == AnnotArgsType.AnnotHighlight ||
  600. annot.EventType == AnnotArgsType.AnnotStrikeout
  601. )
  602. {
  603. return true;
  604. }
  605. else
  606. {
  607. return false;
  608. }
  609. }
  610. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  611. {
  612. if (e != null && e.Count > 0)
  613. {
  614. for (int i = 0; i < e.Count; i++)
  615. {
  616. AnnotEditEvent editEvent = e[i];
  617. switch (editEvent.EditAction)
  618. {
  619. case ActionType.Add:
  620. int pageindex = editEvent.PageIndex;
  621. int annotindex = editEvent.AnnotIndex;
  622. viewContentViewModel.FillAndSign.Add(new Point(pageindex, annotindex));
  623. break;
  624. }
  625. }
  626. }
  627. }
  628. //选中和非选中注释,右键菜单
  629. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  630. {
  631. if (e != null)
  632. {
  633. var annot = e.AnnotItemsList[0];
  634. if (annot != null)
  635. {
  636. if (e.AnnotItemsList.Count == 1)
  637. {
  638. //IsEdit = false;
  639. //IsAnnotCreateReset:是否为创建注释的状态
  640. if (e.IsAnnotCreateReset == false)
  641. {
  642. GetSelectedAnnots(e);
  643. //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
  644. //PDFViewer.SetToolParam(annot);
  645. }
  646. else
  647. {
  648. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  649. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  650. annot.EventType != AnnotArgsType.AnnotUnderline &&
  651. annot.EventType != AnnotArgsType.AnnotHighlight &&
  652. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  653. annot.EventType != AnnotArgsType.AnnotLink &&
  654. annot.EventType != AnnotArgsType.AnnotFreehand &&
  655. annot.EventType != AnnotArgsType.AnnotSticky
  656. )
  657. {
  658. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  659. {
  660. foreach (var item in ToolExpandDict)
  661. {
  662. if (item.Value == e.AnnotItemsList[0].EventType)
  663. {
  664. annot = null;//新建注释时,回到默认值
  665. FindAnnotTypeKey(item.Key, ref annot);
  666. break;
  667. }
  668. }
  669. }
  670. }
  671. //else
  672. //PDFViewer.SetToolParam(annot);
  673. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  674. if (isRightMenuAddAnnot)
  675. {
  676. ShowPropertyPanel(false);
  677. }
  678. else
  679. {
  680. ShowPropertyPanel();
  681. }
  682. }
  683. }
  684. else
  685. {
  686. bool isDifferentAnnotTyle = false;
  687. var lastAnnot = annot;
  688. foreach (var item in e.AnnotItemsList)
  689. {
  690. if (lastAnnot.EventType != item.EventType)
  691. {
  692. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  693. {
  694. lastAnnot = item;
  695. continue;
  696. }
  697. lastAnnot = item;
  698. isDifferentAnnotTyle = true;
  699. break;
  700. }
  701. }
  702. if (isDifferentAnnotTyle)
  703. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  704. else
  705. GetSelectedAnnots(e);
  706. }
  707. }
  708. }
  709. else
  710. {
  711. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  712. }
  713. }
  714. //private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  715. //{
  716. // if (e != null && e.Count > 0)
  717. // {
  718. // for (int i = 0; i < e.Count; i++)
  719. // {
  720. // AnnotEditEvent editEvent = e[i];
  721. // switch (editEvent.EditAction)
  722. // {
  723. // case ActionType.Add:
  724. // // bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  725. // if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  726. // {
  727. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  728. // if (viewModel != null)
  729. // {
  730. // int pageindex = editEvent.PageIndex;
  731. // int annotindex = editEvent.AnnotIndex;
  732. // viewModel.UpdateAddedAnnot(pageindex, annotindex);
  733. // }
  734. // }
  735. // break;
  736. // case ActionType.Del:
  737. // //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  738. // if (isTabItemAnnotation)
  739. // {
  740. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  741. // if (viewModel != null)
  742. // {
  743. // int pageindex = editEvent.PageIndex;
  744. // int annotindex = editEvent.AnnotIndex;
  745. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  746. // }
  747. // }
  748. // break;
  749. // case ActionType.Modify:
  750. // isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  751. // if (bOTAContent.TabItemAnnotation.IsSelected)
  752. // {
  753. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  754. // if (viewModel != null)
  755. // {
  756. // int pageindex = editEvent.PageIndex;
  757. // int annotindex = editEvent.AnnotIndex;
  758. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  759. // }
  760. // }
  761. // break;
  762. // case ActionType.TextEdit:
  763. // break;
  764. // default:
  765. // break;
  766. // }
  767. // }
  768. // }
  769. //}
  770. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  771. {
  772. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  773. annot.EventType == AnnotArgsType.AnnotSquare ||
  774. annot.EventType == AnnotArgsType.AnnotLine
  775. )
  776. {
  777. return true;
  778. }
  779. else
  780. {
  781. return false;
  782. }
  783. }
  784. private void GetSelectedAnnots(AnnotAttribEvent e)
  785. {
  786. IsEdit = true;
  787. var annot = e.AnnotItemsList[0];
  788. switch (annot.EventType)
  789. {
  790. case AnnotArgsType.AnnotFreehand:
  791. GetFreehand(e.AnnotItemsList);
  792. break;
  793. }
  794. }
  795. private void ShowPropertyPanel(bool show = true)
  796. {
  797. viewContentViewModel.IsPropertyOpen = show;
  798. }
  799. #region Navigation
  800. public bool IsNavigationTarget(NavigationContext navigationContext)
  801. {
  802. return true;
  803. }
  804. public void OnNavigatedFrom(NavigationContext navigationContext)
  805. {
  806. UnBindingPDFViewerHandler();
  807. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  808. }
  809. public void OnNavigatedTo(NavigationContext navigationContext)
  810. {
  811. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  812. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  813. BindingPDFViewerHandler();
  814. IsEdit = false;
  815. }
  816. #endregion
  817. }
  818. }