FillAndSignContentViewModel.cs 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  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. namespace PDF_Office.ViewModels.FillAndSign
  46. {
  47. public class FillAndSignContentViewModel : BindableBase, INavigationAware
  48. {
  49. #region
  50. private CPDFViewer PDFViewer;
  51. private AnnotPropertyPanel propertyPanel = new AnnotPropertyPanel();
  52. private ViewContentViewModel viewContentViewModel;
  53. private bool isRightMenuAddAnnot = false;
  54. private IEventAggregator events;
  55. public List<List<Point>> ShapePoints = new List<List<Point>>();
  56. private string Shape = "HookShape";
  57. private PopMenu FreeHandAnnotPopMenu;
  58. private PopMenu MultiAnnotPopMenu;
  59. private IRegionManager regions { get; set; }
  60. private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
  61. public static bool IsEdit = false;
  62. public static bool IsSignPoint=false;
  63. public Brush SelectColor = new SolidColorBrush(Colors.GreenYellow);
  64. public double FillOpacity = 1;
  65. public double LineWidth = 1;
  66. public double LineWidthMultiple = 1;
  67. private bool _HookShapeIsCheck=true;
  68. public bool HookShapeIsCheck {
  69. get { return _HookShapeIsCheck; }
  70. set { SetProperty(ref _HookShapeIsCheck,value); }
  71. }
  72. #endregion
  73. public DelegateCommand<object> AnnotDefaultValue_MenuCommand { get; set; }
  74. #region Command
  75. public DelegateCommand<RoutedEventArgs> CheckCommand { get; set; }
  76. /// <summary>
  77. /// 按钮名称和属性面板映射字典
  78. /// </summary>
  79. public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
  80. #endregion
  81. public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events)
  82. {
  83. regions = regionManager;
  84. this.events = events;
  85. CheckCommand = new DelegateCommand<RoutedEventArgs>(CheckedEvent);
  86. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  87. InitDictionary();
  88. AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
  89. InitSelectFreeHandAnnotMenu();
  90. }
  91. private void AnnotDefaultValues_Menu(object e){}
  92. private void CheckedEvent(RoutedEventArgs e)
  93. {
  94. IsEdit = false;
  95. var control = e.OriginalSource as Control;
  96. //NavigateToProperty(control.Name);
  97. //不创建注释,属于注释模板
  98. bool isTemplateAnnot = false;
  99. bool isSnapshotEdit = false;
  100. AnnotHandlerEventArgs annotArgs = null;
  101. var tag = control.Name;
  102. FindAnnotTypeKey(control.Name, ref annotArgs);
  103. if (control.Name == "RbtnSign") { isTemplateAnnot = true; }
  104. if (tag == "SnapshotEdit")
  105. {
  106. isSnapshotEdit = true;
  107. }
  108. else if (tag == "Signature" || tag == "Stamp")
  109. {
  110. isTemplateAnnot = true;
  111. }
  112. if (annotArgs != null)
  113. {
  114. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  115. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  116. PDFViewer.SetToolParam(annotArgs);
  117. isRightMenuAddAnnot = false;
  118. }
  119. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  120. if (isTemplateAnnot == false && annotArgs == null)
  121. {
  122. PDFViewer.SetMouseMode(MouseModes.PanTool);
  123. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  124. }
  125. else
  126. {
  127. if (isSnapshotEdit == true)
  128. {
  129. ShowPropertyPanel(false);
  130. isSnapshotEdit = false;
  131. }
  132. else
  133. {
  134. ShowPropertyPanel(true);
  135. }
  136. }
  137. }
  138. private void InitCheckedEvent(string e)
  139. {
  140. IsEdit = false;
  141. //NavigateToProperty(control.Name);
  142. //不创建注释,属于注释模板
  143. bool isTemplateAnnot = false;
  144. bool isSnapshotEdit = false;
  145. AnnotHandlerEventArgs annotArgs = null;
  146. var tag = e;
  147. FindAnnotTypeKey(e, ref annotArgs);
  148. if (e == "RbtnSign") { isTemplateAnnot = true; }
  149. if (tag == "SnapshotEdit")
  150. {
  151. isSnapshotEdit = true;
  152. }
  153. else if (tag == "Signature" || tag == "Stamp")
  154. {
  155. isTemplateAnnot = true;
  156. }
  157. if (annotArgs != null)
  158. {
  159. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  160. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  161. PDFViewer.SetToolParam(annotArgs);
  162. isRightMenuAddAnnot = false;
  163. }
  164. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  165. if (isTemplateAnnot == false && annotArgs == null)
  166. {
  167. PDFViewer.SetMouseMode(MouseModes.PanTool);
  168. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  169. }
  170. else
  171. {
  172. if (isSnapshotEdit == true)
  173. {
  174. ShowPropertyPanel(false);
  175. isSnapshotEdit = false;
  176. }
  177. else
  178. {
  179. ShowPropertyPanel(true);
  180. }
  181. }
  182. }
  183. //注释工具
  184. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  185. {
  186. LineWidthMultiple = 1;
  187. IsSignPoint=false;
  188. switch (tag)
  189. {
  190. case "RbtnDate":
  191. case "RbtnText"://文本
  192. annotArgs = GetFreetext();
  193. break;
  194. case "Freetext"://文本
  195. annotArgs = GetFreetext();
  196. break;
  197. case "RbtnSign"://签名
  198. annotArgs = GetSignature();
  199. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  200. break;
  201. case "RbtnTick"://勾
  202. Shape = "HookShape";
  203. 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) } };
  204. annotArgs = GetStamp();
  205. break;
  206. case "RbtnFork"://叉
  207. Shape = "ForkShape";
  208. 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) } };
  209. annotArgs = GetStamp();
  210. break;
  211. case "RbtnRectangle"://矩形
  212. Shape = "RectShape";
  213. 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)} };
  214. annotArgs = GetStamp();
  215. break;
  216. case "RbtnLine"://下划线
  217. Shape = "LineShape";
  218. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(28, 3.20001) } };
  219. annotArgs = GetStamp();
  220. break;
  221. case "RbtnPoint":
  222. IsSignPoint = true;
  223. Shape = "DotShape";
  224. ShapePoints = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.19995), new Point(3.19995, 3.19995) } };
  225. LineWidthMultiple = 5;
  226. annotArgs = GetStamp();
  227. break;
  228. default://图章
  229. break;
  230. }
  231. }
  232. /// <summary>
  233. /// 签名
  234. /// </summary>
  235. /// <returns></returns>
  236. private AnnotHandlerEventArgs GetSignature()
  237. {
  238. AddToPropertyPanel("SignatureAnnotProperty");
  239. return null;
  240. }
  241. /// <summary>
  242. /// 图章
  243. /// </summary>
  244. /// <returns></returns>
  245. private AnnotHandlerEventArgs GetStamp(List<AnnotHandlerEventArgs> selectedArgs = null)
  246. {
  247. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  248. stampAnnotArgs.SetInkData(ShapePoints, LineWidth* LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  249. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  250. //PDFViewer.SetToolParam(stampArgs);
  251. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  252. //stampAnnotArgs.Opacity = 1;
  253. //stampAnnotArgs.StampText = "APPROVED";
  254. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  255. // stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  256. stampAnnotArgs.IsContinueMode = true;
  257. stampAnnotArgs.IsSignPoint = IsSignPoint;
  258. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  259. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  260. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  261. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  262. if (stampAnnotArgs != null)
  263. stampAnnotArgsList.Add(stampAnnotArgs);
  264. //if (selectedArgs != null) {
  265. //var annot = selectedArgs[0];
  266. //if (annot != null)
  267. //{
  268. // foreach (var item in selectedArgs)
  269. // {
  270. // selectedArgs[selectedArgs.IndexOf(item)] = stampAnnotArgs;
  271. // }
  272. // AddToPropertyPanel("ShapFillProperty", "", selectedArgs, annotAttribsList);
  273. // return stampAnnotArgs;
  274. //}
  275. // }
  276. AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  277. return stampAnnotArgs;
  278. }
  279. public void SetStamp()
  280. {
  281. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  282. stampAnnotArgs.SetInkData(ShapePoints, LineWidth* LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  283. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  284. //PDFViewer.SetToolParam(stampArgs);
  285. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  286. //stampAnnotArgs.Opacity = 1;
  287. //stampAnnotArgs.StampText = "APPROVED";
  288. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  289. stampAnnotArgs.IsContinueMode = true;
  290. stampAnnotArgs.IsSignPoint = IsSignPoint;
  291. stampAnnotArgs.Opacity = FillOpacity;
  292. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  293. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  294. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  295. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  296. if (stampAnnotArgs != null)
  297. stampAnnotArgsList.Add(stampAnnotArgs);
  298. AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  299. bool isTemplateAnnot = false;
  300. bool isSnapshotEdit = false;
  301. AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
  302. if (annotArgs != null)
  303. {
  304. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  305. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  306. PDFViewer.SetToolParam(annotArgs);
  307. isRightMenuAddAnnot = false;
  308. }
  309. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  310. if (isTemplateAnnot == false && annotArgs == null)
  311. {
  312. PDFViewer.SetMouseMode(MouseModes.PanTool);
  313. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  314. }
  315. else
  316. {
  317. if (isSnapshotEdit == true)
  318. {
  319. ShowPropertyPanel(false);
  320. isSnapshotEdit = false;
  321. }
  322. else
  323. {
  324. ShowPropertyPanel(true);
  325. }
  326. }
  327. }
  328. /// <summary>
  329. /// 手绘
  330. /// </summary>
  331. /// <param name="selectedArgs"></param>
  332. /// <returns></returns>
  333. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  334. {
  335. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  336. List<AnnotHandlerEventArgs> newSelectedArgs= new List<AnnotHandlerEventArgs>();
  337. FreehandAnnotArgs freehandArgs = null;
  338. if (selectedArgs == null || selectedArgs.Count == 0)
  339. {
  340. freehandArgs = new FreehandAnnotArgs();
  341. var annotate = Settings.Default.AppProperties.Annotate;
  342. if (annotate != null)
  343. {
  344. freehandArgs.InkColor = annotate.FreeHandColor;
  345. }
  346. else
  347. {
  348. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  349. }
  350. 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) } };
  351. freehandArgs.Transparency = 1;
  352. freehandArgs.LineWidth = 2;
  353. if (freehandArgs != null)
  354. {
  355. selectedArgs = new List<AnnotHandlerEventArgs>();
  356. selectedArgs.Add(freehandArgs);
  357. }
  358. }
  359. else
  360. {
  361. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  362. foreach (var item in selectedArgs)
  363. {
  364. //if (ListPoint((item as FreehandAnnotArgs).RawPointList, ShapePoints)){
  365. foreach (var point in viewContentViewModel.FillAndSign)
  366. {
  367. if ((item as FreehandAnnotArgs).PageIndex == point.X && (item as FreehandAnnotArgs).AnnotIndex == point.Y)
  368. {
  369. newSelectedArgs.Add(item);
  370. }
  371. }
  372. }
  373. freehandArgs.RawPointList = ShapePoints;
  374. freehandArgs.InkColor = (SelectColor as SolidColorBrush).Color;
  375. freehandArgs.Transparency = 1;
  376. freehandArgs.LineWidth = LineWidth;
  377. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  378. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  379. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  380. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  381. annotAttribsList[AnnotAttrib.Path]= freehandArgs.RawPointList;
  382. annotAttribsList[AnnotAttrib.Width] = freehandArgs.Width;
  383. annotAttribsList[AnnotAttrib.Height] = freehandArgs.Height;
  384. AddToPropertyPanel("ShapFillProperty", "Freehand", newSelectedArgs, annotAttribsList);
  385. //GetStamp();
  386. return freehandArgs;
  387. }
  388. //annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  389. //annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  390. //annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  391. //annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  392. //AddToPropertyPanel("ShapFillProperty", "Freehand", selectedArgs, annotAttribsList);
  393. return freehandArgs;
  394. }
  395. private bool ListPoint(List<List<Point>> leftpoints, List<List<Point>> rightpoints)
  396. {
  397. if (leftpoints.Count == rightpoints.Count)
  398. {
  399. if (leftpoints[0][0].X == rightpoints[0][0].X) { return true; }
  400. }
  401. return false;
  402. }
  403. /// <summary>
  404. /// 文本
  405. /// </summary>
  406. /// <param name="selectedfreetextArgs"></param>
  407. /// <returns></returns>
  408. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  409. {
  410. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  411. FreeTextAnnotArgs freetextArgs = null;
  412. TextAlignment textAlignment;
  413. if (selectedArgs == null || selectedArgs.Count == 0)
  414. {
  415. freetextArgs = new FreeTextAnnotArgs();
  416. freetextArgs.Align = TextAlignment.Left;
  417. freetextArgs.BgColor = Colors.Transparent;
  418. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  419. freetextArgs.FontColor = Colors.Black;
  420. freetextArgs.FontSize = 14;
  421. freetextArgs.Transparency = 1;
  422. freetextArgs.LineColor = Colors.Black;
  423. freetextArgs.LineWidth = 0;
  424. freetextArgs.TextContent = string.Empty;
  425. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  426. if (annotProperty != null)
  427. {
  428. freetextArgs.Align = annotProperty.TextAlign;
  429. freetextArgs.BgColor = annotProperty.BackgroundColor;
  430. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  431. freetextArgs.FontColor = annotProperty.ForgoundColor;
  432. freetextArgs.FontSize = annotProperty.FontSize;
  433. freetextArgs.Transparency = annotProperty.Opacity;
  434. freetextArgs.LineColor = annotProperty.BorderColor;
  435. freetextArgs.LineWidth = annotProperty.Thickness;
  436. freetextArgs.TextContent = annotProperty.NoteText;
  437. freetextArgs.FontWeight = annotProperty.FontWeight;
  438. freetextArgs.FontStyle = annotProperty.FontStyle;
  439. }
  440. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  441. if (align == 0)
  442. textAlignment = TextAlignment.Left;
  443. else if (align == 1)
  444. textAlignment = TextAlignment.Center;
  445. else
  446. textAlignment = TextAlignment.Right;
  447. if (freetextArgs != null)
  448. {
  449. selectedArgs = new List<AnnotHandlerEventArgs>();
  450. selectedArgs.Add(freetextArgs);
  451. }
  452. }
  453. else
  454. {
  455. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  456. textAlignment = freetextArgs.Align;
  457. }
  458. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  459. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  460. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  461. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  462. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  463. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  464. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  465. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  466. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  467. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  468. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  469. annotAttribsList[AnnotAttrib.Text] = freetextArgs.TextContent;
  470. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
  471. return freetextArgs;
  472. }
  473. /// <summary>
  474. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  475. /// </summary>
  476. /// <param name="viewContent">对应的注释面板</param>
  477. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  478. /// <param name="annot">注释</param>
  479. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  480. private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
  481. {
  482. if (annots != null&& annots.Count!=0)
  483. {
  484. propertyPanel.annotlists = annots;
  485. propertyPanel.annot = annots[0];
  486. }
  487. else
  488. {
  489. propertyPanel.annotlists = null;
  490. propertyPanel.annot = null;
  491. }
  492. if (annotAttribsList != null && annotAttribsList.Count != 0&&annots != null && annots.Count != 0)
  493. {
  494. if (annots.Count > 1)
  495. {
  496. if (propertyPanel.AnnotEvents == null)
  497. propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
  498. propertyPanel.AnnotEvents.Clear();
  499. foreach (var itemAnnot in annots)
  500. {
  501. var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
  502. propertyPanel.AnnotEvents.Add(eventitem);
  503. }
  504. }
  505. propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
  506. if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
  507. {
  508. propertyPanel.AnnotEvent = annotAttribEvent;
  509. }
  510. }
  511. if (toolTag == "Freetext")
  512. {
  513. propertyPanel.SetIsTextFill(true);
  514. }
  515. else
  516. {
  517. propertyPanel.SetIsTextFill(false);
  518. }
  519. if (string.IsNullOrEmpty(viewContent) == false)
  520. {
  521. if (isUpData) { return; }
  522. if (viewContent == "ShapFillProperty") { NavigateToProperty(viewContent, propertyPanel); return; }
  523. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  524. }
  525. }
  526. private void NavigateToProperty(string btnName, AnnotPropertyPanel annotPropertyPanel)
  527. {
  528. NavigationParameters values = new NavigationParameters();
  529. values.Add(ParameterNames.PDFViewer, PDFViewer);
  530. values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  531. values.Add("Shape", Shape);
  532. values.Add("FillAndSignContentViewModel", this);
  533. regions.RequestNavigate(RegionNames.PropertyRegionName, btnName, values);
  534. viewContentViewModel.IsPropertyOpen = true;
  535. }
  536. /// <summary>
  537. /// 初始化按钮名称-属性面板字典
  538. /// </summary>
  539. private void InitDictionary()
  540. {
  541. btnToProperty["RbtnText"] = "TextFillProperty";
  542. btnToProperty["RbtnTick"] = "ShapFillProperty";
  543. btnToProperty["RbtnFork"] = "ShapFillProperty";
  544. btnToProperty["RbtnRectangle"] = "ShapFillProperty";
  545. btnToProperty["RbtnLine"] = "ShapFillProperty";
  546. btnToProperty["RbtnPoint"] = "ShapFillProperty";
  547. btnToProperty["RbtnDate"] = "DateFillProperty";
  548. btnToProperty["RbtnSign"] = "";
  549. }
  550. /// <summary>
  551. /// 手绘
  552. /// </summary>
  553. private void InitSelectFreeHandAnnotMenu()
  554. {
  555. var popMenu = new ContextMenu();
  556. PopMenu pop = new PopMenu(popMenu);
  557. var menuItem = new MenuItem();
  558. menuItem.Name = "FreeHandCopy";
  559. menuItem.Header = "复制";
  560. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  561. menuItem = new MenuItem();
  562. menuItem.Name = "FreeHandCut";
  563. menuItem.Header = "剪切";
  564. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  565. menuItem = new MenuItem();
  566. menuItem.Name = "FreeHandPaste";
  567. menuItem.Header = "粘贴";
  568. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  569. menuItem = new MenuItem();
  570. menuItem.Name = "FreeHandDelete";
  571. menuItem.Header = "删除";
  572. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  573. pop.AddItem(GetSeparator());
  574. menuItem = new MenuItem();
  575. menuItem.Name = "FreeHandDefault";
  576. menuItem.Header = "设置当前属性为默认值";
  577. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  578. FreeHandAnnotPopMenu = pop;
  579. }
  580. private Separator GetSeparator()
  581. {
  582. Separator separator = new Separator();
  583. separator.Height = 1;
  584. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  585. separator.BorderThickness = new Thickness(1);
  586. return separator;
  587. }
  588. private void BindingPDFViewerHandler()
  589. {
  590. //来自PDFViewer的响应事件
  591. if (PDFViewer != null)
  592. {
  593. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  594. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  595. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  596. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  597. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  598. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  599. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  600. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  601. }
  602. }
  603. private void UnBindingPDFViewerHandler()
  604. {
  605. if (PDFViewer != null)
  606. {
  607. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  608. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  609. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  610. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  611. }
  612. }
  613. //在注释工具的状态下,右键菜单
  614. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  615. {
  616. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  617. return;
  618. switch (e.CommandType)
  619. {
  620. case CommandType.Context:
  621. if (e.AnnotEventArgsList.Count > 0)
  622. {
  623. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  624. {
  625. //绑定标记密文处右键菜单
  626. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  627. }
  628. else
  629. {
  630. if (e.AnnotEventArgsList.Count == 1)
  631. {
  632. var selectedAnnot = e.AnnotEventArgsList[0];
  633. switch (selectedAnnot.EventType)
  634. {
  635. case AnnotArgsType.AnnotFreehand:
  636. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  637. break;
  638. }
  639. }
  640. else
  641. {
  642. bool isHigh = true;//是否为高亮
  643. foreach (var item in e.AnnotEventArgsList)
  644. {
  645. if (isHightAnnot(item) == false)
  646. {
  647. isHigh = false;
  648. break;
  649. }
  650. }
  651. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  652. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  653. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  654. }
  655. }
  656. if (e.PopupMenu != null)
  657. {
  658. e.Handle = true;
  659. }
  660. }
  661. else
  662. {
  663. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  664. {
  665. if (e.PopupMenu != null)
  666. {
  667. e.Handle = true;
  668. }
  669. }
  670. else
  671. {
  672. e.PopupMenu = ViewerContextMenu(sender);
  673. if (e.PopupMenu != null)
  674. {
  675. e.Handle = true;
  676. }
  677. }
  678. }
  679. break;
  680. }
  681. }
  682. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  683. {
  684. if (e != null && e.DrawContext != null)
  685. {
  686. Rect hoverRect = new Rect(
  687. e.PaintRect.Left - 2,
  688. e.PaintRect.Top - 2,
  689. e.PaintRect.Width + 4,
  690. e.PaintRect.Height + 4);
  691. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  692. hoverPen.DashStyle = DashStyles.Dash;
  693. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  694. //Todo:目前ComPDFKit.Viewer没有e.Annot参数
  695. //便签,显示ToolTip内容
  696. //if (e.Annot != null && e.Annot.Type == C_ANNOTATION_TYPE.C_ANNOTATION_TEXT)
  697. //{
  698. // if (PDFViewer.ToolTip == null)
  699. // {
  700. // var content = e.Annot.GetContent();
  701. // if (string.IsNullOrEmpty(content) == false)
  702. // {
  703. // ToolTip TipChild = new ToolTip();
  704. // TipChild.Style = App.Current.Resources["FlowToolTip"] as Style;
  705. // TipChild.MaxWidth = 246;
  706. // TipChild.Content = content;
  707. // TipChild.Visibility = Visibility.Visible;
  708. // TipChild.IsOpen = true;
  709. // TipChild.Placement = PlacementMode.Right;
  710. // var rec = e.Annot.GetRect();
  711. // TipChild.PlacementRectangle = new Rect(rec.left, rec.top, rec.right, rec.bottom);
  712. // TipChild.PlacementTarget = PDFViewer.Parent as ContentControl;
  713. // TipChild.Placement = PlacementMode.MousePoint;
  714. // PDFViewer.ToolTip = TipChild;
  715. // oldRect = hoverRect;
  716. // PDFViewer.MouseMove -= PDFViewer_MouseMove;
  717. // PDFViewer.MouseMove += PDFViewer_MouseMove;
  718. // return;
  719. // }
  720. // }
  721. //}
  722. }
  723. CloseAnnotToolTip();
  724. }
  725. private Rect oldRect = new Rect(0, 0, 0, 0);
  726. private void CloseAnnotToolTip()
  727. {
  728. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  729. {
  730. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  731. oldTips.IsOpen = false;
  732. oldTips.Visibility = Visibility.Collapsed;
  733. PDFViewer.ToolTip = null;
  734. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  735. oldRect = new Rect(0, 0, 0, 0);
  736. }
  737. }
  738. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  739. {
  740. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  741. {
  742. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  743. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  744. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  745. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  746. {
  747. CloseAnnotToolTip();
  748. }
  749. }
  750. }
  751. private ContextMenu ViewerContextMenu(object sender)
  752. {
  753. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  754. ViewerContextMenu_Loaded(contextMenu,sender);
  755. return contextMenu;
  756. }
  757. private void ViewerContextMenu_Loaded(object sender,object e,Visibility visibility =Visibility.Collapsed)
  758. {
  759. ContextMenu contextMenu = sender as ContextMenu;
  760. if (contextMenu.Items.Count > 0)
  761. {
  762. int index = PDFViewer.CurrentIndex;
  763. //检测是否已存在相同数据
  764. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  765. foreach (var item in contextMenu.Items)
  766. {
  767. if (item is Separator separator) {
  768. separator.Visibility = visibility;
  769. }
  770. if (item is MenuItem menuItem1)
  771. {
  772. //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
  773. //{
  774. // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  775. //}
  776. switch (menuItem1.Tag.ToString())
  777. {
  778. case "Paste":
  779. //粘贴
  780. //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
  781. //{
  782. // menuItem1.IsEnabled = false;
  783. // menuItem1.Opacity = 0.5;
  784. //}
  785. //else
  786. //{
  787. // menuItem1.IsEnabled = true;
  788. // menuItem1.Opacity = 1;
  789. //}
  790. menuItem1.CommandTarget = (UIElement)e;
  791. menuItem1.Command = ApplicationCommands.Paste;
  792. break;
  793. case "AddAnnotation":
  794. menuItem1.Visibility = visibility;
  795. break;
  796. case "HiddenAnnot":
  797. menuItem1.Visibility = visibility;
  798. break;
  799. case "DisplayAnnot":
  800. menuItem1.Visibility = visibility;
  801. break;
  802. case "AddBookMark":
  803. menuItem1.Visibility = visibility;
  804. break;
  805. case "DelBookMark":
  806. menuItem1.Visibility = visibility;
  807. break;
  808. case "ToolMode":
  809. menuItem1.Visibility = visibility;
  810. break;
  811. case "ReadModel":
  812. menuItem1.Visibility = visibility;
  813. break;
  814. case "UnReadModel":
  815. menuItem1.Visibility = visibility;
  816. break;
  817. case "ViewZoom":
  818. menuItem1.Visibility = visibility;
  819. break;
  820. case "PageDisplay":
  821. menuItem1.Visibility = visibility;
  822. break;
  823. case "Select":
  824. menuItem1.Click -= Select_Click;
  825. menuItem1.Click += Select_Click;
  826. break;
  827. case "Print":
  828. menuItem1.Command = viewContentViewModel.PrintCommand;
  829. break;
  830. }
  831. }
  832. }
  833. }
  834. }
  835. private void Select_Click(object sender, RoutedEventArgs e)
  836. {
  837. if (viewContentViewModel.OpenBOTA == false)
  838. {
  839. viewContentViewModel.OpenBOTA = true;
  840. }
  841. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  842. if (isBook == false)
  843. {
  844. bOTAContent.TabItemSearch.IsSelected = true;
  845. }
  846. }
  847. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  848. {
  849. bool isTabItem = false;
  850. bOTAContentViewModel = null;
  851. bOTAContent = null;
  852. if (regions.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  853. {
  854. var views = regions.Regions[viewContentViewModel.BOTARegionName].Views;
  855. var model = views.FirstOrDefault(q => q is BOTAContent);
  856. if (model is BOTAContent bOTAContent1)
  857. {
  858. bOTAContent = bOTAContent1;
  859. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  860. if (bOTAContentViewModel.CurrentBar == tabItemText)
  861. {
  862. isTabItem = true;
  863. }
  864. }
  865. //foreach (var item in views)
  866. //{
  867. // if (item is BOTAContent bOTAContent1)
  868. // {
  869. // bOTAContent = bOTAContent1;
  870. // bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  871. // if (bOTAContentViewModel.CurrentBar == tabItemText)
  872. // {
  873. // isTabItem = true;
  874. // break;
  875. // }
  876. // }
  877. //}
  878. }
  879. return isTabItem;
  880. }
  881. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  882. {
  883. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  884. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  885. annot.EventType == AnnotArgsType.AnnotHighlight ||
  886. annot.EventType == AnnotArgsType.AnnotStrikeout
  887. )
  888. {
  889. return true;
  890. }
  891. else
  892. {
  893. return false;
  894. }
  895. }
  896. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  897. {
  898. if (e != null && e.Count > 0)
  899. {
  900. for (int i = 0; i < e.Count; i++)
  901. {
  902. AnnotEditEvent editEvent = e[i];
  903. switch (editEvent.EditAction)
  904. {
  905. case ActionType.Add:
  906. int pageindex = editEvent.PageIndex;
  907. int annotindex = editEvent.AnnotIndex;
  908. viewContentViewModel.FillAndSign.Add(new Point(pageindex, annotindex));
  909. break;
  910. }
  911. }
  912. }
  913. }
  914. //选中和非选中注释,右键菜单
  915. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  916. {
  917. if (e != null)
  918. {
  919. var annot = e.AnnotItemsList[0];
  920. if (annot != null)
  921. {
  922. if (e.AnnotItemsList.Count == 1)
  923. {
  924. //IsEdit = false;
  925. //IsAnnotCreateReset:是否为创建注释的状态
  926. if (e.IsAnnotCreateReset == false)
  927. {
  928. GetSelectedAnnots(e);
  929. //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
  930. //PDFViewer.SetToolParam(annot);
  931. }
  932. else
  933. {
  934. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  935. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  936. annot.EventType != AnnotArgsType.AnnotUnderline &&
  937. annot.EventType != AnnotArgsType.AnnotHighlight &&
  938. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  939. annot.EventType != AnnotArgsType.AnnotLink &&
  940. annot.EventType != AnnotArgsType.AnnotFreehand &&
  941. annot.EventType != AnnotArgsType.AnnotSticky
  942. )
  943. {
  944. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  945. {
  946. foreach (var item in ToolExpandDict)
  947. {
  948. if (item.Value == e.AnnotItemsList[0].EventType)
  949. {
  950. annot = null;//新建注释时,回到默认值
  951. FindAnnotTypeKey(item.Key, ref annot);
  952. break;
  953. }
  954. }
  955. }
  956. }
  957. //else
  958. //PDFViewer.SetToolParam(annot);
  959. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  960. if (isRightMenuAddAnnot)
  961. {
  962. ShowPropertyPanel(false);
  963. }
  964. else
  965. {
  966. ShowPropertyPanel();
  967. }
  968. }
  969. }
  970. else
  971. {
  972. bool isDifferentAnnotTyle = false;
  973. var lastAnnot = annot;
  974. foreach (var item in e.AnnotItemsList)
  975. {
  976. if (lastAnnot.EventType != item.EventType)
  977. {
  978. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  979. {
  980. lastAnnot = item;
  981. continue;
  982. }
  983. lastAnnot = item;
  984. isDifferentAnnotTyle = true;
  985. break;
  986. }
  987. }
  988. if (isDifferentAnnotTyle)
  989. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  990. else
  991. GetSelectedAnnots(e);
  992. }
  993. }
  994. }
  995. else
  996. {
  997. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  998. }
  999. }
  1000. //private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1001. //{
  1002. // if (e != null && e.Count > 0)
  1003. // {
  1004. // for (int i = 0; i < e.Count; i++)
  1005. // {
  1006. // AnnotEditEvent editEvent = e[i];
  1007. // switch (editEvent.EditAction)
  1008. // {
  1009. // case ActionType.Add:
  1010. // // bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1011. // if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  1012. // {
  1013. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1014. // if (viewModel != null)
  1015. // {
  1016. // int pageindex = editEvent.PageIndex;
  1017. // int annotindex = editEvent.AnnotIndex;
  1018. // viewModel.UpdateAddedAnnot(pageindex, annotindex);
  1019. // }
  1020. // }
  1021. // break;
  1022. // case ActionType.Del:
  1023. // //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1024. // if (isTabItemAnnotation)
  1025. // {
  1026. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1027. // if (viewModel != null)
  1028. // {
  1029. // int pageindex = editEvent.PageIndex;
  1030. // int annotindex = editEvent.AnnotIndex;
  1031. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  1032. // }
  1033. // }
  1034. // break;
  1035. // case ActionType.Modify:
  1036. // isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1037. // if (bOTAContent.TabItemAnnotation.IsSelected)
  1038. // {
  1039. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1040. // if (viewModel != null)
  1041. // {
  1042. // int pageindex = editEvent.PageIndex;
  1043. // int annotindex = editEvent.AnnotIndex;
  1044. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  1045. // }
  1046. // }
  1047. // break;
  1048. // case ActionType.TextEdit:
  1049. // break;
  1050. // default:
  1051. // break;
  1052. // }
  1053. // }
  1054. // }
  1055. //}
  1056. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  1057. {
  1058. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  1059. annot.EventType == AnnotArgsType.AnnotSquare ||
  1060. annot.EventType == AnnotArgsType.AnnotLine
  1061. )
  1062. {
  1063. return true;
  1064. }
  1065. else
  1066. {
  1067. return false;
  1068. }
  1069. }
  1070. private void GetSelectedAnnots(AnnotAttribEvent e)
  1071. {
  1072. IsEdit = true;
  1073. var annot = e.AnnotItemsList[0];
  1074. switch (annot.EventType)
  1075. {
  1076. case AnnotArgsType.AnnotFreeText:
  1077. GetFreetext(e.AnnotItemsList);
  1078. break;
  1079. case AnnotArgsType.AnnotFreehand:
  1080. GetFreehand(e.AnnotItemsList);
  1081. break;
  1082. }
  1083. }
  1084. private void ShowPropertyPanel(bool show = true)
  1085. {
  1086. viewContentViewModel.IsPropertyOpen = show;
  1087. }
  1088. #region Navigation
  1089. public bool IsNavigationTarget(NavigationContext navigationContext)
  1090. {
  1091. return true;
  1092. }
  1093. public void OnNavigatedFrom(NavigationContext navigationContext)
  1094. {
  1095. UnBindingPDFViewerHandler();
  1096. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1097. ViewerContextMenu_Loaded(contextMenu, null,Visibility.Visible);
  1098. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1099. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1100. ShowPropertyPanel(false);
  1101. }
  1102. public void OnNavigatedTo(NavigationContext navigationContext)
  1103. {
  1104. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1105. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1106. BindingPDFViewerHandler();
  1107. HookShapeIsCheck=true;
  1108. InitCheckedEvent("RbtnTick");
  1109. IsEdit = false;
  1110. }
  1111. #endregion
  1112. }
  1113. }