FillAndSignContentViewModel.cs 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897
  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. ///
  894. public string T_RightMenuAnnotCopy = App.MainPageLoader.GetString("ViewRightMenuAnnot_Copy");
  895. public string T_RightMenuAnnotCut = App.MainPageLoader.GetString("ViewRightMenuAnnot_Cut");
  896. public string T_RightMenuAnnotPaste = App.MainPageLoader.GetString("ViewRightMenuAnnot_Paste");
  897. public string T_RightMenuAnnotDelete = App.MainPageLoader.GetString("ViewRightMenuAnnot_Delete");
  898. public string T_RightMenuAnnotDefault = App.MainPageLoader.GetString("ViewRightMenuAnnot_Default");
  899. public string T_RightMenuFreetextAnnotFontColor = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_FontColor");
  900. public string T_RightMenuFreetextAnnotFillColor = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_FillColor");
  901. public string T_RightMenuFreetextAnnotFont = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_Font");
  902. public string T_RightMenuFreetextAnnotFontCourierNew = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotFont_CourierNew");
  903. public string T_RightMenuFreetextAnnotFontHelvetica = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotFont_Helvetica");
  904. public string T_RightMenuFreetextAnnotFontTimesNewRoman = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotFont_TimesNewRoman");
  905. public string T_RightMenuFreetextAnnotTextAlignment = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_TextAlignment");
  906. public string T_RightMenuFreetextAnnotTextAlignmentAlignLeft = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_AlignLeft");
  907. public string T_RightMenuFreetextAnnotTextAlignmentAlignCenter = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_AlignCenter");
  908. public string T_RightMenuFreetextAnnotTextAlignmentAlignRight = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_AlignRight");
  909. public string T_RightMenuFreetextAnnotTextAlignmentFullyJustified = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_FullyJustified");
  910. private void InitSelectFreeHandAnnotMenu()
  911. {
  912. var popMenu = new ContextMenu();
  913. PopMenu pop = new PopMenu(popMenu);
  914. var menuItem = new MenuItem();
  915. menuItem.Name = "FreeHandCopy";
  916. menuItem.Header = T_RightMenuAnnotCopy;
  917. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  918. menuItem = new MenuItem();
  919. menuItem.Name = "FreeHandCut";
  920. menuItem.Header = T_RightMenuAnnotCut;
  921. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  922. menuItem = new MenuItem();
  923. menuItem.Name = "FreeHandPaste";
  924. menuItem.Header = T_RightMenuAnnotPaste;
  925. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  926. menuItem = new MenuItem();
  927. menuItem.Name = "FreeHandDelete";
  928. menuItem.Header = T_RightMenuAnnotDelete;
  929. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  930. pop.AddItem(GetSeparator());
  931. menuItem = new MenuItem();
  932. menuItem.Name = "FreeHandDefault";
  933. menuItem.Header = T_RightMenuAnnotDefault;
  934. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  935. FreeHandAnnotPopMenu = pop;
  936. }
  937. /// <summary>
  938. /// 文本
  939. /// </summary>
  940. private void InitSelectFreeTextAnnotMenu()
  941. {
  942. var popMenu = new ContextMenu();
  943. PopMenu pop = new PopMenu(popMenu);
  944. var menuItem = new MenuItem();
  945. menuItem.Name = "FreeTextCopy";
  946. menuItem.Header = T_RightMenuAnnotCopy;
  947. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  948. menuItem = new MenuItem();
  949. menuItem.Name = "FreeTextCut";
  950. menuItem.Header = T_RightMenuAnnotCut;
  951. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  952. menuItem = new MenuItem();
  953. menuItem.Name = "FreeTextPaste";
  954. menuItem.Header = T_RightMenuAnnotPaste;
  955. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  956. menuItem = new MenuItem();
  957. menuItem.Name = "FreeTextDelete";
  958. menuItem.Header = T_RightMenuAnnotDelete;
  959. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  960. pop.AddItem(GetSeparator());
  961. menuItem = new MenuItem();
  962. menuItem.Name = "FreeTextColor";
  963. menuItem.Header = T_RightMenuFreetextAnnotFontColor;
  964. menuItem.Tag = "FontColor";
  965. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  966. menuItem = new MenuItem();
  967. menuItem.Name = "FreeTextColor";
  968. menuItem.Header = T_RightMenuFreetextAnnotFillColor;
  969. menuItem.Tag = "FillColor";
  970. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  971. menuItem = new MenuItem();
  972. menuItem.Name = "FreeTextFontFamily";
  973. menuItem.Header = T_RightMenuFreetextAnnotFont;
  974. pop.AddItem(menuItem);
  975. var family = TextFont.GetFamily();
  976. foreach (var item in family)
  977. {
  978. RadioButton familyRdioBtn = new RadioButton();
  979. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  980. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  981. familyRdioBtn.Name = item.ValueStr;
  982. familyRdioBtn.Tag = item.ValueStr;
  983. familyRdioBtn.GroupName = "FontFamily";
  984. familyRdioBtn.Content = item.Content;
  985. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  986. }
  987. menuItem = new MenuItem();
  988. menuItem.Name = "FreeTextAglin";
  989. menuItem.Header = T_RightMenuFreetextAnnotTextAlignment;
  990. pop.AddItem(menuItem);
  991. var radioButton = new RadioButton();
  992. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  993. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  994. radioButton.Name = "FreeTextAglinLeft";
  995. radioButton.Tag = "Left";
  996. radioButton.GroupName = "Aglin";
  997. radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentAlignLeft;
  998. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  999. radioButton = new RadioButton();
  1000. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  1001. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  1002. radioButton.Name = "FreeTextAglinCenter";
  1003. radioButton.Tag = "Center";
  1004. radioButton.GroupName = "Aglin";
  1005. radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentAlignCenter;
  1006. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  1007. radioButton = new RadioButton();
  1008. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  1009. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  1010. radioButton.Name = "FreeTextAglinRight";
  1011. radioButton.Tag = "Right";
  1012. radioButton.GroupName = "Aglin";
  1013. radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentAlignRight;
  1014. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  1015. radioButton = new RadioButton();
  1016. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  1017. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  1018. radioButton.Name = "FreeTextAglinJustify";
  1019. radioButton.Tag = "Justify";
  1020. radioButton.GroupName = "Aglin";
  1021. radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentFullyJustified;
  1022. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  1023. menuItem = new MenuItem();
  1024. menuItem.Name = "FreeHandDefault";
  1025. menuItem.Header = T_RightMenuAnnotDefault;
  1026. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  1027. FreeTextAnnotPopMenu = pop;
  1028. }
  1029. /// <summary>
  1030. /// 多选注释
  1031. /// </summary>
  1032. private void InitSelectMultiAnnotMenu()
  1033. {
  1034. var popMenu = new ContextMenu();
  1035. PopMenu pop = new PopMenu(popMenu);
  1036. var menuItem = new MenuItem();
  1037. menuItem.Name = "MultiCopy";
  1038. menuItem.Header = T_RightMenuAnnotCopy;
  1039. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  1040. menuItem = new MenuItem();
  1041. menuItem.Name = "MultiCut";
  1042. menuItem.Header = T_RightMenuAnnotCut;
  1043. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  1044. menuItem = new MenuItem();
  1045. menuItem.Name = "MultiDelete";
  1046. menuItem.Header = T_RightMenuAnnotDelete;
  1047. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  1048. MultiAnnotPopMenu = pop;
  1049. }
  1050. private Separator GetSeparator()
  1051. {
  1052. Separator separator = new Separator();
  1053. separator.Height = 1;
  1054. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  1055. separator.BorderThickness = new Thickness(1);
  1056. return separator;
  1057. }
  1058. private void BindingPDFViewerHandler()
  1059. {
  1060. //来自PDFViewer的响应事件
  1061. if (PDFViewer != null)
  1062. {
  1063. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  1064. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  1065. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  1066. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  1067. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  1068. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  1069. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  1070. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  1071. //CommandManager.AddPreviewExecutedHandler(PDFViewer, PreviewExcute);
  1072. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1073. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  1074. }
  1075. }
  1076. private void UnBindingPDFViewerHandler()
  1077. {
  1078. if (PDFViewer != null)
  1079. {
  1080. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  1081. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  1082. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  1083. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  1084. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1085. }
  1086. }
  1087. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  1088. {
  1089. if (!PDFViewer.ToolManager.HasTool)
  1090. {
  1091. HookShapeIsCheck = true;
  1092. HookShapeIsCheck = false;
  1093. }
  1094. }
  1095. //在注释工具的状态下,右键菜单
  1096. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  1097. {
  1098. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  1099. return;
  1100. //if ((UIElement)sender != null)
  1101. //{
  1102. // CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  1103. //}
  1104. switch (e.CommandType)
  1105. {
  1106. case CommandType.Context:
  1107. if (e.AnnotEventArgsList.Count > 0)
  1108. {
  1109. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  1110. {
  1111. //绑定标记密文处右键菜单
  1112. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  1113. }
  1114. else
  1115. {
  1116. if (e.AnnotEventArgsList.Count == 1)
  1117. {
  1118. var selectedAnnot = e.AnnotEventArgsList[0];
  1119. switch (selectedAnnot.EventType)
  1120. {
  1121. case AnnotArgsType.AnnotFreehand:
  1122. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1123. break;
  1124. case AnnotArgsType.AnnotFreeText:
  1125. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1126. break;
  1127. }
  1128. }
  1129. else
  1130. {
  1131. bool isHigh = true;//是否为高亮
  1132. foreach (var item in e.AnnotEventArgsList)
  1133. {
  1134. if (isHightAnnot(item) == false)
  1135. {
  1136. isHigh = false;
  1137. break;
  1138. }
  1139. }
  1140. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  1141. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  1142. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  1143. }
  1144. }
  1145. if (e.PopupMenu != null)
  1146. {
  1147. e.Handle = true;
  1148. }
  1149. }
  1150. else
  1151. {
  1152. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  1153. {
  1154. if (e.PopupMenu != null)
  1155. {
  1156. e.Handle = true;
  1157. }
  1158. }
  1159. else
  1160. {
  1161. e.PopupMenu = ViewerContextMenu(sender);
  1162. if (e.PopupMenu != null)
  1163. {
  1164. e.Handle = true;
  1165. }
  1166. }
  1167. }
  1168. break;
  1169. }
  1170. }
  1171. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1172. {
  1173. if (e != null && e.DrawContext != null)
  1174. {
  1175. Rect hoverRect = new Rect(
  1176. e.PaintRect.Left - 2,
  1177. e.PaintRect.Top - 2,
  1178. e.PaintRect.Width + 4,
  1179. e.PaintRect.Height + 4);
  1180. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1181. hoverPen.DashStyle = DashStyles.Dash;
  1182. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1183. }
  1184. CloseAnnotToolTip();
  1185. }
  1186. private Rect oldRect = new Rect(0, 0, 0, 0);
  1187. private void CloseAnnotToolTip()
  1188. {
  1189. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1190. {
  1191. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1192. oldTips.IsOpen = false;
  1193. oldTips.Visibility = Visibility.Collapsed;
  1194. PDFViewer.ToolTip = null;
  1195. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1196. oldRect = new Rect(0, 0, 0, 0);
  1197. }
  1198. }
  1199. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1200. {
  1201. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1202. {
  1203. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1204. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1205. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1206. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1207. {
  1208. CloseAnnotToolTip();
  1209. }
  1210. }
  1211. }
  1212. private ContextMenu ViewerContextMenu(object sender)
  1213. {
  1214. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1215. ViewerContextMenu_Loaded(contextMenu, sender);
  1216. return contextMenu;
  1217. }
  1218. private void ViewerContextMenu_Loaded(object sender, object e, Visibility visibility = Visibility.Collapsed)
  1219. {
  1220. ContextMenu contextMenu = sender as ContextMenu;
  1221. contextMenu.DataContext = viewContentViewModel;
  1222. if (contextMenu.Items.Count > 0)
  1223. {
  1224. int index = PDFViewer.CurrentIndex;
  1225. //检测是否已存在相同数据
  1226. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  1227. foreach (var item in contextMenu.Items)
  1228. {
  1229. if (item is Separator separator)
  1230. {
  1231. separator.Visibility = visibility;
  1232. }
  1233. if (item is MenuItem menuItem1)
  1234. {
  1235. //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
  1236. //{
  1237. // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  1238. //}
  1239. switch (menuItem1.Tag.ToString())
  1240. {
  1241. case "Paste":
  1242. //粘贴
  1243. //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
  1244. //{
  1245. // menuItem1.IsEnabled = false;
  1246. // menuItem1.Opacity = 0.5;
  1247. //}
  1248. //else
  1249. //{
  1250. // menuItem1.IsEnabled = true;
  1251. // menuItem1.Opacity = 1;
  1252. //}
  1253. menuItem1.CommandTarget = (UIElement)e;
  1254. menuItem1.Command = ApplicationCommands.Paste;
  1255. break;
  1256. case "AddAnnotation":
  1257. menuItem1.Visibility = visibility;
  1258. break;
  1259. case "HiddenAnnot":
  1260. menuItem1.Visibility = visibility;
  1261. break;
  1262. case "DisplayAnnot":
  1263. menuItem1.Visibility = visibility;
  1264. break;
  1265. case "AddBookMark":
  1266. menuItem1.Visibility = visibility;
  1267. break;
  1268. case "DelBookMark":
  1269. menuItem1.Visibility = visibility;
  1270. break;
  1271. case "ToolMode":
  1272. menuItem1.Visibility = visibility;
  1273. break;
  1274. case "ReadModel":
  1275. menuItem1.Visibility = visibility;
  1276. break;
  1277. case "UnReadModel":
  1278. menuItem1.Visibility = visibility;
  1279. break;
  1280. case "ViewZoom":
  1281. menuItem1.Visibility = visibility;
  1282. break;
  1283. case "PageDisplay":
  1284. menuItem1.Visibility = visibility;
  1285. break;
  1286. case "Select":
  1287. menuItem1.Click -= Select_Click;
  1288. menuItem1.Click += Select_Click;
  1289. break;
  1290. case "Print":
  1291. menuItem1.Command = viewContentViewModel.PrintCommand;
  1292. break;
  1293. }
  1294. }
  1295. }
  1296. }
  1297. }
  1298. private void Select_Click(object sender, RoutedEventArgs e)
  1299. {
  1300. if (viewContentViewModel.OpenBOTA == false)
  1301. {
  1302. viewContentViewModel.OpenBOTA = true;
  1303. }
  1304. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1305. if (isBook == false)
  1306. {
  1307. bOTAContent.TabItemSearch.IsSelected = true;
  1308. }
  1309. }
  1310. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1311. {
  1312. bool isTabItem = false;
  1313. bOTAContentViewModel = null;
  1314. bOTAContent = null;
  1315. if (regions.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  1316. {
  1317. var views = regions.Regions[viewContentViewModel.BOTARegionName].Views;
  1318. var model = views.FirstOrDefault(q => q is BOTAContent);
  1319. if (model is BOTAContent bOTAContent1)
  1320. {
  1321. bOTAContent = bOTAContent1;
  1322. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1323. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1324. {
  1325. isTabItem = true;
  1326. }
  1327. }
  1328. //foreach (var item in views)
  1329. //{
  1330. // if (item is BOTAContent bOTAContent1)
  1331. // {
  1332. // bOTAContent = bOTAContent1;
  1333. // bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1334. // if (bOTAContentViewModel.CurrentBar == tabItemText)
  1335. // {
  1336. // isTabItem = true;
  1337. // break;
  1338. // }
  1339. // }
  1340. //}
  1341. }
  1342. return isTabItem;
  1343. }
  1344. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  1345. {
  1346. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  1347. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  1348. annot.EventType == AnnotArgsType.AnnotHighlight ||
  1349. annot.EventType == AnnotArgsType.AnnotStrikeout
  1350. )
  1351. {
  1352. return true;
  1353. }
  1354. else
  1355. {
  1356. return false;
  1357. }
  1358. }
  1359. //注释编辑事件
  1360. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1361. {
  1362. bool IsSign = false;
  1363. if (e != null && e.Count > 0)
  1364. {
  1365. int i = 0;
  1366. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  1367. for ( i = 0; i < e.Count; i++)
  1368. {
  1369. AnnotEditEvent editEvent = e[i];
  1370. int pageindex = editEvent.PageIndex;
  1371. int annotindex = editEvent.AnnotIndex;
  1372. switch (editEvent.EditAction)
  1373. {
  1374. case ActionType.Add:
  1375. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  1376. {
  1377. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  1378. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1379. }
  1380. else
  1381. {
  1382. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1383. }
  1384. //if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreehand)
  1385. //{
  1386. // //if (IsSelectShape)
  1387. // //{
  1388. // if (ShapeNames.Count == 0) { continue; }
  1389. // if (ShapeNames[i] == "Freehand") { continue; }
  1390. // try
  1391. // {
  1392. // viewContentViewModel.FillAndSign.Add(new FillAndSignIsShape(pageindex, annotindex, ShapeNames[i]));
  1393. // //PDFViewer.SelectAnnotation(pageindex, annotindex);
  1394. // continue;
  1395. // }
  1396. // catch { continue; }
  1397. // //}
  1398. //}
  1399. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotStamp)
  1400. {
  1401. if (Shape != "None")
  1402. {
  1403. if (Shape == "Sign")
  1404. {
  1405. viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(pageindex, annotindex));
  1406. continue;
  1407. }
  1408. else
  1409. {
  1410. viewContentViewModel.FillAndSign.Add(new FillAndSignIsShape(pageindex, annotindex, Shape));
  1411. PDFViewer.SelectAnnotation(pageindex, annotindex);
  1412. }
  1413. }
  1414. }
  1415. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreehand&&i==0) {
  1416. PDFViewer.SelectAnnotation(pageindex, annotindex);
  1417. }
  1418. //else
  1419. //{
  1420. // foreach (var point in viewContentViewModel.FillAndSign)
  1421. // {
  1422. // if (pageindex == point.PageIndex && annotindex == point.AnnotIndex)
  1423. // {
  1424. // point.Shape= Shape;
  1425. // }
  1426. // }
  1427. //}
  1428. break;
  1429. case ActionType.Del:
  1430. break;
  1431. }
  1432. }
  1433. if (i>1)
  1434. {
  1435. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1436. }
  1437. }
  1438. }
  1439. //选中和非选中注释,右键菜单
  1440. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  1441. {
  1442. if (e != null)
  1443. {
  1444. IsClickNull = false;
  1445. var annot = e.AnnotItemsList[0];
  1446. if (annot != null)
  1447. {
  1448. if (e.AnnotItemsList.Count == 1)
  1449. {
  1450. //IsEdit = false;
  1451. //IsAnnotCreateReset:是否为创建注释的状态
  1452. if (e.IsAnnotCreateReset == false)
  1453. {
  1454. GetSelectedAnnots(e);
  1455. //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
  1456. //PDFViewer.SetToolParam(annot);
  1457. }
  1458. else
  1459. {
  1460. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  1461. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  1462. annot.EventType != AnnotArgsType.AnnotUnderline &&
  1463. annot.EventType != AnnotArgsType.AnnotHighlight &&
  1464. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  1465. annot.EventType != AnnotArgsType.AnnotLink &&
  1466. annot.EventType != AnnotArgsType.AnnotFreehand &&
  1467. annot.EventType != AnnotArgsType.AnnotSticky
  1468. )
  1469. {
  1470. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  1471. {
  1472. foreach (var item in ToolExpandDict)
  1473. {
  1474. if (item.Value == e.AnnotItemsList[0].EventType)
  1475. {
  1476. annot = null;//新建注释时,回到默认值
  1477. FindAnnotTypeKey(item.Key, ref annot);
  1478. break;
  1479. }
  1480. }
  1481. }
  1482. }
  1483. //else
  1484. //PDFViewer.SetToolParam(annot);
  1485. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  1486. if (isRightMenuAddAnnot)
  1487. {
  1488. ShowPropertyPanel(false);
  1489. }
  1490. else
  1491. {
  1492. ShowPropertyPanel();
  1493. }
  1494. }
  1495. }
  1496. else
  1497. {
  1498. bool isDifferentAnnotTyle = false;
  1499. var lastAnnot = annot;
  1500. foreach (var item in e.AnnotItemsList)
  1501. {
  1502. if (lastAnnot.EventType != item.EventType)
  1503. {
  1504. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  1505. {
  1506. lastAnnot = item;
  1507. continue;
  1508. }
  1509. lastAnnot = item;
  1510. isDifferentAnnotTyle = true;
  1511. break;
  1512. }
  1513. }
  1514. if (isDifferentAnnotTyle)
  1515. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1516. else
  1517. GetSelectedAnnots(e);
  1518. }
  1519. }
  1520. }
  1521. else
  1522. {
  1523. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  1524. {
  1525. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1526. }
  1527. else { IsClickNull = true; }
  1528. }
  1529. }
  1530. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  1531. {
  1532. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  1533. annot.EventType == AnnotArgsType.AnnotSquare ||
  1534. annot.EventType == AnnotArgsType.AnnotLine
  1535. )
  1536. {
  1537. return true;
  1538. }
  1539. else
  1540. {
  1541. return false;
  1542. }
  1543. }
  1544. private void GetSelectedAnnots(AnnotAttribEvent e)
  1545. {
  1546. IsEdit = true;
  1547. var annot = e.AnnotItemsList[0];
  1548. switch (annot.EventType)
  1549. {
  1550. case AnnotArgsType.AnnotFreeText:
  1551. GetFreetext(e.AnnotItemsList);
  1552. break;
  1553. case AnnotArgsType.AnnotFreehand:
  1554. bool isDifferen = false;
  1555. foreach (var point in viewContentViewModel.FillAndSign)
  1556. {
  1557. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  1558. {
  1559. isDifferen = true;
  1560. break;
  1561. }
  1562. else
  1563. {
  1564. isDifferen = false;
  1565. }
  1566. }
  1567. if (!isDifferen)
  1568. {
  1569. foreach (var point in viewContentViewModel.AnnotSignatures)
  1570. {
  1571. if (annot.PageIndex == point.Item1 && annot.AnnotIndex == point.Item2)
  1572. {
  1573. isDifferen = true;
  1574. break;
  1575. }
  1576. else
  1577. {
  1578. isDifferen = false;
  1579. }
  1580. }
  1581. if (isDifferen)
  1582. {
  1583. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); return;
  1584. }
  1585. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); return;
  1586. }
  1587. GetFreehand(e.AnnotItemsList);
  1588. break;
  1589. }
  1590. }
  1591. private void ShowPropertyPanel(bool show = true)
  1592. {
  1593. viewContentViewModel.IsPropertyOpen = show;
  1594. }
  1595. //private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  1596. //{
  1597. // if (e.Command == ApplicationCommands.Paste)
  1598. // {
  1599. // ShapeNames.Clear();
  1600. // Trace.WriteLine("几次" + 1);
  1601. // var items = PDFViewer.GetCopyAnnotData();
  1602. // foreach (var item in items)
  1603. // {
  1604. // bool IsShape = false;
  1605. // foreach (var point in viewContentViewModel.FillAndSign)
  1606. // {
  1607. // if ((item as FreehandAnnotArgs).PageIndex == point.PageIndex && (item as FreehandAnnotArgs).AnnotIndex == point.AnnotIndex)
  1608. // {
  1609. // ShapeNames.Add(point.Shape);
  1610. // Trace.WriteLine("woshi什么" + point.Shape);
  1611. // IsShape = true;
  1612. // continue;
  1613. // }
  1614. // }
  1615. // if (!IsShape) {
  1616. // ShapeNames.Add("Freehand");
  1617. // Trace.WriteLine("woshi什么" + "Freehand");
  1618. // }
  1619. // }
  1620. // }
  1621. // if (e.Command == ApplicationCommands.Copy)
  1622. // {
  1623. // IsCopyShape = false;
  1624. // }
  1625. //}
  1626. //private void PreviewExcuteView(object sender, ExecutedRoutedEventArgs e)
  1627. //{
  1628. // if (e.Command == ApplicationCommands.Paste)
  1629. // {
  1630. // IsSelectShape = true;
  1631. // }
  1632. // if (e.Command == ApplicationCommands.Copy)
  1633. // {
  1634. // IsCopyShape = false;
  1635. // }
  1636. //}
  1637. #region Navigation
  1638. public bool IsNavigationTarget(NavigationContext navigationContext)
  1639. {
  1640. return true;
  1641. }
  1642. public void OnNavigatedFrom(NavigationContext navigationContext)
  1643. {
  1644. UnBindingPDFViewerHandler();
  1645. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1646. ViewerContextMenu_Loaded(contextMenu, null, Visibility.Visible);
  1647. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1648. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1649. ShowPropertyPanel(false);
  1650. }
  1651. public void OnNavigatedTo(NavigationContext navigationContext)
  1652. {
  1653. IsFillAndSign = true;
  1654. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1655. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1656. BindingPDFViewerHandler();
  1657. HookShapeIsCheck = true;
  1658. HookShapeIsCheck = false;
  1659. ShowPropertyPanel(false);
  1660. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1661. // InitCheckedEvent("RbtnTick");
  1662. IsEdit = false;
  1663. }
  1664. #endregion
  1665. }
  1666. }