AnnotToolContentViewModel.Function.cs 53 KB

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