FillAndSignContentViewModel.cs 82 KB

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