AnnotToolContentViewModel.Function.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  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. freetextArgs = selectedArgs[0] as FreeTextAnnotArgs;
  572. textAlignment = freetextArgs.Align;
  573. if (NavigatedToFillAndSignVM(selectedArgs, "Freetext"))
  574. {
  575. return freetextArgs;
  576. }
  577. }
  578. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
  579. return freetextArgs;
  580. }
  581. private FreeTextAnnotArgs SetFreetextArgs(FreeTextAnnotArgs defaultAnnot)
  582. {
  583. FreeTextAnnotArgs freetextArgs = new FreeTextAnnotArgs();
  584. freetextArgs.FontColor = defaultAnnot.FontColor;
  585. freetextArgs.LineColor = defaultAnnot.LineColor;
  586. freetextArgs.BgColor = defaultAnnot.BgColor;
  587. freetextArgs.Transparency = defaultAnnot.Transparency;
  588. freetextArgs.FontFamily = defaultAnnot.FontFamily;
  589. freetextArgs.FontSize = defaultAnnot.FontSize;
  590. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  591. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  592. freetextArgs.LineWidth = defaultAnnot.LineWidth;
  593. freetextArgs.Align = defaultAnnot.Align;
  594. return freetextArgs;
  595. }
  596. private void SelectTextCreateAnnot(FreeTextAnnotArgs freeText)
  597. {
  598. List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
  599. if (selectList != null && selectList.Count > 0)
  600. {
  601. foreach (TextSelectNode selectNode in selectList)
  602. {
  603. FreeTextAnnotArgs textArgs = new FreeTextAnnotArgs();
  604. Rect clientRect = Rect.Empty;
  605. foreach (Rect rawRect in selectNode.RawRect)
  606. {
  607. clientRect.Union(rawRect);
  608. }
  609. if (clientRect.IsEmpty == false)
  610. {
  611. clientRect = new Rect(
  612. clientRect.Left / 72D * 96D,
  613. clientRect.Top / 72D * 96D,
  614. clientRect.Width / 72D * 96D,
  615. clientRect.Height / 72D * 96D);
  616. textArgs.ClientRect = DpiHelpers.GetDpiRelatedRect(clientRect);
  617. //textArgs.Transparency = 1;
  618. //textArgs.BgColor = Colors.Transparent;
  619. //textArgs.LineColor = Colors.Red;
  620. //textArgs.LineWidth = 2;
  621. textArgs.Transparency = freeText.Transparency;
  622. textArgs.BgColor = freeText.BgColor;
  623. textArgs.LineColor = freeText.LineColor;
  624. textArgs.LineWidth = freeText.LineWidth;
  625. textArgs.TextContent = selectNode.SelectText;
  626. PDFViewer.CreatePageAnnot(selectNode.PageIndex, textArgs);
  627. }
  628. break;
  629. }
  630. }
  631. }
  632. //获取选中文字内容的区域大小,以及内容内容所在的页码
  633. private Tuple<int, Rect> DrawRectCreateAnnot()
  634. {
  635. List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
  636. Rect clientRect = Rect.Empty;
  637. int pageIndex = -1;
  638. if (selectList != null && selectList.Count > 0)
  639. {
  640. pageIndex = selectList[0].PageIndex;
  641. }
  642. if (selectList != null && selectList.Count > 0)
  643. {
  644. foreach (TextSelectNode selectNode in selectList)
  645. {
  646. foreach (Rect rawRect in selectNode.RawRect)
  647. {
  648. clientRect.Union(rawRect);
  649. }
  650. int dpi = DpiHelpers.Dpi;
  651. if (clientRect.IsEmpty == false)
  652. {
  653. clientRect = new Rect(
  654. clientRect.Left / 72D * dpi,
  655. clientRect.Top / 72D * dpi,
  656. clientRect.Width / 72D * dpi,
  657. clientRect.Height / 72D * dpi);
  658. }
  659. break;
  660. }
  661. }
  662. if (clientRect != Rect.Empty && pageIndex > -1)
  663. {
  664. return new Tuple<int, Rect>(pageIndex, clientRect);
  665. }
  666. return null;
  667. }
  668. //根据选中的文本内容,来创建指定大小的注释。
  669. private void CreateAnnotFromSelectPageText(AnnotHandlerEventArgs annotArgs)
  670. {
  671. //点击注释工具,在阅读页根据选中的文本内容,创建注释矩形大小
  672. var drawRectTuple = DrawRectCreateAnnot();
  673. if (drawRectTuple != null)
  674. {
  675. annotArgs.ClientRect = drawRectTuple.Item2;
  676. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, annotArgs);
  677. }
  678. }
  679. //Event导航到填写与签名的属性面板
  680. private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
  681. {
  682. if (viewContentViewModel.FillAndSign != null && viewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
  683. {
  684. var annotFillAndSign = viewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.PageIndex == annots[0].PageIndex && temp.AnnotIndex == annots[0].AnnotIndex);
  685. if (annotFillAndSign != null)
  686. {
  687. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
  688. return true;
  689. }
  690. }
  691. return false;
  692. }
  693. private void FromFillAndSign(FillAndSigntEventArgs obj)
  694. {
  695. if (obj != null)
  696. {
  697. if (string.IsNullOrEmpty(obj.Action) == false)
  698. {
  699. if (obj.Action == "Clear")
  700. {
  701. viewContentViewModel.AnnotSignatures.Clear();
  702. }
  703. }
  704. }
  705. }
  706. /// <summary>
  707. /// 便签
  708. /// </summary>
  709. /// <param name="selectedArgs"></param>
  710. /// <returns></returns>
  711. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  712. {
  713. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  714. if (selectedArgs == null || selectedArgs.Count == 0)
  715. {
  716. var annotate = Settings.Default.AppProperties.Annotate;
  717. if (annotate != null)
  718. {
  719. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  720. }
  721. else
  722. {
  723. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  724. }
  725. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] == null)
  726. {
  727. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
  728. if (defaultAnnot == null)
  729. {
  730. defaultAnnot = new DefaultAnnotProperty();
  731. defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
  732. defaultAnnot.NoteText = string.Empty;
  733. defaultAnnot.Opacity = 1;
  734. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  735. Settings.Default.Save();
  736. }
  737. stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
  738. }
  739. else
  740. {
  741. stickyAnnotArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
  742. stickyAnnotArgs.Content = string.Empty;
  743. stickyAnnotArgs.StickyNote = string.Empty;
  744. }
  745. if (stickyAnnotArgs != null)
  746. {
  747. selectedArgs = new List<AnnotHandlerEventArgs>();
  748. selectedArgs.Add(stickyAnnotArgs);
  749. }
  750. }
  751. else
  752. {
  753. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  754. }
  755. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  756. if (stickyAnnotArgs != null)
  757. stickyAnnotArgsList.Add(stickyAnnotArgs);
  758. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  759. return stickyAnnotArgs;
  760. }
  761. /// <summary>
  762. /// 矩形
  763. /// </summary>
  764. /// <param name="selectedArgs"></param>
  765. /// <returns></returns>
  766. private AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  767. {
  768. SquareAnnotArgs squareArgs = null;
  769. if (selectedArgs == null || selectedArgs.Count == 0)
  770. {
  771. squareArgs = new SquareAnnotArgs();
  772. var annotate = Settings.Default.AppProperties.Annotate;
  773. if (annotate != null)
  774. {
  775. squareArgs.BgColor = annotate.RectangleFillColor;
  776. squareArgs.LineColor = annotate.RectangleBorderColor;
  777. }
  778. else
  779. {
  780. squareArgs.LineColor = Colors.Red;
  781. squareArgs.BgColor = Colors.Red;
  782. }
  783. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] == null)
  784. {
  785. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  786. if (defaultAnnot == null)
  787. {
  788. defaultAnnot = new DefaultAnnotProperty();
  789. defaultAnnot.AnnotToolType = squareArgs.EventType;
  790. defaultAnnot.Thickness = 1;
  791. defaultAnnot.Opacity = 1;
  792. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  793. Settings.Default.Save();
  794. }
  795. squareArgs.LineWidth = defaultAnnot.Thickness;
  796. squareArgs.Transparency = defaultAnnot.Opacity;
  797. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  798. {
  799. squareArgs.LineDash = DashStyles.Solid;
  800. }
  801. else
  802. {
  803. var collect = new DoubleCollection();
  804. foreach (var item in defaultAnnot.DashArray)
  805. {
  806. collect.Add(item);
  807. }
  808. if (squareArgs.LineDash == null)
  809. squareArgs.LineDash = new DashStyle();
  810. squareArgs.LineDash.Dashes = collect;
  811. }
  812. }
  813. else
  814. {
  815. squareArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
  816. }
  817. if (squareArgs != null)
  818. {
  819. selectedArgs = new List<AnnotHandlerEventArgs>();
  820. selectedArgs.Add(squareArgs);
  821. CreateAnnotFromSelectPageText(squareArgs);
  822. }
  823. }
  824. else
  825. {
  826. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  827. }
  828. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  829. return squareArgs;
  830. }
  831. /// <summary>
  832. /// 圆
  833. /// </summary>
  834. /// <param name="selectedArgs"></param>
  835. /// <returns></returns>
  836. private AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  837. {
  838. CircleAnnotArgs circleAnnotArgs = null;
  839. if (selectedArgs == null || selectedArgs.Count == 0)
  840. {
  841. circleAnnotArgs = new CircleAnnotArgs();
  842. var annotate = Settings.Default.AppProperties.Annotate;
  843. if (annotate != null)
  844. {
  845. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  846. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  847. }
  848. else
  849. {
  850. circleAnnotArgs.LineColor = Colors.Red;
  851. circleAnnotArgs.BgColor = Colors.Red;
  852. }
  853. if (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] == null)
  854. {
  855. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  856. if (defaultAnnot == null)
  857. {
  858. defaultAnnot = new DefaultAnnotProperty();
  859. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  860. defaultAnnot.Thickness = 1;
  861. defaultAnnot.Opacity = 1;
  862. defaultAnnot.NoteText = string.Empty;
  863. defaultAnnot.DashArray = null;
  864. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  865. Settings.Default.Save();
  866. }
  867. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  868. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  869. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  870. {
  871. circleAnnotArgs.LineDash = DashStyles.Solid;
  872. }
  873. else
  874. {
  875. var collect = new DoubleCollection();
  876. foreach (var item in defaultAnnot.DashArray)
  877. {
  878. collect.Add(item);
  879. }
  880. if (circleAnnotArgs.LineDash == null)
  881. circleAnnotArgs.LineDash = new DashStyle();
  882. circleAnnotArgs.LineDash.Dashes = collect;
  883. }
  884. }
  885. else
  886. {
  887. circleAnnotArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
  888. }
  889. if (circleAnnotArgs != null)
  890. {
  891. selectedArgs = new List<AnnotHandlerEventArgs>();
  892. selectedArgs.Add(circleAnnotArgs);
  893. }
  894. }
  895. else
  896. {
  897. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  898. }
  899. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  900. return circleAnnotArgs;
  901. }
  902. /// <summary>
  903. /// 箭头 线
  904. /// </summary>
  905. /// <param name="TagStr"></param>
  906. /// <param name="selectedArgs"></param>
  907. /// <returns></returns>
  908. private AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  909. {
  910. LineAnnotArgs lineArgs = new LineAnnotArgs();
  911. if (selectedArgs == null || selectedArgs.Count == 0)
  912. {
  913. var annotate = Settings.Default.AppProperties.Annotate;
  914. if (annotate != null)
  915. {
  916. lineArgs.LineColor = annotate.LineColor;
  917. }
  918. else
  919. {
  920. lineArgs.LineColor = Colors.Red;
  921. }
  922. lineArgs.LineColor = Colors.Red;
  923. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  924. bool isLastAnnot = false;
  925. if (TagStr == "Line")
  926. {
  927. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  928. isLastAnnot = (propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
  929. }
  930. else
  931. {
  932. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  933. isLastAnnot = (propertyPanel.LastArrowAnnot != null ? true : false);
  934. }
  935. if (isLastAnnot == false)
  936. {
  937. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  938. if (defaultAnnot == null)
  939. {
  940. defaultAnnot = new DefaultAnnotProperty();
  941. defaultAnnot.AnnotToolType = lineArgs.EventType;
  942. defaultAnnot.Thickness = 1;
  943. defaultAnnot.Opacity = 1;
  944. defaultAnnot.NoteText = string.Empty;
  945. defaultAnnot.DashArray = null;
  946. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  947. Settings.Default.Save();
  948. }
  949. lineArgs.LineDash = DashStyles.Solid;
  950. lineArgs.LineWidth = defaultAnnot.Thickness;
  951. lineArgs.Transparency = defaultAnnot.Opacity;
  952. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  953. {
  954. lineArgs.LineDash = DashStyles.Solid;
  955. }
  956. else
  957. {
  958. var collect = new DoubleCollection();
  959. foreach (var item in defaultAnnot.DashArray)
  960. {
  961. collect.Add(item);
  962. }
  963. if (lineArgs.LineDash == null)
  964. lineArgs.LineDash = new DashStyle();
  965. lineArgs.LineDash.Dashes = collect;
  966. }
  967. }
  968. else
  969. {
  970. if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
  971. {
  972. lineArgs = propertyPanel.LastArrowAnnot as LineAnnotArgs;
  973. }
  974. else
  975. {
  976. lineArgs = propertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
  977. }
  978. }
  979. if (lineArgs != null)
  980. {
  981. selectedArgs = new List<AnnotHandlerEventArgs>();
  982. selectedArgs.Add(lineArgs);
  983. }
  984. }
  985. else
  986. {
  987. lineArgs = selectedArgs[0] as LineAnnotArgs;
  988. }
  989. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  990. return lineArgs;
  991. }
  992. /// <summary>
  993. /// 图章
  994. /// </summary>
  995. /// <returns></returns>
  996. private AnnotHandlerEventArgs GetStamp()
  997. {
  998. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  999. stampAnnotArgs.Opacity = 1;
  1000. stampAnnotArgs.StampText = "APPROVED";
  1001. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  1002. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  1003. if (stampAnnotArgs != null)
  1004. stampAnnotArgsList.Add(stampAnnotArgs);
  1005. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1006. return stampAnnotArgs;
  1007. }
  1008. /// <summary>
  1009. /// 签名
  1010. /// </summary>
  1011. /// <returns></returns>
  1012. private AnnotHandlerEventArgs GetSignature()
  1013. {
  1014. AddToPropertyPanel("SignatureAnnotProperty");
  1015. return null;
  1016. }
  1017. private AnnotHandlerEventArgs GetImage()
  1018. {
  1019. StampAnnotArgs stampArgs = new StampAnnotArgs();
  1020. stampArgs.Opacity = 1;
  1021. stampArgs.Type = StampType.IMAGE_STAMP;
  1022. OpenFileDialog openFileDialog = new OpenFileDialog();
  1023. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  1024. if (openFileDialog.ShowDialog() == true)
  1025. {
  1026. stampArgs.ImagePath = openFileDialog.FileName;
  1027. }
  1028. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  1029. if (stampArgs != null)
  1030. stampArgsList.Add(stampArgs);
  1031. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  1032. return stampArgs;
  1033. }
  1034. /// <summary>
  1035. /// 内容选择
  1036. /// </summary>
  1037. /// <param name="annotBtn"></param>
  1038. /// <returns></returns>
  1039. private AnnotHandlerEventArgs GetSnapshotEdit()
  1040. {
  1041. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  1042. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  1043. snapshotArgs.ControlPointColor = Colors.White;
  1044. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  1045. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  1046. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1047. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1048. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  1049. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1050. #region to do
  1051. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  1052. //snapshotArgs.ToolPanel = snapMenu;
  1053. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  1054. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1055. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1056. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  1057. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1058. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  1059. #endregion to do
  1060. return snapshotArgs;
  1061. }
  1062. #endregion 注释工具
  1063. #region 菜单
  1064. private bool InBookModeSetIsEnabled(MenuItem menuItem)
  1065. {
  1066. if (viewContentViewModel.mainViewModel.IsBookMode)
  1067. {
  1068. menuItem.IsEnabled = false;
  1069. return true;
  1070. }
  1071. else
  1072. {
  1073. menuItem.IsEnabled = true;
  1074. return false;
  1075. }
  1076. }
  1077. private void ExportPicture_MenuItemClick()
  1078. {
  1079. //图片提取
  1080. try
  1081. {
  1082. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1083. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1084. foreach (int pageIndex in imageDict.Keys)
  1085. {
  1086. imageList = imageDict[pageIndex];
  1087. }
  1088. string path = PDFViewer.Document.FileName;
  1089. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1090. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1091. {
  1092. int i = 1;
  1093. int pagenum = 1;
  1094. string choosePath = folderDialog.SelectedPath;
  1095. string sPath = choosePath + "\\" + path + "_Extract Image";
  1096. sPath = GetExportPathName(sPath);
  1097. if (!Directory.Exists(sPath))
  1098. {
  1099. Directory.CreateDirectory(sPath);
  1100. }
  1101. if (Directory.Exists(sPath))
  1102. {
  1103. foreach (System.Drawing.Bitmap image in imageList)
  1104. {
  1105. foreach (var item in imageDict.Keys)
  1106. {
  1107. pagenum = item;
  1108. }
  1109. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1110. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1111. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1112. i++;
  1113. }
  1114. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1115. }
  1116. }
  1117. }
  1118. catch (Exception ex) { }
  1119. }
  1120. public string GetExportPathName(string path)
  1121. {
  1122. int i = 1;
  1123. string outpath = path;
  1124. while (Directory.Exists(outpath))
  1125. {
  1126. outpath = path + $"({i.ToString()})";
  1127. i++;
  1128. }
  1129. return outpath;
  1130. }
  1131. private string GetNum(int num)
  1132. {
  1133. if (num % 10 < 1)
  1134. {
  1135. return "00" + num.ToString();
  1136. }
  1137. if (num % 10 >= 1 && num % 10 < 10)
  1138. {
  1139. return "0" + num.ToString();
  1140. }
  1141. else
  1142. {
  1143. return num.ToString();
  1144. }
  1145. }
  1146. #endregion 菜单
  1147. }
  1148. }