FillAndSignContentViewModel.cs 77 KB

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