FillAndSignContentViewModel.cs 77 KB

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