FillAndSignContentViewModel.cs 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913
  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. //付费锁
  406. if (!App.IsLogin)
  407. {
  408. dialogs.ShowDialog(DialogNames.IAPCompareDialog);
  409. return;
  410. }
  411. var tag = control.Name;
  412. FindAnnotTypeKey(control.Name, ref annotArgs);
  413. if (control.Name == "RbtnSign") { isTemplateAnnot = true; }
  414. if (tag == "SnapshotEdit")
  415. {
  416. isSnapshotEdit = true;
  417. }
  418. else if (tag == "Signature" || tag == "Stamp")
  419. {
  420. isTemplateAnnot = true;
  421. }
  422. if (annotArgs != null)
  423. {
  424. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  425. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  426. PDFViewer.SetToolParam(annotArgs);
  427. isRightMenuAddAnnot = false;
  428. }
  429. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  430. if (isTemplateAnnot == false && annotArgs == null)
  431. {
  432. PDFViewer.SetMouseMode(MouseModes.PanTool);
  433. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  434. }
  435. else
  436. {
  437. if (isSnapshotEdit == true)
  438. {
  439. ShowPropertyPanel(false);
  440. isSnapshotEdit = false;
  441. }
  442. else
  443. {
  444. ShowPropertyPanel(true);
  445. }
  446. }
  447. }
  448. private void InitCheckedEvent(string e)
  449. {
  450. IsEdit = false;
  451. //NavigateToProperty(control.Name);
  452. //不创建注释,属于注释模板
  453. bool isTemplateAnnot = false;
  454. bool isSnapshotEdit = false;
  455. AnnotHandlerEventArgs annotArgs = null;
  456. var tag = e;
  457. FindAnnotTypeKey(e, ref annotArgs);
  458. if (e == "RbtnSign") { isTemplateAnnot = true; }
  459. if (tag == "SnapshotEdit")
  460. {
  461. isSnapshotEdit = true;
  462. }
  463. else if (tag == "Signature" || tag == "Stamp")
  464. {
  465. isTemplateAnnot = true;
  466. }
  467. if (annotArgs != null)
  468. {
  469. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  470. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  471. PDFViewer.SetToolParam(annotArgs);
  472. isRightMenuAddAnnot = false;
  473. }
  474. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  475. if (isTemplateAnnot == false && annotArgs == null)
  476. {
  477. PDFViewer.SetMouseMode(MouseModes.PanTool);
  478. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  479. }
  480. else
  481. {
  482. if (isSnapshotEdit == true)
  483. {
  484. ShowPropertyPanel(false);
  485. isSnapshotEdit = false;
  486. }
  487. else
  488. {
  489. ShowPropertyPanel(true);
  490. }
  491. }
  492. }
  493. private List<string> ShapeList = new List<string>();
  494. private void InitShapeList()
  495. {
  496. ShapeList.Add("HookShape");
  497. ShapeList.Add("ForkShape");
  498. ShapeList.Add("RectShape");
  499. ShapeList.Add("LineShape");
  500. ShapeList.Add("DotShape");
  501. ShapeList.Add("Sign");
  502. }
  503. //注释工具
  504. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  505. {
  506. LineWidthMultiple = 1;
  507. IsSignPoint = false;
  508. Shape = "None";
  509. switch (tag)
  510. {
  511. case "RbtnDate":
  512. DateOrText = "Freetext";
  513. annotArgs = GetFreetext();
  514. break;
  515. case "RbtnText"://文本
  516. DateOrText = "";
  517. annotArgs = GetFreetext();
  518. break;
  519. case "Freetext"://文本
  520. annotArgs = GetFreetext();
  521. break;
  522. case "RbtnSign"://签名
  523. Shape = "Sign";
  524. PDFViewer.SetMouseMode(MouseModes.PanTool);
  525. annotArgs = GetSignature();
  526. //清空其他注释
  527. break;
  528. case "RbtnTick"://勾
  529. Shape = "HookShape";
  530. ShapePoints = keyShape[Shape];
  531. annotArgs = GetStamp();
  532. break;
  533. case "RbtnFork"://叉
  534. Shape = "ForkShape";
  535. ShapePoints = keyShape[Shape];
  536. annotArgs = GetStamp();
  537. break;
  538. case "RbtnRectangle"://矩形
  539. Shape = "RectShape";
  540. ShapePoints = keyShape[Shape];
  541. annotArgs = GetStamp();
  542. break;
  543. case "RbtnLine"://下划线
  544. Shape = "LineShape";
  545. ShapePoints = keyShape[Shape];
  546. annotArgs = GetStamp();
  547. break;
  548. case "RbtnPoint":
  549. IsSignPoint = true;
  550. Shape = "DotShape";
  551. ShapePoints = keyShape[Shape];
  552. LineWidthMultiple = 5;
  553. annotArgs = GetStamp();
  554. break;
  555. default://图章
  556. break;
  557. }
  558. }
  559. /// <summary>
  560. /// 签名
  561. /// </summary>
  562. /// <returns></returns>
  563. private AnnotHandlerEventArgs GetSignature()
  564. {
  565. AddToPropertyPanel("SignatureAnnotProperty");
  566. return null;
  567. }
  568. /// <summary>
  569. /// 图章
  570. /// </summary>
  571. /// <returns></returns>
  572. private AnnotHandlerEventArgs GetStamp(List<AnnotHandlerEventArgs> selectedArgs = null)
  573. {
  574. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  575. stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  576. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  577. //PDFViewer.SetToolParam(stampArgs);
  578. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  579. //stampAnnotArgs.Opacity = 1;
  580. //stampAnnotArgs.StampText = "APPROVED";
  581. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  582. // stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  583. stampAnnotArgs.IsContinueMode = true;
  584. stampAnnotArgs.IsSignPoint = IsSignPoint;
  585. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  586. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  587. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  588. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  589. if (stampAnnotArgs != null)
  590. stampAnnotArgsList.Add(stampAnnotArgs);
  591. //if (selectedArgs != null) {
  592. //var annot = selectedArgs[0];
  593. //if (annot != null)
  594. //{
  595. // foreach (var item in selectedArgs)
  596. // {
  597. // selectedArgs[selectedArgs.IndexOf(item)] = stampAnnotArgs;
  598. // }
  599. // AddToPropertyPanel("ShapFillProperty", "", selectedArgs, annotAttribsList);
  600. // return stampAnnotArgs;
  601. //}
  602. // }
  603. AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  604. return stampAnnotArgs;
  605. }
  606. public void SetStamp()
  607. {
  608. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  609. double lineWidthMultiple = LineWidthMultiple;
  610. if (Shape == "DotShape") { LineWidthMultiple = 5; }
  611. stampAnnotArgs.SetInkData(ShapePoints, LineWidth * LineWidthMultiple, (SelectColor as SolidColorBrush).Color);
  612. LineWidthMultiple = lineWidthMultiple;
  613. //PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  614. //PDFViewer.SetToolParam(stampArgs);
  615. //StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  616. //stampAnnotArgs.Opacity = 1;
  617. //stampAnnotArgs.StampText = "APPROVED";
  618. //stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  619. stampAnnotArgs.IsContinueMode = true;
  620. stampAnnotArgs.IsSignPoint = IsSignPoint;
  621. stampAnnotArgs.Opacity = FillOpacity;
  622. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  623. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  624. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotStamp);
  625. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  626. if (stampAnnotArgs != null)
  627. stampAnnotArgsList.Add(stampAnnotArgs);
  628. //AddToPropertyPanel("ShapFillProperty", "", stampAnnotArgsList, annotAttribsList);
  629. bool isTemplateAnnot = false;
  630. bool isSnapshotEdit = false;
  631. AnnotHandlerEventArgs annotArgs = stampAnnotArgs;
  632. if (annotArgs != null)
  633. {
  634. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  635. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  636. PDFViewer.SetToolParam(annotArgs);
  637. isRightMenuAddAnnot = false;
  638. }
  639. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  640. if (isTemplateAnnot == false && annotArgs == null)
  641. {
  642. PDFViewer.SetMouseMode(MouseModes.PanTool);
  643. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  644. }
  645. else
  646. {
  647. if (isSnapshotEdit == true)
  648. {
  649. ShowPropertyPanel(false);
  650. isSnapshotEdit = false;
  651. }
  652. else
  653. {
  654. ShowPropertyPanel(true);
  655. }
  656. }
  657. }
  658. /// <summary>
  659. /// 手绘
  660. /// </summary>
  661. /// <param name="selectedArgs"></param>
  662. /// <returns></returns>
  663. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  664. {
  665. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  666. List<AnnotHandlerEventArgs> newSelectedArgs = new List<AnnotHandlerEventArgs>();
  667. FreehandAnnotArgs freehandArgs = null;
  668. if (selectedArgs == null || selectedArgs.Count == 0)
  669. {
  670. freehandArgs = new FreehandAnnotArgs();
  671. var annotate = Settings.Default.AppProperties.Annotate;
  672. if (annotate != null)
  673. {
  674. freehandArgs.InkColor = annotate.FreeHandColor;
  675. }
  676. else
  677. {
  678. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  679. }
  680. 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) } };
  681. freehandArgs.Transparency = 1;
  682. freehandArgs.LineWidth = 2;
  683. if (freehandArgs != null)
  684. {
  685. selectedArgs = new List<AnnotHandlerEventArgs>();
  686. selectedArgs.Add(freehandArgs);
  687. }
  688. }
  689. else
  690. {
  691. //if (IsCopyShape && !IsSelectShape)
  692. //{
  693. // ShapeNames.Clear();
  694. //}
  695. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  696. foreach (var item in selectedArgs)
  697. {
  698. //if (ListPoint((item as FreehandAnnotArgs).RawPointList, ShapePoints)){
  699. foreach (var point in viewContentViewModel.FillAndSign)
  700. {
  701. if ((item as FreehandAnnotArgs).PageIndex == point.PageIndex && (item as FreehandAnnotArgs).AnnotIndex == point.AnnotIndex)
  702. {
  703. //if (IsCopyShape && !IsSelectShape)
  704. //{
  705. // ShapeNames.Add(point.Shape);
  706. // Trace.WriteLine("woshi什么" + point.Shape);
  707. //}
  708. newSelectedArgs.Add(item);
  709. break;
  710. }
  711. }
  712. }
  713. //IsCopyShape = true;
  714. //freehandArgs.RawPointList = ShapePoints;
  715. //freehandArgs.InkColor = (SelectColor as SolidColorBrush).Color;
  716. //freehandArgs.Transparency = 1;
  717. //freehandArgs.LineWidth = LineWidth;
  718. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  719. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  720. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  721. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  722. annotAttribsList[AnnotAttrib.Path] = freehandArgs.RawPointList;
  723. annotAttribsList[AnnotAttrib.Width] = freehandArgs.Width;
  724. annotAttribsList[AnnotAttrib.Height] = freehandArgs.Height;
  725. AddToPropertyPanel("ShapFillProperty", "Freehand", newSelectedArgs, annotAttribsList);
  726. //GetStamp();
  727. return freehandArgs;
  728. }
  729. //annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  730. //annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  731. //annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  732. //annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  733. //AddToPropertyPanel("ShapFillProperty", "Freehand", selectedArgs, annotAttribsList);
  734. return freehandArgs;
  735. }
  736. /// <summary>
  737. /// 文本
  738. /// </summary>
  739. /// <param name="selectedfreetextArgs"></param>
  740. /// <returns></returns>
  741. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  742. {
  743. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  744. FreeTextAnnotArgs freetextArgs = null;
  745. TextAlignment textAlignment;
  746. if (selectedArgs == null || selectedArgs.Count == 0)
  747. {
  748. freetextArgs = new FreeTextAnnotArgs();
  749. freetextArgs.Align = TextAlignment.Left;
  750. freetextArgs.BgColor = Colors.Transparent;
  751. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  752. freetextArgs.FontColor = Colors.Black;
  753. freetextArgs.FontSize = 14;
  754. freetextArgs.Transparency = 1;
  755. freetextArgs.LineColor = Colors.Black;
  756. freetextArgs.LineWidth = 0;
  757. freetextArgs.TextContent = string.Empty;
  758. DefaultAnnotProperty annotProperty = SettingHelper.GetAnnotDefaultProperty(AnnotArgsType.AnnotFreeText);
  759. if (annotProperty != null)
  760. {
  761. freetextArgs.Align = annotProperty.TextAlign;
  762. freetextArgs.BgColor = annotProperty.BackgroundColor;
  763. freetextArgs.FontFamily = new FontFamily(annotProperty.FontFamily);
  764. freetextArgs.FontColor = annotProperty.ForgoundColor;
  765. freetextArgs.FontSize = annotProperty.FontSize;
  766. freetextArgs.Transparency = annotProperty.Opacity;
  767. freetextArgs.LineColor = annotProperty.BorderColor;
  768. freetextArgs.LineWidth = annotProperty.Thickness;
  769. freetextArgs.TextContent = annotProperty.NoteText;
  770. freetextArgs.FontWeight = annotProperty.FontWeight;
  771. freetextArgs.FontStyle = annotProperty.FontStyle;
  772. }
  773. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  774. if (align == 0)
  775. textAlignment = TextAlignment.Left;
  776. else if (align == 1)
  777. textAlignment = TextAlignment.Center;
  778. else
  779. textAlignment = TextAlignment.Right;
  780. if (freetextArgs != null)
  781. {
  782. selectedArgs = new List<AnnotHandlerEventArgs>();
  783. selectedArgs.Add(freetextArgs);
  784. }
  785. }
  786. else
  787. {
  788. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  789. textAlignment = freetextArgs.Align;
  790. }
  791. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  792. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  793. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  794. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  795. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  796. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  797. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  798. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  799. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  800. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  801. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  802. annotAttribsList[AnnotAttrib.Text] = freetextArgs.TextContent;
  803. AddToPropertyPanel("FreetextAnnotProperty", DateOrText, selectedArgs, annotAttribsList);
  804. return freetextArgs;
  805. }
  806. /// <summary>
  807. /// 导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线
  808. /// </summary>
  809. /// <param name="viewContent">对应的注释面板</param>
  810. /// <param name="toolTag">导航到同一个注释xaml时,需要区分某个注释;比如高亮、删除线、下划线</param>
  811. /// <param name="annot">注释</param>
  812. /// <param name="annotAttribsList">更改注释属性的键值对,更改值后会自动记录undoRedo容器里</param>
  813. private void AddToPropertyPanel(string viewContent, string toolTag = null, List<AnnotHandlerEventArgs> annots = null, Dictionary<AnnotAttrib, object> annotAttribsList = null, AnnotAttribEvent annotAttribEvent = null, bool isUpData = false)
  814. {
  815. if (annots != null && annots.Count != 0)
  816. {
  817. propertyPanel.annotlists = annots;
  818. propertyPanel.annot = annots[0];
  819. }
  820. else
  821. {
  822. propertyPanel.annotlists = null;
  823. propertyPanel.annot = null;
  824. }
  825. if (annotAttribsList != null && annotAttribsList.Count != 0 && annots != null && annots.Count != 0)
  826. {
  827. if (annots.Count > 1)
  828. {
  829. if (propertyPanel.AnnotEvents == null)
  830. propertyPanel.AnnotEvents = new List<AnnotAttribEvent>();
  831. propertyPanel.AnnotEvents.Clear();
  832. foreach (var itemAnnot in annots)
  833. {
  834. var eventitem = AnnotAttribEvent.GetAnnotAttribEvent(itemAnnot, annotAttribsList);
  835. eventitem.ClearChangeAttribute();
  836. propertyPanel.AnnotEvents.Add(eventitem);
  837. }
  838. }
  839. var eventitem1 = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annotAttribsList);
  840. eventitem1.ClearChangeAttribute();
  841. propertyPanel.AnnotEvent = eventitem1;
  842. if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
  843. {
  844. propertyPanel.AnnotEvent = annotAttribEvent;
  845. }
  846. }
  847. if (toolTag == "Freetext")
  848. {
  849. propertyPanel.SetIsTextFill(true);
  850. }
  851. else
  852. {
  853. propertyPanel.SetIsTextFill(false);
  854. }
  855. if (string.IsNullOrEmpty(viewContent) == false)
  856. {
  857. if (isUpData) { return; }
  858. if (viewContent == "ShapFillProperty")
  859. {
  860. NavigateToProperty(viewContent, propertyPanel); return;
  861. }
  862. viewContentViewModel.SelectedPrpoertyPanel(viewContent, propertyPanel);
  863. }
  864. }
  865. private void NavigateToProperty(string btnName, AnnotTransfer annotPropertyPanel)
  866. {
  867. NavigationParameters values = new NavigationParameters();
  868. values.Add(ParameterNames.PDFViewer, PDFViewer);
  869. values.Add(ParameterNames.PropertyPanelContentViewModel, annotPropertyPanel);
  870. values.Add("IsFillAndSign", IsFillAndSign);
  871. values.Add("Shape", Shape);
  872. values.Add("FillAndSignContentViewModel", this);
  873. regions.RequestNavigate(RegionNames.PropertyRegionName, btnName, values);
  874. viewContentViewModel.IsPropertyOpen = true;
  875. }
  876. /// <summary>
  877. /// 初始化按钮名称-属性面板字典
  878. /// </summary>
  879. private void InitDictionary()
  880. {
  881. btnToProperty["RbtnText"] = "TextFillProperty";
  882. btnToProperty["RbtnTick"] = "ShapFillProperty";
  883. btnToProperty["RbtnFork"] = "ShapFillProperty";
  884. btnToProperty["RbtnRectangle"] = "ShapFillProperty";
  885. btnToProperty["RbtnLine"] = "ShapFillProperty";
  886. btnToProperty["RbtnPoint"] = "ShapFillProperty";
  887. btnToProperty["RbtnDate"] = "DateFillProperty";
  888. btnToProperty["RbtnSign"] = "";
  889. }
  890. /// <summary>
  891. /// 手绘
  892. /// </summary>
  893. ///
  894. public string T_RightMenuAnnotCopy = App.MainPageLoader.GetString("ViewRightMenuAnnot_Copy");
  895. public string T_RightMenuAnnotCut = App.MainPageLoader.GetString("ViewRightMenuAnnot_Cut");
  896. public string T_RightMenuAnnotPaste = App.MainPageLoader.GetString("ViewRightMenuAnnot_Paste");
  897. public string T_RightMenuAnnotDelete = App.MainPageLoader.GetString("ViewRightMenuAnnot_Delete");
  898. public string T_RightMenuAnnotDefault = App.MainPageLoader.GetString("ViewRightMenuAnnot_Default");
  899. public string T_RightMenuFreetextAnnotFontColor = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_FontColor");
  900. public string T_RightMenuFreetextAnnotFillColor = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_FillColor");
  901. public string T_RightMenuFreetextAnnotFont = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_Font");
  902. public string T_RightMenuFreetextAnnotFontCourierNew = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotFont_CourierNew");
  903. public string T_RightMenuFreetextAnnotFontHelvetica = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotFont_Helvetica");
  904. public string T_RightMenuFreetextAnnotFontTimesNewRoman = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotFont_TimesNewRoman");
  905. public string T_RightMenuFreetextAnnotTextAlignment = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnot_TextAlignment");
  906. public string T_RightMenuFreetextAnnotTextAlignmentAlignLeft = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_AlignLeft");
  907. public string T_RightMenuFreetextAnnotTextAlignmentAlignCenter = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_AlignCenter");
  908. public string T_RightMenuFreetextAnnotTextAlignmentAlignRight = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_AlignRight");
  909. public string T_RightMenuFreetextAnnotTextAlignmentFullyJustified = App.MainPageLoader.GetString("ViewRightMenuFreetextAnnotTextAlignment_FullyJustified");
  910. private void InitSelectFreeHandAnnotMenu()
  911. {
  912. var popMenu = new ContextMenu();
  913. PopMenu pop = new PopMenu(popMenu);
  914. var menuItem = new MenuItem();
  915. menuItem.Name = "FreeHandCopy";
  916. menuItem.Header = T_RightMenuAnnotCopy;
  917. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  918. menuItem = new MenuItem();
  919. menuItem.Name = "FreeHandCut";
  920. menuItem.Header = T_RightMenuAnnotCut;
  921. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  922. menuItem = new MenuItem();
  923. menuItem.Name = "FreeHandPaste";
  924. menuItem.Header = T_RightMenuAnnotPaste;
  925. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  926. menuItem = new MenuItem();
  927. menuItem.Name = "FreeHandDelete";
  928. menuItem.Header = T_RightMenuAnnotDelete;
  929. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  930. pop.AddItem(GetSeparator());
  931. menuItem = new MenuItem();
  932. menuItem.Name = "FreeHandDefault";
  933. menuItem.Header = T_RightMenuAnnotDefault;
  934. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  935. FreeHandAnnotPopMenu = pop;
  936. }
  937. /// <summary>
  938. /// 文本
  939. /// </summary>
  940. private void InitSelectFreeTextAnnotMenu()
  941. {
  942. var popMenu = new ContextMenu();
  943. PopMenu pop = new PopMenu(popMenu);
  944. var menuItem = new MenuItem();
  945. menuItem.Name = "FreeTextCopy";
  946. menuItem.Header = T_RightMenuAnnotCopy;
  947. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  948. menuItem = new MenuItem();
  949. menuItem.Name = "FreeTextCut";
  950. menuItem.Header = T_RightMenuAnnotCut;
  951. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  952. menuItem = new MenuItem();
  953. menuItem.Name = "FreeTextPaste";
  954. menuItem.Header = T_RightMenuAnnotPaste;
  955. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Paste);
  956. menuItem = new MenuItem();
  957. menuItem.Name = "FreeTextDelete";
  958. menuItem.Header = T_RightMenuAnnotDelete;
  959. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  960. pop.AddItem(GetSeparator());
  961. menuItem = new MenuItem();
  962. menuItem.Name = "FreeTextColor";
  963. menuItem.Header = T_RightMenuFreetextAnnotFontColor;
  964. menuItem.Tag = "FontColor";
  965. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  966. menuItem = new MenuItem();
  967. menuItem.Name = "FreeTextColor";
  968. menuItem.Header = T_RightMenuFreetextAnnotFillColor;
  969. menuItem.Tag = "FillColor";
  970. pop.BindingEvent(pop.AddItem(menuItem), AnnotColorPalette_MenuCommand);
  971. menuItem = new MenuItem();
  972. menuItem.Name = "FreeTextFontFamily";
  973. menuItem.Header = T_RightMenuFreetextAnnotFont;
  974. pop.AddItem(menuItem);
  975. var family = TextFont.GetFamily();
  976. foreach (var item in family)
  977. {
  978. RadioButton familyRdioBtn = new RadioButton();
  979. familyRdioBtn.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  980. familyRdioBtn.Background = new SolidColorBrush(Colors.Transparent);
  981. familyRdioBtn.Name = item.ValueStr;
  982. familyRdioBtn.Tag = item.ValueStr;
  983. familyRdioBtn.GroupName = "FontFamily";
  984. familyRdioBtn.Content = item.Content;
  985. pop.BindingEvent(pop.AddChild("FreeTextFontFamily", familyRdioBtn), FreeTextFontFamily_MenuCommand);
  986. }
  987. menuItem = new MenuItem();
  988. menuItem.Name = "FreeTextAglin";
  989. menuItem.Header = T_RightMenuFreetextAnnotTextAlignment;
  990. pop.AddItem(menuItem);
  991. var radioButton = new RadioButton();
  992. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  993. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  994. radioButton.Name = "FreeTextAglinLeft";
  995. radioButton.Tag = "Left";
  996. radioButton.GroupName = "Aglin";
  997. radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentAlignLeft;
  998. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  999. radioButton = new RadioButton();
  1000. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  1001. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  1002. radioButton.Name = "FreeTextAglinCenter";
  1003. radioButton.Tag = "Center";
  1004. radioButton.GroupName = "Aglin";
  1005. radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentAlignCenter;
  1006. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  1007. radioButton = new RadioButton();
  1008. radioButton.Style = App.Current.Resources["MenuRadioBtnStyle"] as Style;
  1009. radioButton.Background = new SolidColorBrush(Colors.Transparent);
  1010. radioButton.Name = "FreeTextAglinRight";
  1011. radioButton.Tag = "Right";
  1012. radioButton.GroupName = "Aglin";
  1013. radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentAlignRight;
  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 = "FreeTextAglinJustify";
  1019. radioButton.Tag = "Justify";
  1020. radioButton.GroupName = "Aglin";
  1021. radioButton.Content = T_RightMenuFreetextAnnotTextAlignmentFullyJustified;
  1022. pop.BindingEvent(pop.AddChild("FreeTextAglin", radioButton), FreeTextAglin_MenuCommand);
  1023. menuItem = new MenuItem();
  1024. menuItem.Name = "FreeHandDefault";
  1025. menuItem.Header = T_RightMenuAnnotDefault;
  1026. pop.BindingEvent(pop.AddItem(menuItem), AnnotDefaultValue_MenuCommand);
  1027. FreeTextAnnotPopMenu = pop;
  1028. }
  1029. /// <summary>
  1030. /// 多选注释
  1031. /// </summary>
  1032. private void InitSelectMultiAnnotMenu()
  1033. {
  1034. var popMenu = new ContextMenu();
  1035. PopMenu pop = new PopMenu(popMenu);
  1036. var menuItem = new MenuItem();
  1037. menuItem.Name = "MultiCopy";
  1038. menuItem.Header = T_RightMenuAnnotCopy;
  1039. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Copy);
  1040. menuItem = new MenuItem();
  1041. menuItem.Name = "MultiCut";
  1042. menuItem.Header = T_RightMenuAnnotCut;
  1043. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Cut);
  1044. menuItem = new MenuItem();
  1045. menuItem.Name = "MultiDelete";
  1046. menuItem.Header = T_RightMenuAnnotDelete;
  1047. pop.BindingEvent(pop.AddItem(menuItem), ApplicationCommands.Delete);
  1048. MultiAnnotPopMenu = pop;
  1049. }
  1050. private Separator GetSeparator()
  1051. {
  1052. Separator separator = new Separator();
  1053. separator.Height = 1;
  1054. separator.BorderBrush = new SolidColorBrush(Color.FromArgb(0x33, 0x00, 0x00, 0x00));
  1055. separator.BorderThickness = new Thickness(1);
  1056. return separator;
  1057. }
  1058. private void BindingPDFViewerHandler()
  1059. {
  1060. //来自PDFViewer的响应事件
  1061. if (PDFViewer != null)
  1062. {
  1063. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  1064. PDFViewer.AnnotActiveHandler += PDFViewer_AnnotActiveHandler;
  1065. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  1066. PDFViewer.AnnotCommandHandler += PDFViewer_AnnotCommandHandler;
  1067. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  1068. PDFViewer.AnnotEditHandler += PDFViewer_AnnotEditHandler;
  1069. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  1070. PDFViewer.AnnotHoverHandler += PDFViewer_AnnotHoverHandler;
  1071. //CommandManager.AddPreviewExecutedHandler(PDFViewer, PreviewExcute);
  1072. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1073. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  1074. }
  1075. }
  1076. private void UnBindingPDFViewerHandler()
  1077. {
  1078. if (PDFViewer != null)
  1079. {
  1080. PDFViewer.AnnotActiveHandler -= PDFViewer_AnnotActiveHandler;
  1081. PDFViewer.AnnotEditHandler -= PDFViewer_AnnotEditHandler;
  1082. PDFViewer.AnnotCommandHandler -= PDFViewer_AnnotCommandHandler;
  1083. PDFViewer.AnnotHoverHandler -= PDFViewer_AnnotHoverHandler;
  1084. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  1085. }
  1086. }
  1087. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  1088. {
  1089. //if (!PDFViewer.ToolManager.HasTool)
  1090. //{
  1091. // HookShapeIsCheck = true;
  1092. // HookShapeIsCheck = false;
  1093. //}
  1094. }
  1095. //在注释工具的状态下,右键菜单
  1096. private void PDFViewer_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  1097. {
  1098. if (e.AnnotEventArgsList == null || (PDFViewer != null && PDFViewer.MouseMode == MouseModes.FormEditTool))
  1099. return;
  1100. //if ((UIElement)sender != null)
  1101. //{
  1102. // CommandManager.AddPreviewExecutedHandler((UIElement)sender, PreviewExcute);
  1103. //}
  1104. switch (e.CommandType)
  1105. {
  1106. case CommandType.Context:
  1107. if (e.AnnotEventArgsList.Count > 0)
  1108. {
  1109. if (App.mainWindowViewModel.SelectedItem.IsInReadctonMode && e.AnnotEventArgsList[0].EventType == AnnotArgsType.AnnotRedaction)
  1110. {
  1111. //绑定标记密文处右键菜单
  1112. events.GetEvent<RedactionCommandEvent>().Publish(new RedactionCommandEventArgs() { UniCode = App.mainWindowViewModel.SelectedItem.Unicode, Sender = sender, args = e });
  1113. }
  1114. else
  1115. {
  1116. if (e.AnnotEventArgsList.Count == 1)
  1117. {
  1118. var selectedAnnot = e.AnnotEventArgsList[0];
  1119. switch (selectedAnnot.EventType)
  1120. {
  1121. case AnnotArgsType.AnnotFreehand:
  1122. e.PopupMenu = FreeHandAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1123. break;
  1124. case AnnotArgsType.AnnotFreeText:
  1125. e.PopupMenu = FreeTextAnnotPopMenu.OpenMenu(selectedAnnot, sender);
  1126. break;
  1127. }
  1128. }
  1129. else
  1130. {
  1131. bool isHigh = true;//是否为高亮
  1132. foreach (var item in e.AnnotEventArgsList)
  1133. {
  1134. if (isHightAnnot(item) == false)
  1135. {
  1136. isHigh = false;
  1137. break;
  1138. }
  1139. }
  1140. MultiAnnotPopMenu.SetVisual("MultiCopy", !isHigh);
  1141. MultiAnnotPopMenu.SetVisual("MultiCut", !isHigh);
  1142. e.PopupMenu = MultiAnnotPopMenu.OpenMenu(e.AnnotEventArgsList, sender);//SelectMultiAnnotMenu(e.AnnotEventArgsList, isHigh);
  1143. }
  1144. }
  1145. if (e.PopupMenu != null)
  1146. {
  1147. e.Handle = true;
  1148. }
  1149. }
  1150. else
  1151. {
  1152. if (e.PressOnSelectedText || e.CommandTarget == TargetType.ImageSelection)
  1153. {
  1154. if (e.PopupMenu != null)
  1155. {
  1156. e.Handle = true;
  1157. }
  1158. }
  1159. else
  1160. {
  1161. e.PopupMenu = ViewerContextMenu(sender);
  1162. if (e.PopupMenu != null)
  1163. {
  1164. e.Handle = true;
  1165. }
  1166. }
  1167. }
  1168. break;
  1169. }
  1170. }
  1171. private void PDFViewer_AnnotHoverHandler(object sender, AnnotHoverData e)
  1172. {
  1173. if (e != null && e.DrawContext != null)
  1174. {
  1175. Rect hoverRect = new Rect(
  1176. e.PaintRect.Left - 2,
  1177. e.PaintRect.Top - 2,
  1178. e.PaintRect.Width + 4,
  1179. e.PaintRect.Height + 4);
  1180. Pen hoverPen = new Pen(new SolidColorBrush(Color.FromArgb(0xff, 0x11, 0x8A, 0xff)), 1);
  1181. hoverPen.DashStyle = DashStyles.Dash;
  1182. e.DrawContext?.DrawRectangle(null, hoverPen, hoverRect);
  1183. }
  1184. CloseAnnotToolTip();
  1185. }
  1186. private Rect oldRect = new Rect(0, 0, 0, 0);
  1187. private void CloseAnnotToolTip()
  1188. {
  1189. if (PDFViewer.ToolTip != null && PDFViewer.ToolTip is ToolTip)
  1190. {
  1191. ToolTip oldTips = (ToolTip)PDFViewer.ToolTip;
  1192. oldTips.IsOpen = false;
  1193. oldTips.Visibility = Visibility.Collapsed;
  1194. PDFViewer.ToolTip = null;
  1195. PDFViewer.MouseMove -= PDFViewer_MouseMove;
  1196. oldRect = new Rect(0, 0, 0, 0);
  1197. }
  1198. }
  1199. private void PDFViewer_MouseMove(object sender, MouseEventArgs e)
  1200. {
  1201. if (sender != null && PDFViewer.ToolTip != null && PDFViewer.Parent != null)
  1202. {
  1203. var newPoint = e.GetPosition(PDFViewer.Parent as ContentControl);
  1204. var isOutw = newPoint.X > (oldRect.X + oldRect.Width + 4);
  1205. var isOuth = newPoint.Y > (oldRect.Y + oldRect.Height + 4);
  1206. if (newPoint.X < oldRect.X || newPoint.Y < oldRect.Y || isOutw || isOuth)
  1207. {
  1208. CloseAnnotToolTip();
  1209. }
  1210. }
  1211. }
  1212. private ContextMenu ViewerContextMenu(object sender)
  1213. {
  1214. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1215. ViewerContextMenu_Loaded(contextMenu, sender);
  1216. return contextMenu;
  1217. }
  1218. private void ViewerContextMenu_Loaded(object sender, object e, Visibility visibility = Visibility.Collapsed)
  1219. {
  1220. ContextMenu contextMenu = sender as ContextMenu;
  1221. contextMenu.DataContext = viewContentViewModel;
  1222. if (contextMenu.Items.Count > 0)
  1223. {
  1224. int index = PDFViewer.CurrentIndex;
  1225. //检测是否已存在相同数据
  1226. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  1227. foreach (var item in contextMenu.Items)
  1228. {
  1229. if (item is Separator separator)
  1230. {
  1231. separator.Visibility = visibility;
  1232. }
  1233. if (item is MenuItem menuItem1)
  1234. {
  1235. //if (menuItem1.Tag.ToString() == "DisplayAnnot" || menuItem1.Tag.ToString() == "HiddenAnnot")
  1236. //{
  1237. // SetMenuItemVisibility(menuItem1, "DisplayAnnot", "HiddenAnnot", isHiddenAnnot);
  1238. //}
  1239. switch (menuItem1.Tag.ToString())
  1240. {
  1241. case "Paste":
  1242. //粘贴
  1243. //if (!ApplicationCommands.Paste.CanExecute(null, (UIElement)sender))
  1244. //{
  1245. // menuItem1.IsEnabled = false;
  1246. // menuItem1.Opacity = 0.5;
  1247. //}
  1248. //else
  1249. //{
  1250. // menuItem1.IsEnabled = true;
  1251. // menuItem1.Opacity = 1;
  1252. //}
  1253. menuItem1.CommandTarget = (UIElement)e;
  1254. menuItem1.Command = ApplicationCommands.Paste;
  1255. break;
  1256. case "AddAnnotation":
  1257. menuItem1.Visibility = visibility;
  1258. break;
  1259. case "HiddenAnnot":
  1260. menuItem1.Visibility = visibility;
  1261. break;
  1262. case "DisplayAnnot":
  1263. menuItem1.Visibility = visibility;
  1264. break;
  1265. case "AddBookMark":
  1266. menuItem1.Visibility = visibility;
  1267. break;
  1268. case "DelBookMark":
  1269. menuItem1.Visibility = visibility;
  1270. break;
  1271. case "ToolMode":
  1272. menuItem1.Visibility = visibility;
  1273. break;
  1274. case "ReadModel":
  1275. menuItem1.Visibility = visibility;
  1276. break;
  1277. case "UnReadModel":
  1278. menuItem1.Visibility = visibility;
  1279. break;
  1280. case "ViewZoom":
  1281. menuItem1.Visibility = visibility;
  1282. break;
  1283. case "PageDisplay":
  1284. menuItem1.Visibility = visibility;
  1285. break;
  1286. case "Select":
  1287. menuItem1.Click -= Select_Click;
  1288. menuItem1.Click += Select_Click;
  1289. break;
  1290. case "Print":
  1291. menuItem1.Command = viewContentViewModel.PrintCommand;
  1292. break;
  1293. }
  1294. }
  1295. }
  1296. }
  1297. }
  1298. private void Select_Click(object sender, RoutedEventArgs e)
  1299. {
  1300. if (viewContentViewModel.OpenBOTA == false)
  1301. {
  1302. viewContentViewModel.OpenBOTA = true;
  1303. }
  1304. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  1305. if (isBook == false)
  1306. {
  1307. bOTAContent.TabItemSearch.IsSelected = true;
  1308. }
  1309. }
  1310. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  1311. {
  1312. bool isTabItem = false;
  1313. bOTAContentViewModel = null;
  1314. bOTAContent = null;
  1315. if (regions.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  1316. {
  1317. var views = regions.Regions[viewContentViewModel.BOTARegionName].Views;
  1318. var model = views.FirstOrDefault(q => q is BOTAContent);
  1319. if (model is BOTAContent bOTAContent1)
  1320. {
  1321. bOTAContent = bOTAContent1;
  1322. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1323. if (bOTAContentViewModel.CurrentBar == tabItemText)
  1324. {
  1325. isTabItem = true;
  1326. }
  1327. }
  1328. //foreach (var item in views)
  1329. //{
  1330. // if (item is BOTAContent bOTAContent1)
  1331. // {
  1332. // bOTAContent = bOTAContent1;
  1333. // bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  1334. // if (bOTAContentViewModel.CurrentBar == tabItemText)
  1335. // {
  1336. // isTabItem = true;
  1337. // break;
  1338. // }
  1339. // }
  1340. //}
  1341. }
  1342. return isTabItem;
  1343. }
  1344. private bool isHightAnnot(AnnotHandlerEventArgs annot)
  1345. {
  1346. if (annot.EventType == AnnotArgsType.AnnotUnderline ||
  1347. annot.EventType == AnnotArgsType.AnnotSquiggly ||
  1348. annot.EventType == AnnotArgsType.AnnotHighlight ||
  1349. annot.EventType == AnnotArgsType.AnnotStrikeout
  1350. )
  1351. {
  1352. return true;
  1353. }
  1354. else
  1355. {
  1356. return false;
  1357. }
  1358. }
  1359. //注释编辑事件
  1360. private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
  1361. {
  1362. bool IsAdd = false;
  1363. if (e != null && e.Count > 0)
  1364. {
  1365. int i = 0;
  1366. Dictionary<int, List<int>> selectAnnotDicts = new Dictionary<int, List<int>>();
  1367. for (i = 0; i < e.Count; i++)
  1368. {
  1369. AnnotEditEvent editEvent = e[i];
  1370. int pageindex = editEvent.PageIndex;
  1371. int annotindex = editEvent.AnnotIndex;
  1372. switch (editEvent.EditAction)
  1373. {
  1374. case ActionType.Add:
  1375. IsAdd = true;
  1376. if (selectAnnotDicts.ContainsKey(editEvent.PageIndex) == false)
  1377. {
  1378. selectAnnotDicts.Add(editEvent.PageIndex, new List<int>());
  1379. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1380. }
  1381. else
  1382. {
  1383. selectAnnotDicts[editEvent.PageIndex].Add(editEvent.AnnotIndex);
  1384. }
  1385. //if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreehand)
  1386. //{
  1387. // //if (IsSelectShape)
  1388. // //{
  1389. // if (ShapeNames.Count == 0) { continue; }
  1390. // if (ShapeNames[i] == "Freehand") { continue; }
  1391. // try
  1392. // {
  1393. // viewContentViewModel.FillAndSign.Add(new FillAndSignIsShape(pageindex, annotindex, ShapeNames[i]));
  1394. // //PDFViewer.SelectAnnotation(pageindex, annotindex);
  1395. // continue;
  1396. // }
  1397. // catch { continue; }
  1398. // //}
  1399. //}
  1400. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotStamp)
  1401. {
  1402. if (Shape != "None")
  1403. {
  1404. if (Shape == "Sign")
  1405. {
  1406. viewContentViewModel.AnnotSignatures.Add(new Tuple<int, int>(pageindex, annotindex));
  1407. continue;
  1408. }
  1409. else
  1410. {
  1411. viewContentViewModel.FillAndSign.Add(new FillAndSignIsShape(pageindex, annotindex, Shape));
  1412. PDFViewer.SelectAnnotation(pageindex, annotindex);
  1413. }
  1414. }
  1415. }
  1416. if (editEvent.EditAnnotArgs.EventType == AnnotArgsType.AnnotFreehand && i == 0)
  1417. {
  1418. PDFViewer.SelectAnnotation(pageindex, annotindex);
  1419. }
  1420. //else
  1421. //{
  1422. // foreach (var point in viewContentViewModel.FillAndSign)
  1423. // {
  1424. // if (pageindex == point.PageIndex && annotindex == point.AnnotIndex)
  1425. // {
  1426. // point.Shape= Shape;
  1427. // }
  1428. // }
  1429. //}
  1430. break;
  1431. case ActionType.Del:
  1432. break;
  1433. }
  1434. }
  1435. if (i > 1 && IsAdd)
  1436. {
  1437. PDFViewer.SelectAnnotation(selectAnnotDicts);
  1438. }
  1439. }
  1440. }
  1441. //选中和非选中注释,右键菜单
  1442. private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)
  1443. {
  1444. if (e != null)
  1445. {
  1446. IsClickNull = false;
  1447. var annot = e.AnnotItemsList[0];
  1448. if (annot != null)
  1449. {
  1450. if (e.AnnotItemsList.Count == 1)
  1451. {
  1452. //IsEdit = false;
  1453. //IsAnnotCreateReset:是否为创建注释的状态
  1454. if (e.IsAnnotCreateReset == false)
  1455. {
  1456. GetSelectedAnnots(e);
  1457. //记录这次选中的注释,之后创建注释会跟随上次选中注释的属性值
  1458. //PDFViewer.SetToolParam(annot);
  1459. }
  1460. else
  1461. {
  1462. //TODO: 设计已重新调整为(仅限高亮注释):修改注释后,会作用到之后添加的注释中。因此先把此逻辑“创建注释后,会自动回到默认值”注释掉
  1463. if (annot.EventType != AnnotArgsType.AnnotStrikeout &&
  1464. annot.EventType != AnnotArgsType.AnnotUnderline &&
  1465. annot.EventType != AnnotArgsType.AnnotHighlight &&
  1466. annot.EventType != AnnotArgsType.AnnotSquiggly &&
  1467. annot.EventType != AnnotArgsType.AnnotLink &&
  1468. annot.EventType != AnnotArgsType.AnnotFreehand &&
  1469. annot.EventType != AnnotArgsType.AnnotSticky
  1470. )
  1471. {
  1472. if (ToolExpandDict.ContainsValue(e.AnnotItemsList[0].EventType))
  1473. {
  1474. foreach (var item in ToolExpandDict)
  1475. {
  1476. if (item.Value == e.AnnotItemsList[0].EventType)
  1477. {
  1478. annot = null;//新建注释时,回到默认值
  1479. FindAnnotTypeKey(item.Key, ref annot);
  1480. break;
  1481. }
  1482. }
  1483. }
  1484. }
  1485. //else
  1486. //PDFViewer.SetToolParam(annot);
  1487. //设计重新调整,阅读页空白处,右键菜单,添加链接,和pro mac一样的效果,不显示属性栏
  1488. if (isRightMenuAddAnnot)
  1489. {
  1490. ShowPropertyPanel(false);
  1491. }
  1492. else
  1493. {
  1494. ShowPropertyPanel();
  1495. }
  1496. }
  1497. }
  1498. else
  1499. {
  1500. bool isDifferentAnnotTyle = false;
  1501. var lastAnnot = annot;
  1502. foreach (var item in e.AnnotItemsList)
  1503. {
  1504. if (lastAnnot.EventType != item.EventType)
  1505. {
  1506. if (isShapAnnot(annot) == true && isShapAnnot(item) == true)
  1507. {
  1508. lastAnnot = item;
  1509. continue;
  1510. }
  1511. lastAnnot = item;
  1512. isDifferentAnnotTyle = true;
  1513. break;
  1514. }
  1515. }
  1516. if (isDifferentAnnotTyle)
  1517. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1518. else
  1519. GetSelectedAnnots(e);
  1520. }
  1521. }
  1522. }
  1523. else
  1524. {
  1525. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  1526. {
  1527. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1528. }
  1529. else { IsClickNull = true; }
  1530. }
  1531. }
  1532. private bool isShapAnnot(AnnotHandlerEventArgs annot)
  1533. {
  1534. if (annot.EventType == AnnotArgsType.AnnotCircle ||
  1535. annot.EventType == AnnotArgsType.AnnotSquare ||
  1536. annot.EventType == AnnotArgsType.AnnotLine
  1537. )
  1538. {
  1539. return true;
  1540. }
  1541. else
  1542. {
  1543. return false;
  1544. }
  1545. }
  1546. private void GetSelectedAnnots(AnnotAttribEvent e)
  1547. {
  1548. IsEdit = true;
  1549. var annot = e.AnnotItemsList[0];
  1550. switch (annot.EventType)
  1551. {
  1552. case AnnotArgsType.AnnotFreeText:
  1553. GetFreetext(e.AnnotItemsList);
  1554. break;
  1555. case AnnotArgsType.AnnotFreehand:
  1556. bool isDifferen = false;
  1557. foreach (var point in viewContentViewModel.FillAndSign)
  1558. {
  1559. if (annot.PageIndex == point.PageIndex && annot.AnnotIndex == point.AnnotIndex)
  1560. {
  1561. isDifferen = true;
  1562. break;
  1563. }
  1564. else
  1565. {
  1566. isDifferen = false;
  1567. }
  1568. }
  1569. if (!isDifferen)
  1570. {
  1571. foreach (var point in viewContentViewModel.AnnotSignatures)
  1572. {
  1573. if (annot.PageIndex == point.Item1 && annot.AnnotIndex == point.Item2)
  1574. {
  1575. isDifferen = true;
  1576. break;
  1577. }
  1578. else
  1579. {
  1580. isDifferen = false;
  1581. }
  1582. }
  1583. if (isDifferen)
  1584. {
  1585. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); return;
  1586. }
  1587. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null); return;
  1588. }
  1589. GetFreehand(e.AnnotItemsList);
  1590. break;
  1591. }
  1592. }
  1593. public void ShowPropertyPanel(bool show = true)
  1594. {
  1595. viewContentViewModel.IsPropertyOpen = show;
  1596. }
  1597. //private void PreviewExcute(object sender, ExecutedRoutedEventArgs e)
  1598. //{
  1599. // if (e.Command == ApplicationCommands.Paste)
  1600. // {
  1601. // ShapeNames.Clear();
  1602. // Trace.WriteLine("几次" + 1);
  1603. // var items = PDFViewer.GetCopyAnnotData();
  1604. // foreach (var item in items)
  1605. // {
  1606. // bool IsShape = false;
  1607. // foreach (var point in viewContentViewModel.FillAndSign)
  1608. // {
  1609. // if ((item as FreehandAnnotArgs).PageIndex == point.PageIndex && (item as FreehandAnnotArgs).AnnotIndex == point.AnnotIndex)
  1610. // {
  1611. // ShapeNames.Add(point.Shape);
  1612. // Trace.WriteLine("woshi什么" + point.Shape);
  1613. // IsShape = true;
  1614. // continue;
  1615. // }
  1616. // }
  1617. // if (!IsShape) {
  1618. // ShapeNames.Add("Freehand");
  1619. // Trace.WriteLine("woshi什么" + "Freehand");
  1620. // }
  1621. // }
  1622. // }
  1623. // if (e.Command == ApplicationCommands.Copy)
  1624. // {
  1625. // IsCopyShape = false;
  1626. // }
  1627. //}
  1628. //private void PreviewExcuteView(object sender, ExecutedRoutedEventArgs e)
  1629. //{
  1630. // if (e.Command == ApplicationCommands.Paste)
  1631. // {
  1632. // IsSelectShape = true;
  1633. // }
  1634. // if (e.Command == ApplicationCommands.Copy)
  1635. // {
  1636. // IsCopyShape = false;
  1637. // }
  1638. //}
  1639. public void ExitAnnotationTool()
  1640. {
  1641. PDFViewer.DisableClearSelectAnnot(false);
  1642. PDFViewer.ClearSelectAnnots();
  1643. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1644. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  1645. {
  1646. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  1647. var annotArgs = new SelectToolArgs();
  1648. PDFViewer.SetToolParam(annotArgs);
  1649. }
  1650. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1651. ShowPropertyPanel(false);
  1652. }
  1653. #region Navigation
  1654. public bool IsNavigationTarget(NavigationContext navigationContext)
  1655. {
  1656. return true;
  1657. }
  1658. public void OnNavigatedFrom(NavigationContext navigationContext)
  1659. {
  1660. UnBindingPDFViewerHandler();
  1661. ContextMenu contextMenu = App.Current.FindResource("ViewerContextMenu") as ContextMenu;
  1662. ViewerContextMenu_Loaded(contextMenu, null, Visibility.Visible);
  1663. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1664. PDFViewer.SetMouseMode(MouseModes.PanTool);
  1665. ShowPropertyPanel(false);
  1666. }
  1667. public void OnNavigatedTo(NavigationContext navigationContext)
  1668. {
  1669. IsFillAndSign = true;
  1670. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  1671. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  1672. BindingPDFViewerHandler();
  1673. ExitAnnotationTool();
  1674. HookShapeIsCheck = true;
  1675. HookShapeIsCheck = false;
  1676. //ShowPropertyPanel(false);
  1677. //PDFViewer.SetMouseMode(MouseModes.PanTool);
  1678. // InitCheckedEvent("RbtnTick");
  1679. IsEdit = false;
  1680. }
  1681. #endregion
  1682. }
  1683. }