FillAndSignContentViewModel.cs 77 KB

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