FillAndSignContentViewModel.cs 80 KB

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