FillAndSignContentViewModel.cs 78 KB

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