FillAndSignContentViewModel.cs 80 KB

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