FillAndSignContentViewModel.cs 81 KB

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