FillAndSignContentViewModel.cs 81 KB

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