AnnotToolContentViewModel.Function.cs 57 KB

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