FillAndSignContentViewModel.cs 74 KB

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