AnnotToolContentViewModel.Function.cs 55 KB

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