FillAndSignContentViewModel.cs 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855
  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. namespace PDF_Master.ViewModels.FillAndSign
  60. {
  61. public class FillAndSignContentViewModel : BindableBase, INavigationAware
  62. {
  63. #region
  64. public CPDFViewer PDFViewer;
  65. private AnnotTransfer propertyPanel = new AnnotTransfer();
  66. public ViewContentViewModel viewContentViewModel;
  67. private bool isRightMenuAddAnnot = false;
  68. private IEventAggregator events;
  69. public List<List<Point>> ShapePoints = new List<List<Point>>();
  70. public string Shape = "HookShape";
  71. private bool IsFillAndSign
  72. {get;set;} = true;
  73. private PopMenu FreeHandAnnotPopMenu;
  74. private PopMenu FreeTextAnnotPopMenu;
  75. private PopMenu MultiAnnotPopMenu;
  76. public bool isFirst = true;
  77. private IRegionManager regions { get; set; }
  78. private Dictionary<string, AnnotArgsType> ToolExpandDict = new Dictionary<string, AnnotArgsType>();
  79. public static bool IsEdit = false;
  80. public static bool IsSignPoint = false;
  81. public Brush SelectColor = new SolidColorBrush(Color.FromArgb(0xff, 0x26, 0x25, 0x29));
  82. public double FillOpacity = 1;
  83. public double LineWidth = 2;
  84. public double LineWidthMultiple = 1;
  85. public bool IsClickNull=false;
  86. private string DateOrText = "";
  87. private bool _HookShapeIsCheck = false;
  88. public bool HookShapeIsCheck
  89. {
  90. get { return _HookShapeIsCheck; }
  91. set { SetProperty(ref _HookShapeIsCheck, value); }
  92. }
  93. public Dictionary<string, List<List<Point>>> keyShape = new Dictionary<string, List<List<Point>>>();
  94. private void InitkeyShape()
  95. {
  96. 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) } };
  97. 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) } };
  98. 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) } };
  99. keyShape["LineShape"] = new List<List<Point>> { new List<Point> { new Point(3.19995, 14), new Point(25.127, 14) } };
  100. keyShape["DotShape"] = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.19995), new Point(3.19995, 3.19995) } };
  101. //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) } };
  102. //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) } };
  103. //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) } };
  104. //keyShape["LineShape"] = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.20001), new Point(28, 3.20001) } };
  105. //keyShape["DotShape"] = new List<List<Point>> { new List<Point> { new Point(3.19995, 3.19995), new Point(3.19995, 3.19995) } };
  106. }
  107. #endregion
  108. public DelegateCommand<object> AnnotDefaultValue_MenuCommand { get; set; }
  109. public DelegateCommand<object> FreeTextFontFamily_MenuCommand { get; set; }
  110. public DelegateCommand<object> AnnotColorPalette_MenuCommand { get; set; }
  111. public DelegateCommand<object> FreeTextAglin_MenuCommand { get; set; }
  112. #region Command
  113. public DelegateCommand<object> CheckCommand { get; set; }
  114. /// <summary>
  115. /// 按钮名称和属性面板映射字典
  116. /// </summary>
  117. public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
  118. private IDialogService dialogs;
  119. #endregion
  120. string Unicode = "";
  121. public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events) { }
  122. public FillAndSignContentViewModel(IRegionManager regionManager, IEventAggregator events, IDialogService dialogService)
  123. {
  124. dialogs = dialogService;
  125. regions = regionManager;
  126. this.events = events;
  127. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  128. CheckCommand = new DelegateCommand<object>(CheckedEvent);
  129. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  130. InitDictionary();
  131. InitkeyShape();
  132. AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
  133. AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
  134. FreeTextFontFamily_MenuCommand = new DelegateCommand<object>(FreeTextFontFamily_Menu);
  135. FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
  136. InitSelectFreeHandAnnotMenu();
  137. InitSelectFreeTextAnnotMenu();
  138. InitSelectMultiAnnotMenu();
  139. SubscribeEvent();
  140. InitShapeList();
  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. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  692. foreach (var item in selectedArgs)
  693. {
  694. //if (ListPoint((item as FreehandAnnotArgs).RawPointList, ShapePoints)){
  695. foreach (var point in viewContentViewModel.FillAndSign)
  696. {
  697. if ((item as FreehandAnnotArgs).PageIndex == point.PageIndex && (item as FreehandAnnotArgs).AnnotIndex == point.AnnotIndex)
  698. {
  699. newSelectedArgs.Add(item);
  700. }
  701. }
  702. }
  703. //freehandArgs.RawPointList = ShapePoints;
  704. //freehandArgs.InkColor = (SelectColor as SolidColorBrush).Color;
  705. //freehandArgs.Transparency = 1;
  706. //freehandArgs.LineWidth = LineWidth;
  707. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  708. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  709. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  710. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  711. annotAttribsList[AnnotAttrib.Path] = freehandArgs.RawPointList;
  712. annotAttribsList[AnnotAttrib.Width] = freehandArgs.Width;
  713. annotAttribsList[AnnotAttrib.Height] = freehandArgs.Height;
  714. AddToPropertyPanel("ShapFillProperty", "Freehand", newSelectedArgs, annotAttribsList);
  715. //GetStamp();
  716. return freehandArgs;
  717. }
  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. //AddToPropertyPanel("ShapFillProperty", "Freehand", selectedArgs, annotAttribsList);
  723. return freehandArgs;
  724. }
  725. /// <summary>
  726. /// 文本
  727. /// </summary>
  728. /// <param name="selectedfreetextArgs"></param>
  729. /// <returns></returns>
  730. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  731. {
  732. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  733. FreeTextAnnotArgs freetextArgs = null;
  734. TextAlignment textAlignment;
  735. if (selectedArgs == null || selectedArgs.Count == 0)
  736. {
  737. freetextArgs = new FreeTextAnnotArgs();
  738. freetextArgs.Align = TextAlignment.Left;
  739. freetextArgs.BgColor = Colors.Transparent;
  740. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  741. freetextArgs.FontColor = Colors.Black;
  742. freetextArgs.FontSize = 14;
  743. freetextArgs.Transparency = 1;
  744. freetextArgs.LineColor = Colors.Black;
  745. freetextArgs.LineWidth = 0;
  746. freetextArgs.TextContent = string.Empty;
  747. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  748. if (annotProperty != null)
  749. {
  750. freetextArgs.Align = annotProperty.TextAlign;
  751. freetextArgs.BgColor = annotProperty.BackgroundColor;
  752. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  753. freetextArgs.FontColor = annotProperty.ForgoundColor;
  754. freetextArgs.FontSize = annotProperty.FontSize;
  755. freetextArgs.Transparency = annotProperty.Opacity;
  756. freetextArgs.LineColor = annotProperty.BorderColor;
  757. freetextArgs.LineWidth = annotProperty.Thickness;
  758. freetextArgs.TextContent = annotProperty.NoteText;
  759. freetextArgs.FontWeight = annotProperty.FontWeight;
  760. freetextArgs.FontStyle = annotProperty.FontStyle;
  761. }
  762. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  763. if (align == 0)
  764. textAlignment = TextAlignment.Left;
  765. else if (align == 1)
  766. textAlignment = TextAlignment.Center;
  767. else
  768. textAlignment = TextAlignment.Right;
  769. if (freetextArgs != null)
  770. {
  771. selectedArgs = new List<AnnotHandlerEventArgs>();
  772. selectedArgs.Add(freetextArgs);
  773. }
  774. }
  775. else
  776. {
  777. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  778. textAlignment = freetextArgs.Align;
  779. }
  780. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  781. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  782. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  783. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  784. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  785. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  786. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  787. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  788. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  789. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  790. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  791. annotAttribsList[AnnotAttrib.Text] = freetextArgs.TextContent;
  792. AddToPropertyPanel("FreetextAnnotProperty", DateOrText, selectedArgs, annotAttribsList);
  793. return freetextArgs;
  794. }
  795. /// <summary>
  796. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  797. /// </summary>
  798. /// <param name="viewContent">对应的注释面板</param>
  799. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  800. /// <param name="annot">注释</param>
  801. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  802. private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
  803. {
  804. if (annots != null && annots.Count != 0)
  805. {
  806. propertyPanel.annotlists = annots;
  807. propertyPanel.annot = annots[0];
  808. }
  809. else
  810. {
  811. propertyPanel.annotlists = null;
  812. propertyPanel.annot = null;
  813. }
  814. if (annotAttribsList != null && annotAttribsList.Count != 0 && annots != null && annots.Count != 0)
  815. {
  816. if (annots.Count > 1)
  817. {
  818. if (propertyPanel.AnnotEvents == null)
  819. propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
  820. propertyPanel.AnnotEvents.Clear();
  821. foreach (var itemAnnot in annots)
  822. {
  823. //for (int j = 0; j < viewContentViewModel.FillAndSign.Count; j++)
  824. //{
  825. // //annotAttribsList = itemAnnot.GetAnnotAttrib();
  826. // //annotAttribsList[AnnotAttrib.Width] = (itemAnnot as FreehandAnnotArgs).Width;
  827. // //annotAttribsList[AnnotAttrib.Height] = (itemAnnot as FreehandAnnotArgs).Height;
  828. // if (viewContentViewModel.FillAndSign[j].PageIndex == itemAnnot.PageIndex && viewContentViewModel.FillAndSign[j].AnnotIndex == itemAnnot.AnnotIndex)
  829. // {
  830. // FreehandAnnotArgs freehandArgs = null;
  831. // freehandArgs = itemAnnot as FreehandAnnotArgs;
  832. // annotAttribsList = itemAnnot.GetAnnotAttrib();
  833. // annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  834. // annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  835. // annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  836. // annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  837. // annotAttribsList[AnnotAttrib.Path] = freehandArgs.RawPointList;
  838. // annotAttribsList[AnnotAttrib.Width] = freehandArgs.Width;
  839. // annotAttribsList[AnnotAttrib.Height] = freehandArgs.Height;
  840. // }
  841. //}
  842. var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
  843. eventitem.ClearChangeAttribute();
  844. propertyPanel.AnnotEvents.Add(eventitem);
  845. }
  846. }
  847. //for (int j = 0; j < viewContentViewModel.FillAndSign.Count; j++)
  848. //{
  849. // //if (viewContentViewModel.FillAndSign[j].PageIndex == annots[0].PageIndex && viewContentViewModel.FillAndSign[j].AnnotIndex == annots[0].AnnotIndex)
  850. // //{
  851. // // FreehandAnnotArgs freehandArgs = null;
  852. // // freehandArgs = annots[0] as FreehandAnnotArgs;
  853. // // annotAttribsList = annots[0].GetAnnotAttrib();
  854. // // annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  855. // // annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  856. // // annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  857. // // annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  858. // // annotAttribsList[AnnotAttrib.Path] = freehandArgs.RawPointList;
  859. // // annotAttribsList[AnnotAttrib.Width] = freehandArgs.Width;
  860. // // annotAttribsList[AnnotAttrib.Height] = freehandArgs.Height;
  861. // //}
  862. //}
  863. var eventitem1 = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
  864. eventitem1.ClearChangeAttribute();
  865. propertyPanel.AnnotEvent = eventitem1;
  866. if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
  867. {
  868. propertyPanel.AnnotEvent = annotAttribEvent;
  869. }
  870. }
  871. if (toolTag == "Freetext")
  872. {
  873. propertyPanel.SetIsTextFill(true);
  874. }
  875. else
  876. {
  877. propertyPanel.SetIsTextFill(false);
  878. }
  879. if (string.IsNullOrEmpty(viewContent) == false)
  880. {
  881. if (isUpData) { return; }
  882. if (viewContent == "ShapFillProperty")
  883. {
  884. NavigateToProperty(viewContent, propertyPanel); return;
  885. }
  886. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  887. }
  888. }
  889. private void NavigateToProperty(string btnName, AnnotTransfer annotPropertyPanel)
  890. {
  891. NavigationParameters values = new NavigationParameters();
  892. values.Add(ParameterNames.PDFViewer, PDFViewer);
  893. values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  894. values.Add("IsFillAndSign", IsFillAndSign);
  895. values.Add("Shape", Shape);
  896. values.Add("FillAndSignContentViewModel", this);
  897. regions.RequestNavigate(RegionNames.PropertyRegionName, btnName, values);
  898. viewContentViewModel.IsPropertyOpen = true;
  899. }
  900. /// <summary>
  901. /// 初始化按钮名称-属性面板字典
  902. /// </summary>
  903. private void InitDictionary()
  904. {
  905. btnToProperty["RbtnText"] = "TextFillProperty";
  906. btnToProperty["RbtnTick"] = "ShapFillProperty";
  907. btnToProperty["RbtnFork"] = "ShapFillProperty";
  908. btnToProperty["RbtnRectangle"] = "ShapFillProperty";
  909. btnToProperty["RbtnLine"] = "ShapFillProperty";
  910. btnToProperty["RbtnPoint"] = "ShapFillProperty";
  911. btnToProperty["RbtnDate"] = "DateFillProperty";
  912. btnToProperty["RbtnSign"] = "";
  913. }
  914. /// <summary>
  915. /// 手绘
  916. /// </summary>
  917. private void InitSelectFreeHandAnnotMenu()
  918. {
  919. var popMenu = new ContextMenu();
  920. PopMenu pop = new PopMenu(popMenu);
  921. var menuItem = new MenuItem();
  922. menuItem.Name = "FreeHandCopy";
  923. menuItem.Header = "复制";
  924. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  925. menuItem = new MenuItem();
  926. menuItem.Name = "FreeHandCut";
  927. menuItem.Header = "剪切";
  928. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  929. menuItem = new MenuItem();
  930. menuItem.Name = "FreeHandPaste";
  931. menuItem.Header = "粘贴";
  932. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  933. menuItem = new MenuItem();
  934. menuItem.Name = "FreeHandDelete";
  935. menuItem.Header = "删除";
  936. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  937. pop.AddItem(GetSeparator());
  938. menuItem = new MenuItem();
  939. menuItem.Name = "FreeHandDefault";
  940. menuItem.Header = "设置当前属性为默认值";
  941. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  942. FreeHandAnnotPopMenu = pop;
  943. }
  944. /// <summary>
  945. /// 文本
  946. /// </summary>
  947. private void InitSelectFreeTextAnnotMenu()
  948. {
  949. var popMenu = new ContextMenu();
  950. PopMenu pop = new PopMenu(popMenu);
  951. var menuItem = new MenuItem();
  952. menuItem.Name = "FreeTextCopy";
  953. menuItem.Header = "复制";
  954. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  955. menuItem = new MenuItem();
  956. menuItem.Name = "FreeTextCut";
  957. menuItem.Header = "剪切";
  958. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  959. menuItem = new MenuItem();
  960. menuItem.Name = "FreeTextPaste";
  961. menuItem.Header = "粘贴";
  962. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  963. menuItem = new MenuItem();
  964. menuItem.Name = "FreeTextDelete";
  965. menuItem.Header = "删除";
  966. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  967. pop.AddItem(GetSeparator());
  968. menuItem = new MenuItem();
  969. menuItem.Name = "FreeTextColor";
  970. menuItem.Header = "字体颜色";
  971. menuItem.Tag = "FontColor";
  972. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  973. menuItem = new MenuItem();
  974. menuItem.Name = "FreeTextColor";
  975. menuItem.Header = "填充颜色";
  976. menuItem.Tag = "FillColor";
  977. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  978. menuItem = new MenuItem();
  979. menuItem.Name = "FreeTextFontFamily";
  980. menuItem.Header = "字体";
  981. pop.AddItem(menuItem);
  982. var family = TextFont.GetFamily();
  983. foreach (var item in family)
  984. {
  985. RadioButton familyRdioBtn = new RadioButton();
  986. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  987. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  988. familyRdioBtn.Name = item.ValueStr;
  989. familyRdioBtn.Tag = item.ValueStr;
  990. familyRdioBtn.GroupName = "FontFamily";
  991. familyRdioBtn.Content = item.Content;
  992. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  993. }
  994. menuItem = new MenuItem();
  995. menuItem.Name = "FreeTextAglin";
  996. menuItem.Header = "文本对齐";
  997. pop.AddItem(menuItem);
  998. var radioButton = new RadioButton();
  999. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  1000. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  1001. radioButton.Name = "FreeTextAglinLeft";
  1002. radioButton.Tag = "Left";
  1003. radioButton.GroupName = "Aglin";
  1004. radioButton.Content = "左对齐";
  1005. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  1006. radioButton = new RadioButton();
  1007. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  1008. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  1009. radioButton.Name = "FreeTextAglinCenter";
  1010. radioButton.Tag = "Center";
  1011. radioButton.GroupName = "Aglin";
  1012. radioButton.Content = "居中对齐";
  1013. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  1014. radioButton = new RadioButton();
  1015. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  1016. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  1017. radioButton.Name = "FreeTextAglinRight";
  1018. radioButton.Tag = "Right";
  1019. radioButton.GroupName = "Aglin";
  1020. radioButton.Content = "右对齐";
  1021. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  1022. radioButton = new RadioButton();
  1023. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  1024. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  1025. radioButton.Name = "FreeTextAglinJustify";
  1026. radioButton.Tag = "Justify";
  1027. radioButton.GroupName = "Aglin";
  1028. radioButton.Content = "两端对齐";
  1029. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  1030. menuItem = new MenuItem();
  1031. menuItem.Name = "FreeHandDefault";
  1032. menuItem.Header = "设置当前属性为默认值";
  1033. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  1034. FreeTextAnnotPopMenu = pop;
  1035. }
  1036. /// <summary>
  1037. /// 多选注释
  1038. /// </summary>
  1039. private void InitSelectMultiAnnotMenu()
  1040. {
  1041. var popMenu = new ContextMenu();
  1042. PopMenu pop = new PopMenu(popMenu);
  1043. var menuItem = new MenuItem();
  1044. menuItem.Name = "MultiCopy";
  1045. menuItem.Header = "复制";
  1046. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  1047. menuItem = new MenuItem();
  1048. menuItem.Name = "MultiCut";
  1049. menuItem.Header = "剪切";
  1050. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  1051. menuItem = new MenuItem();
  1052. menuItem.Name = "MultiDelete";
  1053. menuItem.Header = "删除";
  1054. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  1055. MultiAnnotPopMenu = pop;
  1056. }
  1057. private Separator GetSeparator()
  1058. {
  1059. Separator separator = new Separator();
  1060. separator.Height = 1;
  1061. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  1062. separator.BorderThickness = new Thickness(1);
  1063. return separator;
  1064. }
  1065. private void BindingPDFViewerHandler()
  1066. {
  1067. //来自PDFViewer的响应事件
  1068. if (PDFViewer != null)
  1069. {
  1070. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  1071. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  1072. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  1073. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  1074. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  1075. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  1076. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  1077. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  1078. }
  1079. }
  1080. private void UnBindingPDFViewerHandler()
  1081. {
  1082. if (PDFViewer != null)
  1083. {
  1084. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  1085. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  1086. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  1087. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  1088. }
  1089. }
  1090. //在注释工具的状态下,右键菜单
  1091. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  1092. {
  1093. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  1094. return;
  1095. switch (e.CommandType)
  1096. {
  1097. case CommandType.Context:
  1098. if (e.AnnotEventArgsList.Count > 0)
  1099. {
  1100. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  1101. {
  1102. //绑定标记密文处右键菜单
  1103. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  1104. }
  1105. else
  1106. {
  1107. if (e.AnnotEventArgsList.Count == 1)
  1108. {
  1109. var selectedAnnot = e.AnnotEventArgsList[0];
  1110. switch (selectedAnnot.EventType)
  1111. {
  1112. case AnnotArgsType.AnnotFreehand:
  1113. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1114. break;
  1115. case AnnotArgsType.AnnotFreeText:
  1116. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1117. break;
  1118. }
  1119. }
  1120. else
  1121. {
  1122. bool isHigh = true;//是否为高亮
  1123. foreach (var item in e.AnnotEventArgsList)
  1124. {
  1125. if (isHightAnnot(item) == false)
  1126. {
  1127. isHigh = false;
  1128. break;
  1129. }
  1130. }
  1131. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  1132. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  1133. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  1134. }
  1135. }
  1136. if (e.PopupMenu != null)
  1137. {
  1138. e.Handle = true;
  1139. }
  1140. }
  1141. else
  1142. {
  1143. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  1144. {
  1145. if (e.PopupMenu != null)
  1146. {
  1147. e.Handle = true;
  1148. }
  1149. }
  1150. else
  1151. {
  1152. e.PopupMenu = ViewerContextMenu(sender);
  1153. if (e.PopupMenu != null)
  1154. {
  1155. e.Handle = true;
  1156. }
  1157. }
  1158. }
  1159. break;
  1160. }
  1161. }
  1162. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1163. {
  1164. if (e != null && e.DrawContext != null)
  1165. {
  1166. Rect hoverRect = new Rect(
  1167. e.PaintRect.Left - 2,
  1168. e.PaintRect.Top - 2,
  1169. e.PaintRect.Width + 4,
  1170. e.PaintRect.Height + 4);
  1171. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1172. hoverPen.DashStyle = DashStyles.Dash;
  1173. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1174. }
  1175. CloseAnnotToolTip();
  1176. }
  1177. private Rect oldRect = new Rect(0, 0, 0, 0);
  1178. private void CloseAnnotToolTip()
  1179. {
  1180. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1181. {
  1182. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1183. oldTips.IsOpen = false;
  1184. oldTips.Visibility = Visibility.Collapsed;
  1185. PDFViewer.ToolTip = null;
  1186. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1187. oldRect = new Rect(0, 0, 0, 0);
  1188. }
  1189. }
  1190. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1191. {
  1192. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1193. {
  1194. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1195. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1196. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1197. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1198. {
  1199. CloseAnnotToolTip();
  1200. }
  1201. }
  1202. }
  1203. private ContextMenu ViewerContextMenu(object sender)
  1204. {
  1205. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1206. ViewerContextMenu_Loaded(contextMenu, sender);
  1207. return contextMenu;
  1208. }
  1209. private void ViewerContextMenu_Loaded(object sender, object e, Visibility visibility = Visibility.Collapsed)
  1210. {
  1211. ContextMenu contextMenu = sender as ContextMenu;
  1212. contextMenu.DataContext = viewContentViewModel;
  1213. if (contextMenu.Items.Count > 0)
  1214. {
  1215. int index = PDFViewer.CurrentIndex;
  1216. //检测是否已存在相同数据
  1217. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  1218. foreach (var item in contextMenu.Items)
  1219. {
  1220. if (item is Separator separator)
  1221. {
  1222. separator.Visibility = visibility;
  1223. }
  1224. if (item is MenuItem menuItem1)
  1225. {
  1226. //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
  1227. //{
  1228. // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  1229. //}
  1230. switch (menuItem1.Tag.ToString())
  1231. {
  1232. case "Paste":
  1233. //粘贴
  1234. //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
  1235. //{
  1236. // menuItem1.IsEnabled = false;
  1237. // menuItem1.Opacity = 0.5;
  1238. //}
  1239. //else
  1240. //{
  1241. // menuItem1.IsEnabled = true;
  1242. // menuItem1.Opacity = 1;
  1243. //}
  1244. menuItem1.CommandTarget = (UIElement)e;
  1245. menuItem1.Command = ApplicationCommands.Paste;
  1246. break;
  1247. case "AddAnnotation":
  1248. menuItem1.Visibility = visibility;
  1249. break;
  1250. case "HiddenAnnot":
  1251. menuItem1.Visibility = visibility;
  1252. break;
  1253. case "DisplayAnnot":
  1254. menuItem1.Visibility = visibility;
  1255. break;
  1256. case "AddBookMark":
  1257. menuItem1.Visibility = visibility;
  1258. break;
  1259. case "DelBookMark":
  1260. menuItem1.Visibility = visibility;
  1261. break;
  1262. case "ToolMode":
  1263. menuItem1.Visibility = visibility;
  1264. break;
  1265. case "ReadModel":
  1266. menuItem1.Visibility = visibility;
  1267. break;
  1268. case "UnReadModel":
  1269. menuItem1.Visibility = visibility;
  1270. break;
  1271. case "ViewZoom":
  1272. menuItem1.Visibility = visibility;
  1273. break;
  1274. case "PageDisplay":
  1275. menuItem1.Visibility = visibility;
  1276. break;
  1277. case "Select":
  1278. menuItem1.Click -= Select_Click;
  1279. menuItem1.Click += Select_Click;
  1280. break;
  1281. case "Print":
  1282. menuItem1.Command = viewContentViewModel.PrintCommand;
  1283. break;
  1284. }
  1285. }
  1286. }
  1287. }
  1288. }
  1289. private void Select_Click(object sender, RoutedEventArgs e)
  1290. {
  1291. if (viewContentViewModel.OpenBOTA == false)
  1292. {
  1293. viewContentViewModel.OpenBOTA = true;
  1294. }
  1295. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1296. if (isBook == false)
  1297. {
  1298. bOTAContent.TabItemSearch.IsSelected = true;
  1299. }
  1300. }
  1301. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1302. {
  1303. bool isTabItem = false;
  1304. bOTAContentViewModel = null;
  1305. bOTAContent = null;
  1306. if (regions.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  1307. {
  1308. var views = regions.Regions[viewContentViewModel.BOTARegionName].Views;
  1309. var model = views.FirstOrDefault(q => q is BOTAContent);
  1310. if (model is BOTAContent bOTAContent1)
  1311. {
  1312. bOTAContent = bOTAContent1;
  1313. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1314. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1315. {
  1316. isTabItem = true;
  1317. }
  1318. }
  1319. //foreach (var item in views)
  1320. //{
  1321. // if (item is BOTAContent bOTAContent1)
  1322. // {
  1323. // bOTAContent = bOTAContent1;
  1324. // bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1325. // if (bOTAContentViewModel.CurrentBar == tabItemText)
  1326. // {
  1327. // isTabItem = true;
  1328. // break;
  1329. // }
  1330. // }
  1331. //}
  1332. }
  1333. return isTabItem;
  1334. }
  1335. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  1336. {
  1337. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  1338. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  1339. annot.EventType == AnnotArgsType.AnnotHighlight ||
  1340. annot.EventType == AnnotArgsType.AnnotStrikeout
  1341. )
  1342. {
  1343. return true;
  1344. }
  1345. else
  1346. {
  1347. return false;
  1348. }
  1349. }
  1350. //注释编辑事件
  1351. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1352. {
  1353. if (e != null && e.Count > 0)
  1354. {
  1355. for (int i = 0; i < e.Count; i++)
  1356. {
  1357. AnnotEditEvent editEvent = e[i];
  1358. int pageindex = editEvent.PageIndex;
  1359. int annotindex = editEvent.AnnotIndex;
  1360. switch (editEvent.EditAction)
  1361. {
  1362. case ActionType.Add:
  1363. if (Shape != "None") { if (Shape == "Sign") { viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(pageindex, annotindex)); } else { viewContentViewModel.FillAndSign.Add(new FillAndSignIsShape(pageindex, annotindex, Shape)); } }
  1364. PDFViewer.SelectAnnotation(pageindex, annotindex);
  1365. break;
  1366. case ActionType.Del:
  1367. if (Shape != "None")
  1368. {
  1369. for (int j = 0; j < viewContentViewModel.FillAndSign.Count; j++)
  1370. {
  1371. if (viewContentViewModel.FillAndSign[j].PageIndex == pageindex && viewContentViewModel.FillAndSign[j].AnnotIndex == annotindex)
  1372. {
  1373. viewContentViewModel.FillAndSign.Remove(viewContentViewModel.FillAndSign[j]);
  1374. }
  1375. }
  1376. for (int j = 0; j < viewContentViewModel.AnnotSignatures.Count; j++)
  1377. {
  1378. if (viewContentViewModel.AnnotSignatures[j].Item1 == pageindex && viewContentViewModel.AnnotSignatures[j].Item2 == annotindex)
  1379. {
  1380. viewContentViewModel.AnnotSignatures.Remove(viewContentViewModel.AnnotSignatures[j]);
  1381. }
  1382. }
  1383. }
  1384. break;
  1385. }
  1386. }
  1387. }
  1388. }
  1389. //选中和非选中注释,右键菜单
  1390. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  1391. {
  1392. if (e != null)
  1393. {
  1394. IsClickNull=false;
  1395. var annot = e.AnnotItemsList[0];
  1396. if (annot != null)
  1397. {
  1398. if (e.AnnotItemsList.Count == 1)
  1399. {
  1400. //IsEdit = false;
  1401. //IsAnnotCreateReset:是否为创建注释的状态
  1402. if (e.IsAnnotCreateReset == false)
  1403. {
  1404. GetSelectedAnnots(e);
  1405. //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
  1406. //PDFViewer.SetToolParam(annot);
  1407. }
  1408. else
  1409. {
  1410. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  1411. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  1412. annot.EventType != AnnotArgsType.AnnotUnderline &&
  1413. annot.EventType != AnnotArgsType.AnnotHighlight &&
  1414. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  1415. annot.EventType != AnnotArgsType.AnnotLink &&
  1416. annot.EventType != AnnotArgsType.AnnotFreehand &&
  1417. annot.EventType != AnnotArgsType.AnnotSticky
  1418. )
  1419. {
  1420. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  1421. {
  1422. foreach (var item in ToolExpandDict)
  1423. {
  1424. if (item.Value == e.AnnotItemsList[0].EventType)
  1425. {
  1426. annot = null;//新建注释时,回到默认值
  1427. FindAnnotTypeKey(item.Key, ref annot);
  1428. break;
  1429. }
  1430. }
  1431. }
  1432. }
  1433. //else
  1434. //PDFViewer.SetToolParam(annot);
  1435. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  1436. if (isRightMenuAddAnnot)
  1437. {
  1438. ShowPropertyPanel(false);
  1439. }
  1440. else
  1441. {
  1442. ShowPropertyPanel();
  1443. }
  1444. }
  1445. }
  1446. else
  1447. {
  1448. bool isDifferentAnnotTyle = false;
  1449. var lastAnnot = annot;
  1450. foreach (var item in e.AnnotItemsList)
  1451. {
  1452. if (lastAnnot.EventType != item.EventType)
  1453. {
  1454. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  1455. {
  1456. lastAnnot = item;
  1457. continue;
  1458. }
  1459. lastAnnot = item;
  1460. isDifferentAnnotTyle = true;
  1461. break;
  1462. }
  1463. }
  1464. if (isDifferentAnnotTyle)
  1465. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1466. else
  1467. GetSelectedAnnots(e);
  1468. }
  1469. }
  1470. }
  1471. else
  1472. {
  1473. if (PDFViewer.MouseMode != MouseModes.AnnotCreate) { viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); }
  1474. else { IsClickNull = true; }
  1475. }
  1476. }
  1477. //private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1478. //{
  1479. // if (e != null && e.Count > 0)
  1480. // {
  1481. // for (int i = 0; i < e.Count; i++)
  1482. // {
  1483. // AnnotEditEvent editEvent = e[i];
  1484. // switch (editEvent.EditAction)
  1485. // {
  1486. // case ActionType.Add:
  1487. // // bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  1488. // if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  1489. // {
  1490. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1491. // if (viewModel != null)
  1492. // {
  1493. // int pageindex = editEvent.PageIndex;
  1494. // int annotindex = editEvent.AnnotIndex;
  1495. // viewModel.UpdateAddedAnnot(pageindex, annotindex);
  1496. // }
  1497. // }
  1498. // break;
  1499. // case ActionType.Del:
  1500. // //isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1501. // if (isTabItemAnnotation)
  1502. // {
  1503. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1504. // if (viewModel != null)
  1505. // {
  1506. // int pageindex = editEvent.PageIndex;
  1507. // int annotindex = editEvent.AnnotIndex;
  1508. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, true);
  1509. // }
  1510. // }
  1511. // break;
  1512. // case ActionType.Modify:
  1513. // isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
  1514. // if (bOTAContent.TabItemAnnotation.IsSelected)
  1515. // {
  1516. // AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
  1517. // if (viewModel != null)
  1518. // {
  1519. // int pageindex = editEvent.PageIndex;
  1520. // int annotindex = editEvent.AnnotIndex;
  1521. // viewModel.UpdateModifiedAnnot(pageindex, annotindex, false);
  1522. // }
  1523. // }
  1524. // break;
  1525. // case ActionType.TextEdit:
  1526. // break;
  1527. // default:
  1528. // break;
  1529. // }
  1530. // }
  1531. // }
  1532. //}
  1533. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  1534. {
  1535. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  1536. annot.EventType == AnnotArgsType.AnnotSquare ||
  1537. annot.EventType == AnnotArgsType.AnnotLine
  1538. )
  1539. {
  1540. return true;
  1541. }
  1542. else
  1543. {
  1544. return false;
  1545. }
  1546. }
  1547. private void GetSelectedAnnots(AnnotAttribEvent e)
  1548. {
  1549. IsEdit = true;
  1550. var annot = e.AnnotItemsList[0];
  1551. switch (annot.EventType)
  1552. {
  1553. case AnnotArgsType.AnnotFreeText:
  1554. GetFreetext(e.AnnotItemsList);
  1555. break;
  1556. case AnnotArgsType.AnnotFreehand:
  1557. bool isDifferen = false;
  1558. foreach (var point in viewContentViewModel.FillAndSign)
  1559. {
  1560. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  1561. {
  1562. isDifferen = true;
  1563. break;
  1564. }
  1565. else
  1566. {
  1567. isDifferen = false;
  1568. }
  1569. }
  1570. if (!isDifferen)
  1571. {
  1572. foreach (var point in viewContentViewModel.AnnotSignatures)
  1573. {
  1574. if (annot.PageIndex == point.Item1 && annot.AnnotIndex == point.Item2)
  1575. {
  1576. isDifferen = true;
  1577. break;
  1578. }
  1579. else
  1580. {
  1581. isDifferen = false;
  1582. }
  1583. }
  1584. if (isDifferen)
  1585. {
  1586. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); return;
  1587. }
  1588. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); return;
  1589. }
  1590. GetFreehand(e.AnnotItemsList);
  1591. break;
  1592. }
  1593. }
  1594. private void ShowPropertyPanel(bool show = true)
  1595. {
  1596. viewContentViewModel.IsPropertyOpen = show;
  1597. }
  1598. #region Navigation
  1599. public bool IsNavigationTarget(NavigationContext navigationContext)
  1600. {
  1601. return true;
  1602. }
  1603. public void OnNavigatedFrom(NavigationContext navigationContext)
  1604. {
  1605. UnBindingPDFViewerHandler();
  1606. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1607. ViewerContextMenu_Loaded(contextMenu, null, Visibility.Visible);
  1608. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1609. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1610. ShowPropertyPanel(false);
  1611. }
  1612. public void OnNavigatedTo(NavigationContext navigationContext)
  1613. {
  1614. IsFillAndSign = true;
  1615. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1616. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1617. BindingPDFViewerHandler();
  1618. HookShapeIsCheck = true;
  1619. HookShapeIsCheck = false;
  1620. InitFillAndSignProperty();
  1621. ShowPropertyPanel(false);
  1622. // InitCheckedEvent("RbtnTick");
  1623. IsEdit = false;
  1624. }
  1625. #endregion
  1626. }
  1627. }