AnnotToolContentViewModel.Function.cs 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Microsoft.Office.Core;
  7. using Microsoft.Win32;
  8. using PDF_Office.CustomControl;
  9. using PDF_Office.Helper;
  10. using PDF_Office.Model;
  11. using PDF_Office.Model.BOTA;
  12. using PDF_Office.Properties;
  13. using PDF_Office.ViewModels.BOTA;
  14. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  15. using PDF_Office.Views.BOTA;
  16. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  17. using PDFSettings;
  18. using Prism.Mvvm;
  19. using Prism.Regions;
  20. using Prism.Services.Dialogs;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.IO;
  24. using System.Linq;
  25. using System.Text;
  26. using System.Threading.Tasks;
  27. using System.Windows;
  28. using System.Windows.Controls;
  29. using System.Windows.Forms;
  30. using System.Windows.Input;
  31. using System.Windows.Media;
  32. using static Dropbox.Api.Sharing.ListFileMembersIndividualResult;
  33. using ContextMenu = System.Windows.Controls.ContextMenu;
  34. using HorizontalAlignment = System.Windows.HorizontalAlignment;
  35. using MenuItem = System.Windows.Controls.MenuItem;
  36. using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
  37. namespace PDF_Office.ViewModels.Tools
  38. {
  39. //文件说明:初始化注释工具的数据,注释工具,菜单响应事件
  40. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  41. {
  42. #region 初始化
  43. #region 初始化数据
  44. //初始化注释的属性值,并存在本地缓存数据集里
  45. private void InitDefaultValue()
  46. {
  47. InitAnnotHighlight();
  48. InitAnnotUnderline();
  49. InitAnnotSquiggly();
  50. InitAnnotStrikeout();
  51. }
  52. private void InitAnnotHighlight()
  53. {
  54. var annotate = Settings.Default.AppProperties.Annotate;
  55. if(annotate != null)
  56. {
  57. HighLightColor = new SolidColorBrush(annotate.HighLightColor);
  58. HighLightOpacity = 1;
  59. }
  60. else
  61. {
  62. HighLightColor = new SolidColorBrush(Colors.Red);
  63. HighLightOpacity = 1;
  64. }
  65. }
  66. private void InitAnnotUnderline()
  67. {
  68. var annotate = Settings.Default.AppProperties.Annotate;
  69. if (annotate != null)
  70. {
  71. UnderLineColor = new SolidColorBrush(annotate.UnderLineColor);
  72. HighLightOpacity = 1;
  73. }
  74. else
  75. {
  76. UnderLineColor = new SolidColorBrush(Colors.Red);
  77. UnderLineOpacity = 1;
  78. }
  79. }
  80. private void InitAnnotSquiggly()
  81. {
  82. var annotate = Settings.Default.AppProperties.Annotate;
  83. if (annotate != null)
  84. {
  85. SquigglyColor = new SolidColorBrush(annotate.StrikethroughColor);
  86. SquigglyOpacity = 1;
  87. }
  88. else
  89. {
  90. SquigglyColor = new SolidColorBrush(Colors.Red);
  91. SquigglyOpacity = 1;
  92. }
  93. }
  94. private void InitAnnotStrikeout()
  95. {
  96. var annotate = Settings.Default.AppProperties.Annotate;
  97. if (annotate != null)
  98. {
  99. StrikeoutColor = new SolidColorBrush(annotate.NoteAnnoteColor);
  100. StrikeoutOpacity = 1;
  101. }
  102. else
  103. {
  104. StrikeoutColor = new SolidColorBrush(Colors.Red);
  105. StrikeoutOpacity = 1;
  106. }
  107. }
  108. //用来记录选中和创建注释的标识
  109. private void InitToolDict()
  110. {
  111. ToolExpandDict.Add("SnapshotEdit", AnnotArgsType.SnapshotWithEditTool);
  112. ToolExpandDict.Add("HighLight", AnnotArgsType.AnnotHighlight);
  113. ToolExpandDict.Add("UnderLine", AnnotArgsType.AnnotUnderline);
  114. ToolExpandDict.Add("Squiggly", AnnotArgsType.AnnotSquiggly);
  115. ToolExpandDict.Add("Strikeout", AnnotArgsType.AnnotStrikeout);
  116. ToolExpandDict.Add("Freehand", AnnotArgsType.AnnotFreehand);
  117. ToolExpandDict.Add("Freetext", AnnotArgsType.AnnotFreeText);
  118. ToolExpandDict.Add("StickyNote", AnnotArgsType.AnnotSticky);
  119. ToolExpandDict.Add("Rect", AnnotArgsType.AnnotSquare);
  120. ToolExpandDict.Add("Circle", AnnotArgsType.AnnotCircle);
  121. ToolExpandDict.Add("Arrow", AnnotArgsType.AnnotLine);
  122. ToolExpandDict.Add("Line", AnnotArgsType.AnnotLine);
  123. ToolExpandDict.Add("Link", AnnotArgsType.AnnotLink);
  124. }
  125. #endregion 初始化数据
  126. #endregion 初始化
  127. #region 注释工具
  128. //注释工具
  129. private void FindAnnotTypeKey(string tag, ref AnnotHandlerEventArgs annotArgs, bool isRightMenuAdd = false)
  130. {
  131. switch (tag)
  132. {
  133. case "SnapshotEdit"://内容选择
  134. annotArgs = GetSnapshotEdit();
  135. break;
  136. case "HighLight"://字体高亮
  137. annotArgs = GetHighLight();
  138. break;
  139. case "UnderLine"://下划线
  140. annotArgs = GetUnderLine();
  141. break;
  142. case "Squiggly"://波浪线
  143. annotArgs = GetSquiggly();
  144. break;
  145. case "Strikeout"://删除线
  146. annotArgs = GetStrikeout();
  147. break;
  148. case "Freehand"://手绘
  149. annotArgs = GetFreehand();
  150. break;
  151. case "Freetext"://文本
  152. annotArgs = GetFreetext();
  153. break;
  154. case "StickyNote"://便签
  155. annotArgs = GetStickyNote();
  156. break;
  157. case "Rect"://矩形
  158. annotArgs = GetRect();
  159. break;
  160. case "Circle"://圆
  161. annotArgs = GetCircle();
  162. break;
  163. case "Arrow"://箭头
  164. case "Line"://线
  165. annotArgs = GetArrowLine(tag);
  166. break;
  167. case "Stamp"://图章
  168. annotArgs = GetStamp();
  169. break;
  170. case "Image":
  171. annotArgs = GetImage();
  172. break;
  173. case "Signature"://签名
  174. annotArgs = GetSignature();
  175. PDFViewer.SetMouseMode(MouseModes.PanTool);//清空其他注释
  176. break;
  177. case "Link"://链接
  178. viewContentViewModel.IsRightMenuCreateLink = isRightMenuAdd;
  179. annotArgs = GetLink();
  180. break;
  181. }
  182. }
  183. /// <summary>
  184. /// 高亮注释
  185. /// </summary>
  186. private AnnotHandlerEventArgs GetHighLight(List<AnnotHandlerEventArgs> selectedArgs = null)
  187. {
  188. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  189. TextHighlightAnnotArgs highlightArgs = null;
  190. if (selectedArgs == null || selectedArgs.Count == 0)
  191. {
  192. highlightArgs = new TextHighlightAnnotArgs();
  193. highlightArgs.Transparency = highLightOpacity;
  194. highlightArgs.Color = (highLightColor as SolidColorBrush).Color;
  195. if (highlightArgs != null)
  196. {
  197. selectedArgs = new List<AnnotHandlerEventArgs>();
  198. selectedArgs.Add(highlightArgs);
  199. }
  200. }
  201. else
  202. {
  203. highlightArgs = selectedArgs[0] as TextHighlightAnnotArgs;
  204. }
  205. annotAttribsList[AnnotAttrib.Color] = highlightArgs.Color;
  206. annotAttribsList[AnnotAttrib.Transparency] = highlightArgs.Transparency;
  207. annotAttribsList[AnnotAttrib.NoteText] = highlightArgs.Content;
  208. AddToPropertyPanel("TextAnnotProperty", "HighLight", selectedArgs, annotAttribsList);
  209. return highlightArgs;
  210. }
  211. /// <summary>
  212. /// 链接
  213. /// </summary>
  214. /// <param name="selectedArgs">所选中的注释</param>
  215. /// <param name="annotAttribEvent">注释属性列表</param>
  216. public AnnotHandlerEventArgs GetLink(List<AnnotHandlerEventArgs> selectedArgs = null, AnnotAttribEvent annotAttribEvent = null)
  217. {
  218. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  219. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  220. if (selectedArgs != null && selectedArgs.Count > 1)
  221. {
  222. linkArgs = selectedArgs[0] as LinkAnnotArgs;
  223. }
  224. else
  225. {
  226. linkArgs.URI = string.Empty;
  227. linkArgs.LinkType = LINK_TYPE.GOTO;
  228. linkArgs.DestIndex = -1;
  229. if (linkArgs != null)
  230. {
  231. selectedArgs = new List<AnnotHandlerEventArgs>();
  232. selectedArgs.Add(linkArgs);
  233. }
  234. }
  235. annotAttribsList[AnnotAttrib.LinkType] = linkArgs.LinkType;
  236. annotAttribsList[AnnotAttrib.LinkUri] = linkArgs.URI;
  237. annotAttribsList[AnnotAttrib.LinkDestIndx] = linkArgs.DestIndex;
  238. AddToPropertyPanel("LinkAnnotProperty", "Link", selectedArgs, annotAttribsList, annotAttribEvent);
  239. return linkArgs;
  240. }
  241. /// <summary>
  242. /// 下划线
  243. /// </summary>
  244. /// <param name="selectedArgs"></param>
  245. private AnnotHandlerEventArgs GetUnderLine(List<AnnotHandlerEventArgs> selectedArgs = null)
  246. {
  247. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  248. TextUnderlineAnnotArgs underlineArgs = null;
  249. if (selectedArgs == null || selectedArgs.Count == 0)
  250. {
  251. underlineArgs = new TextUnderlineAnnotArgs();
  252. underlineArgs.Transparency = UnderLineOpacity;
  253. underlineArgs.Color = (UnderLineColor as SolidColorBrush).Color;
  254. if (underlineArgs != null)
  255. {
  256. selectedArgs = new List<AnnotHandlerEventArgs>();
  257. selectedArgs.Add(underlineArgs);
  258. }
  259. }
  260. else
  261. {
  262. underlineArgs = selectedArgs[0] as TextUnderlineAnnotArgs;
  263. }
  264. annotAttribsList[AnnotAttrib.Color] = underlineArgs.Color;
  265. annotAttribsList[AnnotAttrib.Transparency] = underlineArgs.Transparency;
  266. annotAttribsList[AnnotAttrib.NoteText] = underlineArgs.Content;
  267. AddToPropertyPanel("TextAnnotProperty", "UnderLine", selectedArgs, annotAttribsList);
  268. return underlineArgs;
  269. }
  270. /// <summary>
  271. /// 波浪线
  272. /// </summary>
  273. /// <param name="selectedArgs"></param>
  274. /// <returns></returns>
  275. private AnnotHandlerEventArgs GetSquiggly(List<AnnotHandlerEventArgs> selectedArgs = null)
  276. {
  277. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  278. TextSquigglyAnnotArgs squigglyArgs = null;
  279. if (selectedArgs == null || selectedArgs.Count == 0)
  280. {
  281. squigglyArgs = new TextSquigglyAnnotArgs();
  282. squigglyArgs.Transparency = SquigglyOpacity;
  283. squigglyArgs.Color = (squigglyColor as SolidColorBrush).Color;
  284. if (squigglyArgs != null)
  285. {
  286. selectedArgs = new List<AnnotHandlerEventArgs>();
  287. selectedArgs.Add(squigglyArgs);
  288. }
  289. }
  290. else
  291. {
  292. squigglyArgs = selectedArgs[0] as TextSquigglyAnnotArgs;
  293. }
  294. annotAttribsList[AnnotAttrib.Color] = squigglyArgs.Color;
  295. annotAttribsList[AnnotAttrib.Transparency] = squigglyArgs.Transparency;
  296. annotAttribsList[AnnotAttrib.NoteText] = squigglyArgs.Content;
  297. AddToPropertyPanel("TextAnnotProperty", "Squiggly", selectedArgs, annotAttribsList);
  298. return squigglyArgs;
  299. }
  300. /// <summary>
  301. /// 删除线
  302. /// </summary>
  303. /// <param name="selectedArgs"></param>
  304. /// <returns></returns>
  305. private AnnotHandlerEventArgs GetStrikeout(List<AnnotHandlerEventArgs> selectedArgs = null)
  306. {
  307. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  308. TextStrikeoutAnnotArgs strikeoutArgs = null;
  309. if (selectedArgs == null || selectedArgs.Count == 0)
  310. {
  311. strikeoutArgs = new TextStrikeoutAnnotArgs();
  312. strikeoutArgs.Transparency = strikeoutOpacity;
  313. strikeoutArgs.Color = (strikeoutColor as SolidColorBrush).Color;
  314. if (strikeoutArgs != null)
  315. {
  316. selectedArgs = new List<AnnotHandlerEventArgs>();
  317. selectedArgs.Add(strikeoutArgs);
  318. }
  319. }
  320. else
  321. {
  322. strikeoutArgs = selectedArgs[0] as TextStrikeoutAnnotArgs;
  323. }
  324. annotAttribsList[AnnotAttrib.Color] = strikeoutArgs.Color;
  325. annotAttribsList[AnnotAttrib.Transparency] = strikeoutArgs.Transparency;
  326. annotAttribsList[AnnotAttrib.NoteText] = strikeoutArgs.Content;
  327. AddToPropertyPanel("TextAnnotProperty", "Strikeout", selectedArgs, annotAttribsList);
  328. return strikeoutArgs;
  329. }
  330. /// <summary>
  331. /// 手绘
  332. /// </summary>
  333. /// <param name="selectedArgs"></param>
  334. /// <returns></returns>
  335. private AnnotHandlerEventArgs GetFreehand(List<AnnotHandlerEventArgs> selectedArgs = null)
  336. {
  337. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  338. FreehandAnnotArgs freehandArgs = null;
  339. if (selectedArgs == null || selectedArgs.Count == 0)
  340. {
  341. freehandArgs = new FreehandAnnotArgs();
  342. var annotate = Settings.Default.AppProperties.Annotate;
  343. if(annotate != null)
  344. {
  345. freehandArgs.InkColor = annotate.FreeHandColor;
  346. }
  347. else
  348. {
  349. freehandArgs.InkColor = Color.FromRgb(0x38, 0xE0, 0x2E);
  350. }
  351. freehandArgs.Transparency = 1;
  352. freehandArgs.LineWidth = 2;
  353. if (freehandArgs != null)
  354. {
  355. selectedArgs = new List<AnnotHandlerEventArgs>();
  356. selectedArgs.Add(freehandArgs);
  357. }
  358. }
  359. else
  360. {
  361. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  362. }
  363. annotAttribsList[AnnotAttrib.Color] = freehandArgs.InkColor;
  364. annotAttribsList[AnnotAttrib.Transparency] = freehandArgs.Transparency;
  365. annotAttribsList[AnnotAttrib.Thickness] = freehandArgs.LineWidth;
  366. annotAttribsList[AnnotAttrib.NoteText] = freehandArgs.Content;
  367. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs, annotAttribsList);
  368. return freehandArgs;
  369. }
  370. /// <summary>
  371. /// 文本
  372. /// </summary>
  373. /// <param name="selectedArgs"></param>
  374. /// <returns></returns>
  375. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  376. {
  377. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  378. FreeTextAnnotArgs freetextArgs = null;
  379. TextAlignment textAlignment;
  380. if (selectedArgs == null || selectedArgs.Count == 0)
  381. {
  382. freetextArgs = new FreeTextAnnotArgs();
  383. var annotate = Settings.Default.AppProperties.Annotate;
  384. if (annotate != null)
  385. {
  386. freetextArgs.FontColor = annotate.TextAnnoteColor;
  387. }
  388. else
  389. {
  390. freetextArgs.FontColor = Colors.Black;
  391. }
  392. freetextArgs.Align = TextAlignment.Left;
  393. freetextArgs.BgColor = Colors.Transparent;
  394. freetextArgs.FontFamily = new FontFamily(Settings.Default.AppProperties.Annotate.TextFontFamaily);
  395. freetextArgs.FontColor = Colors.Black;
  396. freetextArgs.FontSize = 14;
  397. freetextArgs.Transparency = 1;
  398. freetextArgs.LineColor = Colors.Black;
  399. freetextArgs.LineWidth = 0;
  400. freetextArgs.TextContent = string.Empty;
  401. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  402. if (align == 0)
  403. textAlignment = TextAlignment.Left;
  404. else if (align == 1)
  405. textAlignment = TextAlignment.Center;
  406. else
  407. textAlignment = TextAlignment.Right;
  408. if (freetextArgs != null)
  409. {
  410. selectedArgs = new List<AnnotHandlerEventArgs>();
  411. selectedArgs.Add(freetextArgs);
  412. }
  413. }
  414. else
  415. {
  416. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  417. textAlignment = freetextArgs.Align;
  418. }
  419. annotAttribsList[AnnotAttrib.Color] = freetextArgs.LineColor;
  420. annotAttribsList[AnnotAttrib.FillColor] = freetextArgs.BgColor;
  421. annotAttribsList[AnnotAttrib.Thickness] = freetextArgs.LineWidth;
  422. annotAttribsList[AnnotAttrib.Transparency] = freetextArgs.Transparency;
  423. annotAttribsList[AnnotAttrib.FontColor] = freetextArgs.FontColor;
  424. annotAttribsList[AnnotAttrib.FontSize] = freetextArgs.FontSize;
  425. annotAttribsList[AnnotAttrib.FontFamily] = freetextArgs.FontFamily;
  426. annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
  427. annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
  428. annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
  429. annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
  430. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
  431. return freetextArgs;
  432. }
  433. /// <summary>
  434. /// 便签
  435. /// </summary>
  436. /// <param name="selectedArgs"></param>
  437. /// <returns></returns>
  438. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  439. {
  440. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  441. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  442. if (selectedArgs == null || selectedArgs.Count == 0)
  443. {
  444. var annotate = Settings.Default.AppProperties.Annotate;
  445. if (annotate != null)
  446. {
  447. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  448. }
  449. else
  450. {
  451. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  452. }
  453. stickyAnnotArgs.StickyNote = string.Empty;
  454. stickyAnnotArgs.Transparency = 1;
  455. if (stickyAnnotArgs != null)
  456. {
  457. selectedArgs = new List<AnnotHandlerEventArgs>();
  458. selectedArgs.Add(stickyAnnotArgs);
  459. }
  460. }
  461. else
  462. {
  463. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  464. }
  465. annotAttribsList[AnnotAttrib.Color] = stickyAnnotArgs.Color;
  466. annotAttribsList[AnnotAttrib.Transparency] = stickyAnnotArgs.Transparency;
  467. annotAttribsList[AnnotAttrib.NoteText] = stickyAnnotArgs.StickyNote;
  468. annotAttribsList[AnnotAttrib.StickyIcon] = stickyAnnotArgs.IconName;
  469. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  470. if (stickyAnnotArgs != null)
  471. stickyAnnotArgsList.Add(stickyAnnotArgs);
  472. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs, annotAttribsList);
  473. return stickyAnnotArgs;
  474. }
  475. /// <summary>
  476. /// 矩形
  477. /// </summary>
  478. /// <param name="selectedArgs"></param>
  479. /// <returns></returns>
  480. private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  481. {
  482. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  483. SquareAnnotArgs squareArgs = null;
  484. if (selectedArgs == null || selectedArgs.Count == 0)
  485. {
  486. squareArgs = new SquareAnnotArgs();
  487. var annotate = Settings.Default.AppProperties.Annotate;
  488. if (annotate != null)
  489. {
  490. squareArgs.BgColor = annotate.RectangleFillColor;
  491. squareArgs.LineColor = annotate.RectangleBorderColor;
  492. }
  493. else
  494. {
  495. squareArgs.LineColor = Colors.Red;
  496. squareArgs.BgColor = Colors.Red;
  497. }
  498. squareArgs.LineWidth = 1;
  499. squareArgs.Transparency = 1;
  500. squareArgs.LineDash = DashStyles.Solid;
  501. squareArgs.Content = string.Empty;
  502. if (squareArgs != null)
  503. {
  504. selectedArgs = new List<AnnotHandlerEventArgs>();
  505. selectedArgs.Add(squareArgs);
  506. }
  507. }
  508. else
  509. {
  510. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  511. }
  512. annotAttribsList[AnnotAttrib.Color] = squareArgs.LineColor;
  513. annotAttribsList[AnnotAttrib.FillColor] = squareArgs.BgColor;
  514. annotAttribsList[AnnotAttrib.LineStyle] = squareArgs.LineDash;
  515. annotAttribsList[AnnotAttrib.Thickness] = squareArgs.LineWidth;
  516. annotAttribsList[AnnotAttrib.Transparency] = squareArgs.Transparency;
  517. annotAttribsList[AnnotAttrib.NoteText] = squareArgs.Content;
  518. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs, annotAttribsList);
  519. return squareArgs;
  520. }
  521. /// <summary>
  522. /// 圆
  523. /// </summary>
  524. /// <param name="selectedArgs"></param>
  525. /// <returns></returns>
  526. private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  527. {
  528. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  529. CircleAnnotArgs circleAnnotArgs = null;
  530. if (selectedArgs == null || selectedArgs.Count == 0)
  531. {
  532. circleAnnotArgs = new CircleAnnotArgs();
  533. var annotate = Settings.Default.AppProperties.Annotate;
  534. if (annotate != null)
  535. {
  536. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  537. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  538. }
  539. else
  540. {
  541. circleAnnotArgs.LineColor = Colors.Red;
  542. circleAnnotArgs.BgColor = Colors.Red;
  543. }
  544. circleAnnotArgs.LineWidth = 1;
  545. circleAnnotArgs.Transparency = 1;
  546. circleAnnotArgs.LineDash = DashStyles.Solid;
  547. circleAnnotArgs.Content = string.Empty;
  548. if (circleAnnotArgs != null)
  549. {
  550. selectedArgs = new List<AnnotHandlerEventArgs>();
  551. selectedArgs.Add(circleAnnotArgs);
  552. }
  553. }
  554. else
  555. {
  556. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  557. }
  558. annotAttribsList[AnnotAttrib.Color] = circleAnnotArgs.LineColor;
  559. annotAttribsList[AnnotAttrib.FillColor] = circleAnnotArgs.BgColor;
  560. annotAttribsList[AnnotAttrib.LineStyle] = circleAnnotArgs.LineDash;
  561. annotAttribsList[AnnotAttrib.Thickness] = circleAnnotArgs.LineWidth;
  562. annotAttribsList[AnnotAttrib.Transparency] = circleAnnotArgs.Transparency;
  563. annotAttribsList[AnnotAttrib.NoteText] = circleAnnotArgs.Content;
  564. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs, annotAttribsList);
  565. return circleAnnotArgs;
  566. }
  567. /// <summary>
  568. /// 箭头 线
  569. /// </summary>
  570. /// <param name="TagStr"></param>
  571. /// <param name="selectedArgs"></param>
  572. /// <returns></returns>
  573. private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  574. {
  575. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  576. LineAnnotArgs lineArgs = new LineAnnotArgs();
  577. if (selectedArgs == null || selectedArgs.Count == 0)
  578. {
  579. var annotate = Settings.Default.AppProperties.Annotate;
  580. if (annotate != null)
  581. {
  582. lineArgs.LineColor = annotate.LineColor;
  583. }
  584. else
  585. {
  586. lineArgs.LineColor = Colors.Red;
  587. }
  588. lineArgs.LineColor = Colors.Red;
  589. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  590. if (TagStr == "Line")
  591. {
  592. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  593. }
  594. else
  595. {
  596. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  597. }
  598. lineArgs.LineDash = DashStyles.Solid;
  599. lineArgs.LineWidth = 1;
  600. lineArgs.Transparency = 1;
  601. lineArgs.Content = string.Empty;
  602. if (lineArgs != null)
  603. {
  604. selectedArgs = new List<AnnotHandlerEventArgs>();
  605. selectedArgs.Add(lineArgs);
  606. }
  607. }
  608. else
  609. {
  610. lineArgs = selectedArgs[0] as LineAnnotArgs;
  611. }
  612. annotAttribsList[AnnotAttrib.Color] = lineArgs.LineColor;
  613. annotAttribsList[AnnotAttrib.LineStart] = lineArgs.HeadLineType;
  614. annotAttribsList[AnnotAttrib.LineEnd] = lineArgs.TailLineType;
  615. annotAttribsList[AnnotAttrib.LineStyle] = lineArgs.LineDash;
  616. annotAttribsList[AnnotAttrib.Thickness] = lineArgs.LineWidth;
  617. annotAttribsList[AnnotAttrib.Transparency] = lineArgs.Transparency;
  618. annotAttribsList[AnnotAttrib.NoteText] = lineArgs.Content;
  619. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs, annotAttribsList);
  620. return lineArgs;
  621. }
  622. /// <summary>
  623. /// 图章
  624. /// </summary>
  625. /// <returns></returns>
  626. private AnnotHandlerEventArgs GetStamp()
  627. {
  628. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  629. stampAnnotArgs.Opacity = 1;
  630. stampAnnotArgs.StampText = "APPROVED";
  631. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  632. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  633. annotAttribsList[AnnotAttrib.Transparency] = stampAnnotArgs.Opacity;
  634. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  635. if (stampAnnotArgs != null)
  636. stampAnnotArgsList.Add(stampAnnotArgs);
  637. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList, annotAttribsList);
  638. return stampAnnotArgs;
  639. }
  640. /// <summary>
  641. /// 签名
  642. /// </summary>
  643. /// <returns></returns>
  644. private AnnotHandlerEventArgs GetSignature()
  645. {
  646. AddToPropertyPanel("SignatureAnnotProperty");
  647. return null;
  648. }
  649. private AnnotHandlerEventArgs GetImage()
  650. {
  651. Dictionary<AnnotAttrib, object> annotAttribsList = new Dictionary<AnnotAttrib, object>();
  652. StampAnnotArgs stampArgs = new StampAnnotArgs();
  653. stampArgs.Opacity = 1;
  654. stampArgs.Type = StampType.IMAGE_STAMP;
  655. OpenFileDialog openFileDialog = new OpenFileDialog();
  656. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  657. if (openFileDialog.ShowDialog() == true)
  658. {
  659. stampArgs.ImagePath = openFileDialog.FileName;
  660. }
  661. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  662. if (stampArgs != null)
  663. stampArgsList.Add(stampArgs);
  664. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList, annotAttribsList);
  665. return stampArgs;
  666. }
  667. /// <summary>
  668. /// 内容选择
  669. /// </summary>
  670. /// <param name="annotBtn"></param>
  671. /// <returns></returns>
  672. private AnnotHandlerEventArgs GetSnapshotEdit()
  673. {
  674. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  675. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  676. snapshotArgs.ControlPointColor = Colors.White;
  677. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  678. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  679. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  680. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  681. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  682. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  683. #region to do
  684. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  685. //snapshotArgs.ToolPanel = snapMenu;
  686. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  687. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  688. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  689. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  690. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  691. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  692. #endregion to do
  693. return snapshotArgs;
  694. }
  695. #endregion 注释工具
  696. #region 菜单
  697. private void AnnotToolMenu_Click(object sender, RoutedEventArgs e)
  698. {
  699. if (sender is MenuItem clickMenu && clickMenu.CommandParameter is AnnotCommandArgs)
  700. {
  701. AnnotCommandArgs annotCommand = clickMenu.CommandParameter as AnnotCommandArgs;
  702. switch (clickMenu.Tag.ToString())
  703. {
  704. case "HighLight"://字体高亮
  705. TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
  706. highlightArgs.ClientRect = annotCommand.TextRect;
  707. highlightArgs.Content = annotCommand.Text;
  708. highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
  709. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  710. PDFViewer.SetToolParam(highlightArgs);
  711. PDFViewer.SetMouseMode(MouseModes.PanTool);
  712. break;
  713. case "UnderLine"://下划线
  714. TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
  715. underlineArgs.ClientRect = annotCommand.TextRect;
  716. underlineArgs.Content = annotCommand.Text;
  717. underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
  718. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  719. PDFViewer.SetToolParam(underlineArgs);
  720. PDFViewer.SetMouseMode(MouseModes.PanTool);
  721. break;
  722. case "Strikeout"://删除线
  723. TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
  724. strikeoutArgs.ClientRect = annotCommand.TextRect;
  725. strikeoutArgs.Content = annotCommand.Text;
  726. strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
  727. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  728. PDFViewer.SetToolParam(strikeoutArgs);
  729. PDFViewer.SetMouseMode(MouseModes.PanTool);
  730. break;
  731. case "Freetext"://文本
  732. FreeTextAnnotArgs textArgs = (FreeTextAnnotArgs)GetFreetext();
  733. textArgs.ClientRect = annotCommand.TextRect;
  734. //textArgs.Transparency = 1;
  735. //textArgs.BgColor = Colors.Transparent;
  736. //textArgs.LineColor = Colors.Red;
  737. //textArgs.LineWidth = 2;
  738. textArgs.TextContent = annotCommand.Text;
  739. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, textArgs);
  740. break;
  741. case "StickyNote"://便签
  742. StickyAnnotArgs stickyAnnotArgs = (StickyAnnotArgs)GetStickyNote();
  743. stickyAnnotArgs.ClientRect = annotCommand.TextRect;
  744. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, stickyAnnotArgs);
  745. break;
  746. case "Rect"://矩形
  747. SquareAnnotArgs squareAnnotArgs = (SquareAnnotArgs)GetRect();
  748. squareAnnotArgs.ClientRect = annotCommand.TextRect;
  749. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, squareAnnotArgs);
  750. break;
  751. case "Circle"://圆
  752. CircleAnnotArgs circleAnnotArgs = (CircleAnnotArgs)GetCircle();
  753. circleAnnotArgs.ClientRect = annotCommand.TextRect;
  754. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, circleAnnotArgs);
  755. break;
  756. case "Line"://线
  757. LineAnnotArgs lineAnnotArgs = (LineAnnotArgs)GetArrowLine(clickMenu.Tag.ToString());
  758. lineAnnotArgs.ClientRect = annotCommand.TextRect;
  759. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Left, annotCommand.TextRect.Top));
  760. lineAnnotArgs.LinePoints.Add(new Point(annotCommand.TextRect.Right, annotCommand.TextRect.Bottom));
  761. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, lineAnnotArgs);
  762. break;
  763. case "Link"://链接
  764. LinkAnnotArgs linkArgs = new LinkAnnotArgs();
  765. linkArgs.ClientRect = annotCommand.TextRect;
  766. linkArgs.URI = string.Empty;
  767. linkArgs.LinkType = LINK_TYPE.GOTO;
  768. linkArgs.DestIndex = annotCommand.PageIndex;
  769. PDFViewer.CreatePageAnnot(annotCommand.PageIndex, linkArgs);
  770. BtnLinkIsChecked = true;
  771. List<AnnotHandlerEventArgs> lists = new List<AnnotHandlerEventArgs>();
  772. lists.Add(linkArgs);
  773. AnnotHandlerEventArgs annotArgs = GetLink(lists);
  774. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  775. PDFViewer.SetToolParam(annotArgs);
  776. viewContentViewModel.IsPropertyOpen = true;
  777. break;
  778. case "OutLine":
  779. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemOutLine");
  780. if (isTabItemAnnotation == false)
  781. {
  782. bOTAContent.TabItemOutLine.IsSelected = true;
  783. }
  784. OutLineControlViewModel outLineControlViewModel = GetOutLineControlViewModel(bOTAContentViewModel, out OutLineControl outLineControl);
  785. if (outLineControlViewModel != null && outLineControl != null)
  786. {
  787. string str = null;
  788. if (string.IsNullOrEmpty(annotCommand.Text))
  789. {
  790. str = (annotCommand.PageIndex + 1).ToString();
  791. }
  792. else
  793. {
  794. str = annotCommand.Text;
  795. }
  796. OutlineNode outline = outLineControl.AddOutlineNode(str);
  797. CPDFOutline result = outline.Outline;
  798. if (result != null)
  799. {
  800. outLineControlViewModel.SetTitle(result, str);
  801. outLineControlViewModel.Updata(false);
  802. //outLineControl.IsReName = true;
  803. //if (outLineControl.OutlineView.SelectedItem is OutlineNode selectOutLine)
  804. //{
  805. // outLineControl.ReNameOutlineNode = outline;
  806. //}
  807. }
  808. }
  809. break;
  810. case "ExportPicture":
  811. ExportPicture_MenuItemClick();
  812. break;
  813. }
  814. //ShowPropertyPanel(false);
  815. }
  816. }
  817. private void ExportPicture_MenuItemClick()
  818. {
  819. //图片提取
  820. try
  821. {
  822. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  823. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  824. foreach (int pageIndex in imageDict.Keys)
  825. {
  826. imageList = imageDict[pageIndex];
  827. }
  828. string path = PDFViewer.Document.FileName;
  829. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  830. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  831. {
  832. int i = 1;
  833. int pagenum = 1;
  834. string choosePath = folderDialog.SelectedPath;
  835. string sPath = choosePath + "\\" + path + "_Extract Image";
  836. sPath = GetExportPathName(sPath);
  837. if (!Directory.Exists(sPath))
  838. {
  839. Directory.CreateDirectory(sPath);
  840. }
  841. if (Directory.Exists(sPath))
  842. {
  843. foreach (System.Drawing.Bitmap image in imageList)
  844. {
  845. foreach (var item in imageDict.Keys)
  846. {
  847. pagenum = item;
  848. }
  849. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  850. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  851. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  852. i++;
  853. }
  854. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  855. }
  856. }
  857. }
  858. catch (Exception ex) { }
  859. }
  860. public string GetExportPathName(string path)
  861. {
  862. int i = 1;
  863. string outpath = path;
  864. while (Directory.Exists(outpath))
  865. {
  866. outpath = path + $"({i.ToString()})";
  867. i++;
  868. }
  869. return outpath;
  870. }
  871. private string GetNum(int num)
  872. {
  873. if (num % 10 < 1)
  874. {
  875. return "00" + num.ToString();
  876. }
  877. if (num % 10 >= 1 && num % 10 < 10)
  878. {
  879. return "0" + num.ToString();
  880. }
  881. else
  882. {
  883. return num.ToString();
  884. }
  885. }
  886. #region 注释右键菜单事件
  887. //高亮、下划线、删除
  888. private void HightAnnotCopyText_Menu(object obj)
  889. {
  890. if (obj != null && obj as AnnotationHandlerEventArgs != null)
  891. {
  892. var annot = (AnnotationHandlerEventArgs)obj;
  893. System.Windows.Clipboard.SetText(annot.Content);
  894. }
  895. }
  896. //更改为当前注释属性默认值
  897. private void AnnotDefaultValues_Menu(object obj)
  898. {
  899. if (obj != null && obj as AnnotHandlerEventArgs != null)
  900. {
  901. var annot = (AnnotHandlerEventArgs)obj;
  902. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  903. if (annot is TextHighlightAnnotArgs)
  904. {
  905. var color = (annot as TextHighlightAnnotArgs).Color;
  906. Settings.Default.AppProperties.Annotate.HighLightColor = color;
  907. HighLightColor = new SolidColorBrush(color);
  908. }
  909. else if(annot is TextUnderlineAnnotArgs)
  910. {
  911. var color = (annot as TextHighlightAnnotArgs).Color;
  912. Settings.Default.AppProperties.Annotate.UnderLineColor = color;
  913. UnderLineColor = new SolidColorBrush(color);
  914. }
  915. else if (annot is TextStrikeoutAnnotArgs)
  916. {
  917. var color = (annot as TextHighlightAnnotArgs).Color;
  918. Settings.Default.AppProperties.Annotate.StrikethroughColor = color;
  919. StrikeoutColor = new SolidColorBrush(color);
  920. }
  921. else if (annot is FreehandAnnotArgs)
  922. {
  923. var color = (annot as FreehandAnnotArgs).InkColor;
  924. Settings.Default.AppProperties.Annotate.FreeHandColor = color;
  925. }
  926. else if (annot is FreeTextAnnotArgs)
  927. {
  928. var color = (annot as FreeTextAnnotArgs).FontColor;
  929. Settings.Default.AppProperties.Annotate.TextAnnoteColor = color;
  930. }
  931. else if (annot is StickyAnnotArgs)
  932. {
  933. var color = (annot as StickyAnnotArgs).Color;
  934. Settings.Default.AppProperties.Annotate.NoteAnnoteColor = color;
  935. }
  936. else if (annot is SquareAnnotArgs)
  937. {
  938. var bgColor = (annot as SquareAnnotArgs).BgColor;
  939. Settings.Default.AppProperties.Annotate.RectangleFillColor = bgColor;
  940. var borderColor = (annot as SquareAnnotArgs).LineColor;
  941. Settings.Default.AppProperties.Annotate.RectangleBorderColor = borderColor;
  942. }
  943. else if (annot is CircleAnnotArgs)
  944. {
  945. var bgColor = (annot as CircleAnnotArgs).BgColor;
  946. Settings.Default.AppProperties.Annotate.CircleFillColor = bgColor;
  947. var borderColor = (annot as CircleAnnotArgs).LineColor;
  948. Settings.Default.AppProperties.Annotate.CircleBorderColor = borderColor;
  949. }
  950. else if (annot is LineAnnotArgs)
  951. {
  952. var color = (annot as LineAnnotArgs).LineColor;
  953. Settings.Default.AppProperties.Annotate.LineColor = color;
  954. }
  955. Settings.Default.Save();
  956. }
  957. }
  958. //更改颜色
  959. private void AnnotColorPalette_Menu(object obj)
  960. {
  961. if (obj != null && obj as AnnotHandlerEventArgs != null)
  962. {
  963. var annot = obj as AnnotHandlerEventArgs;
  964. var item = new ColorDropBoxPop();
  965. item.DataContext = annot;
  966. item.ColorSelected -= AnnotMenu_ColorSelected;
  967. item.ColorSelected += AnnotMenu_ColorSelected;
  968. System.Windows.Controls.Primitives.Popup popup = new System.Windows.Controls.Primitives.Popup();
  969. popup.Child = item;
  970. popup.PlacementRectangle = new Rect(Mouse.GetPosition(App.Current.MainWindow), new Size(item.Width, item.Height));
  971. popup.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
  972. popup.IsOpen = true;
  973. }
  974. }
  975. private void AnnotMenu_ColorSelected(object sender, Color e)
  976. {
  977. if (sender != null)
  978. {
  979. var annot = (sender as FrameworkElement).DataContext as AnnotHandlerEventArgs;
  980. if (annot != null)
  981. {
  982. if(annot is FreehandAnnotArgs || annot is StickyAnnotArgs || annot is LineAnnotArgs)
  983. {
  984. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  985. AnnotEvent?.UpdateAttrib(AnnotAttrib.Color, e);
  986. AnnotEvent?.UpdateAnnot();
  987. }
  988. else if(annot is FreeTextAnnotArgs)
  989. {
  990. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  991. AnnotEvent?.UpdateAttrib(AnnotAttrib.FontColor, e);
  992. AnnotEvent?.UpdateAnnot();
  993. }
  994. else if (annot is SquareAnnotArgs || annot is CircleAnnotArgs)
  995. {
  996. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  997. AnnotEvent?.UpdateAttrib(AnnotAttrib.FillColor, e);
  998. AnnotEvent?.UpdateAnnot();
  999. }
  1000. }
  1001. }
  1002. }
  1003. //添加笔记
  1004. private void AnnotAddNoteText_Menu(object obj)
  1005. {
  1006. if (obj != null)
  1007. {
  1008. var annot = obj as AnnotHandlerEventArgs;
  1009. if (annot != null)
  1010. {
  1011. DialogParameters value = new DialogParameters();
  1012. value.Add(ParameterNames.Annotation, annot);
  1013. dialogs.ShowDialog(DialogNames.AddAnnotationDialog, value, e =>
  1014. {
  1015. if (e.Result == ButtonResult.OK && e.Parameters != null)
  1016. {
  1017. PDFViewer.UndoManager.CanSave = true;
  1018. if (e.Parameters.ContainsKey(ParameterNames.Annotation) && e.Parameters.ContainsKey(ParameterNames.AnnotEvent))
  1019. {
  1020. }
  1021. }
  1022. });
  1023. }
  1024. }
  1025. }
  1026. //手绘
  1027. private void FreeHandLineStyle_Menu(object obj)
  1028. {
  1029. if (obj != null)
  1030. {
  1031. }
  1032. }
  1033. //文本
  1034. private void FreeTextFontFamily_Menu(object obj)
  1035. {
  1036. if (obj != null)
  1037. {
  1038. }
  1039. }
  1040. private void FreeTextAglin_Menu(object obj)
  1041. {
  1042. if (obj != null)
  1043. {
  1044. if (obj is System.Windows.Controls.RadioButton)
  1045. {
  1046. var btn = obj as System.Windows.Controls.RadioButton;
  1047. var annot = btn.DataContext as AnnotHandlerEventArgs;
  1048. if (annot != null)
  1049. {
  1050. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1051. if (btn.Tag.ToString() == "Left")
  1052. {
  1053. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Left);
  1054. }
  1055. else if(btn.Tag.ToString() == "Center")
  1056. {
  1057. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Center);
  1058. }
  1059. else if (btn.Tag.ToString() == "Right")
  1060. {
  1061. AnnotEvent?.UpdateAttrib(AnnotAttrib.TextAlign, TextAlignment.Right);
  1062. }
  1063. AnnotEvent?.UpdateAnnot();
  1064. }
  1065. }
  1066. }
  1067. }
  1068. //便签
  1069. private void StrikeNoteEditStrike_Menu(object obj)
  1070. {
  1071. if (obj != null)
  1072. {
  1073. }
  1074. }
  1075. //形状
  1076. private void ShapeLineStyle_Menu(object obj)
  1077. {
  1078. if (obj != null)
  1079. {
  1080. if( obj is System.Windows.Controls.RadioButton)
  1081. {
  1082. var btn = obj as System.Windows.Controls.RadioButton;
  1083. var annot = btn.DataContext as AnnotHandlerEventArgs;
  1084. if (annot != null)
  1085. {
  1086. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1087. if (btn.Tag.ToString() == "solid")
  1088. {
  1089. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(true);
  1090. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1091. }
  1092. else
  1093. {
  1094. var dashStyle = AnnotPropertyPanel.GetLineDashStyle(false);
  1095. AnnotEvent?.UpdateAttrib(AnnotAttrib.LineStyle, dashStyle);
  1096. }
  1097. AnnotEvent?.UpdateAnnot();
  1098. }
  1099. }
  1100. }
  1101. }
  1102. private void ShapeLineDirect_Menu(object obj)
  1103. {
  1104. if (obj != null)
  1105. {
  1106. if(obj is MenuItem)
  1107. {
  1108. var btn = obj as MenuItem;
  1109. var annot = btn.DataContext as LineAnnotArgs;
  1110. var AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annot, annot.GetAnnotAttrib());
  1111. if (btn.Tag.ToString() == "ver")
  1112. {
  1113. annot.SetLineVertical();
  1114. }
  1115. else
  1116. {
  1117. annot.SetLineHorizontal();
  1118. }
  1119. }
  1120. }
  1121. }
  1122. private void ShapeDefaultValues_Menu(object obj)
  1123. {
  1124. if (obj != null)
  1125. {
  1126. }
  1127. }
  1128. //图章
  1129. private void StampExportPicture_Menu(object obj)
  1130. {
  1131. if (obj != null)
  1132. {
  1133. }
  1134. }
  1135. #endregion 注释右键菜单事件
  1136. #endregion 菜单
  1137. }
  1138. }