AnnotToolContentViewModel.Function.cs 49 KB

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