AnnotToolContentViewModel.Function.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  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. squareAnnot.ClientRect = drawRectTuple.Item2;
  766. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, squareAnnot);
  767. annotHandler = squareAnnot;
  768. }
  769. if (annotArgs is CircleAnnotArgs circleAnnot)
  770. {
  771. circleAnnot.ClientRect = drawRectTuple.Item2;
  772. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, circleAnnot);
  773. annotHandler = circleAnnot;
  774. }
  775. if (annotArgs is LineAnnotArgs lineAnnot)
  776. {
  777. lineAnnot.ClientRect = drawRectTuple.Item2;
  778. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, lineAnnot);
  779. annotHandler = lineAnnot;
  780. }
  781. }
  782. return annotHandler;
  783. }
  784. //Event导航到填写与签名的属性面板
  785. private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
  786. {
  787. if (viewContentViewModel.FillAndSign != null && viewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
  788. {
  789. var annotFillAndSign = viewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.PageIndex == annots[0].PageIndex && temp.AnnotIndex == annots[0].AnnotIndex);
  790. if (annotFillAndSign != null)
  791. {
  792. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
  793. return true;
  794. }
  795. }
  796. return false;
  797. }
  798. private void FromFillAndSign(FillAndSigntEventArgs obj)
  799. {
  800. if (obj != null)
  801. {
  802. if (string.IsNullOrEmpty(obj.Action) == false)
  803. {
  804. if (obj.Action == "Clear")
  805. {
  806. viewContentViewModel.AnnotSignatures.Clear();
  807. }
  808. }
  809. }
  810. }
  811. /// <summary>
  812. /// 便签
  813. /// </summary>
  814. /// <param name="selectedArgs"></param>
  815. /// <returns></returns>
  816. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  817. {
  818. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  819. if (selectedArgs == null || selectedArgs.Count == 0)
  820. {
  821. var annotate = Settings.Default.AppProperties.Annotate;
  822. if (annotate != null)
  823. {
  824. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  825. }
  826. else
  827. {
  828. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  829. }
  830. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] == null)
  831. {
  832. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
  833. if (defaultAnnot == null)
  834. {
  835. defaultAnnot = new DefaultAnnotProperty();
  836. defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
  837. defaultAnnot.NoteText = string.Empty;
  838. defaultAnnot.Opacity = 1;
  839. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  840. Settings.Default.Save();
  841. }
  842. stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
  843. //希望defaultAnnot里面可以缓存这个名字 2023/4/4
  844. stickyAnnotArgs.IconName = "Comment";
  845. }
  846. else
  847. {
  848. stickyAnnotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
  849. stickyAnnotArgs.Content = string.Empty;
  850. stickyAnnotArgs.StickyNote = string.Empty;
  851. //希望defaultAnnot里面可以缓存这个名字 2023/4/4
  852. stickyAnnotArgs.IconName = "Comment";
  853. }
  854. if (stickyAnnotArgs != null)
  855. {
  856. selectedArgs = new List<AnnotHandlerEventArgs>();
  857. selectedArgs.Add(stickyAnnotArgs);
  858. }
  859. }
  860. else
  861. {
  862. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  863. }
  864. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  865. if (stickyAnnotArgs != null)
  866. stickyAnnotArgsList.Add(stickyAnnotArgs);
  867. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  868. return stickyAnnotArgs;
  869. }
  870. /// <summary>
  871. /// 矩形
  872. /// </summary>
  873. /// <param name="selectedArgs"></param>
  874. /// <returns></returns>
  875. public AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  876. {
  877. SquareAnnotArgs squareArgs = null;
  878. if (selectedArgs == null || selectedArgs.Count == 0)
  879. {
  880. squareArgs = new SquareAnnotArgs();
  881. var annotate = Settings.Default.AppProperties.Annotate;
  882. if (annotate != null)
  883. {
  884. squareArgs.BgColor = annotate.RectangleFillColor;
  885. squareArgs.LineColor = annotate.RectangleBorderColor;
  886. }
  887. else
  888. {
  889. squareArgs.LineColor = Colors.Red;
  890. squareArgs.BgColor = Colors.Red;
  891. }
  892. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] == null)
  893. {
  894. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  895. if (defaultAnnot == null)
  896. {
  897. defaultAnnot = new DefaultAnnotProperty();
  898. defaultAnnot.AnnotToolType = squareArgs.EventType;
  899. defaultAnnot.Thickness = 1;
  900. defaultAnnot.Opacity = 1;
  901. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  902. Settings.Default.Save();
  903. }
  904. squareArgs.LineWidth = defaultAnnot.Thickness;
  905. squareArgs.Transparency = defaultAnnot.Opacity;
  906. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  907. {
  908. squareArgs.LineDash = DashStyles.Solid;
  909. }
  910. else
  911. {
  912. var collect = new DoubleCollection();
  913. foreach (var item in defaultAnnot.DashArray)
  914. {
  915. collect.Add(item);
  916. }
  917. if (squareArgs.LineDash == null)
  918. squareArgs.LineDash = new DashStyle();
  919. squareArgs.LineDash.Dashes = collect;
  920. }
  921. }
  922. else
  923. {
  924. SquareAnnotArgs squareAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
  925. squareArgs.BgColor = squareAnnot.BgColor;
  926. squareArgs.LineColor = squareAnnot.LineColor;
  927. squareArgs.LineWidth = squareAnnot.LineWidth;
  928. squareArgs.Transparency = squareAnnot.Transparency;
  929. squareArgs.LineDash = squareAnnot.LineDash;
  930. squareArgs.ClientRect = Rect.Empty;
  931. }
  932. if (squareArgs != null)
  933. {
  934. selectedArgs = new List<AnnotHandlerEventArgs>();
  935. selectedArgs.Add(squareArgs);
  936. //CreateAnnotFromSelectPageText(squareArgs);
  937. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(squareArgs);
  938. if (annotHandler is SquareAnnotArgs annotArgs)
  939. {
  940. selectedArgs.Clear();
  941. selectedArgs.Add(annotArgs);
  942. PropertyPanel.IsSelectedTextAddShape = true;
  943. }
  944. }
  945. }
  946. else
  947. {
  948. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  949. }
  950. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  951. return squareArgs;
  952. }
  953. /// <summary>
  954. /// 圆
  955. /// </summary>
  956. /// <param name="selectedArgs"></param>
  957. /// <returns></returns>
  958. public AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  959. {
  960. CircleAnnotArgs circleAnnotArgs = null;
  961. if (selectedArgs == null || selectedArgs.Count == 0)
  962. {
  963. circleAnnotArgs = new CircleAnnotArgs();
  964. var annotate = Settings.Default.AppProperties.Annotate;
  965. if (annotate != null)
  966. {
  967. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  968. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  969. }
  970. else
  971. {
  972. circleAnnotArgs.LineColor = Colors.Red;
  973. circleAnnotArgs.BgColor = Colors.Red;
  974. }
  975. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] == null)
  976. {
  977. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  978. if (defaultAnnot == null)
  979. {
  980. defaultAnnot = new DefaultAnnotProperty();
  981. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  982. defaultAnnot.Thickness = 1;
  983. defaultAnnot.Opacity = 1;
  984. defaultAnnot.NoteText = string.Empty;
  985. defaultAnnot.DashArray = null;
  986. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  987. Settings.Default.Save();
  988. }
  989. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  990. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  991. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  992. {
  993. circleAnnotArgs.LineDash = DashStyles.Solid;
  994. }
  995. else
  996. {
  997. var collect = new DoubleCollection();
  998. foreach (var item in defaultAnnot.DashArray)
  999. {
  1000. collect.Add(item);
  1001. }
  1002. if (circleAnnotArgs.LineDash == null)
  1003. circleAnnotArgs.LineDash = new DashStyle();
  1004. circleAnnotArgs.LineDash.Dashes = collect;
  1005. }
  1006. }
  1007. else
  1008. {
  1009. CircleAnnotArgs circleAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
  1010. circleAnnotArgs.LineColor = circleAnnot.LineColor;
  1011. circleAnnotArgs.BgColor = circleAnnot.BgColor;
  1012. circleAnnotArgs.LineWidth = circleAnnot.LineWidth;
  1013. circleAnnotArgs.Transparency = circleAnnot.Transparency;
  1014. circleAnnotArgs.LineDash = circleAnnot.LineDash;
  1015. circleAnnotArgs.ClientRect = Rect.Empty;
  1016. }
  1017. if (circleAnnotArgs != null)
  1018. {
  1019. selectedArgs = new List<AnnotHandlerEventArgs>();
  1020. selectedArgs.Add(circleAnnotArgs);
  1021. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(circleAnnotArgs);
  1022. if (annotHandler is CircleAnnotArgs annotArgs)
  1023. {
  1024. selectedArgs.Clear();
  1025. selectedArgs.Add(annotArgs);
  1026. PropertyPanel.IsSelectedTextAddShape = true;
  1027. }
  1028. }
  1029. }
  1030. else
  1031. {
  1032. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  1033. }
  1034. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  1035. return circleAnnotArgs;
  1036. }
  1037. /// <summary>
  1038. /// 箭头 线
  1039. /// </summary>
  1040. /// <param name="TagStr"></param>
  1041. /// <param name="selectedArgs"></param>
  1042. /// <returns></returns>
  1043. public AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  1044. {
  1045. LineAnnotArgs lineArgs = new LineAnnotArgs();
  1046. if (selectedArgs == null || selectedArgs.Count == 0)
  1047. {
  1048. //var annotate = Settings.Default.AppProperties.Annotate;
  1049. //if (annotate != null)
  1050. //{
  1051. // lineArgs.LineColor = annotate.LineColor;
  1052. //}
  1053. //else
  1054. //{
  1055. // lineArgs.LineColor = Colors.Red;
  1056. //}
  1057. //lineArgs.LineColor = Colors.Red;
  1058. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  1059. bool isLastAnnot = false;
  1060. if (TagStr == "Line")
  1061. {
  1062. lineArgs.LineColor = (LineColor as SolidColorBrush).Color;
  1063. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  1064. isLastAnnot = (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
  1065. }
  1066. else
  1067. {
  1068. lineArgs.LineColor = (ArrowColor as SolidColorBrush).Color;
  1069. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  1070. isLastAnnot = (PropertyPanel.LastArrowAnnot != null ? true : false);
  1071. }
  1072. if (isLastAnnot == false)
  1073. {
  1074. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  1075. if (defaultAnnot == null)
  1076. {
  1077. defaultAnnot = new DefaultAnnotProperty();
  1078. defaultAnnot.AnnotToolType = lineArgs.EventType;
  1079. defaultAnnot.Thickness = 1;
  1080. defaultAnnot.Opacity = 1;
  1081. defaultAnnot.NoteText = string.Empty;
  1082. defaultAnnot.DashArray = null;
  1083. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  1084. Settings.Default.Save();
  1085. }
  1086. lineArgs.LineDash = DashStyles.Solid;
  1087. lineArgs.LineWidth = defaultAnnot.Thickness;
  1088. lineArgs.Transparency = defaultAnnot.Opacity;
  1089. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  1090. {
  1091. lineArgs.LineDash = DashStyles.Solid;
  1092. }
  1093. else
  1094. {
  1095. var collect = new DoubleCollection();
  1096. foreach (var item in defaultAnnot.DashArray)
  1097. {
  1098. collect.Add(item);
  1099. }
  1100. if (lineArgs.LineDash == null)
  1101. lineArgs.LineDash = new DashStyle();
  1102. lineArgs.LineDash.Dashes = collect;
  1103. }
  1104. }
  1105. else
  1106. {
  1107. LineAnnotArgs lineAnnot = null;
  1108. if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
  1109. {
  1110. lineAnnot = PropertyPanel.LastArrowAnnot as LineAnnotArgs;
  1111. }
  1112. else
  1113. {
  1114. lineAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
  1115. }
  1116. lineArgs.LineColor = lineAnnot.LineColor;
  1117. lineArgs.HeadLineType = lineAnnot.HeadLineType;
  1118. lineArgs.TailLineType = lineAnnot.TailLineType;
  1119. lineArgs.LineWidth = lineAnnot.LineWidth;
  1120. lineArgs.Transparency = lineAnnot.Transparency;
  1121. lineArgs.LineDash = lineAnnot.LineDash;
  1122. }
  1123. if (lineArgs != null)
  1124. {
  1125. selectedArgs = new List<AnnotHandlerEventArgs>();
  1126. selectedArgs.Add(lineArgs);
  1127. }
  1128. }
  1129. else
  1130. {
  1131. lineArgs = selectedArgs[0] as LineAnnotArgs;
  1132. }
  1133. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  1134. return lineArgs;
  1135. }
  1136. /// <summary>
  1137. /// 图章
  1138. /// </summary>
  1139. /// <returns></returns>
  1140. private AnnotHandlerEventArgs GetStamp()
  1141. {
  1142. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  1143. stampAnnotArgs.Opacity = 1;
  1144. stampAnnotArgs.StampText = "APPROVED";
  1145. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  1146. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  1147. if (stampAnnotArgs != null)
  1148. stampAnnotArgsList.Add(stampAnnotArgs);
  1149. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Stamp")
  1150. {
  1151. if (IsNoSelectMenu)
  1152. {
  1153. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1154. return stampAnnotArgs;
  1155. }
  1156. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1157. return stampAnnotArgs;
  1158. }
  1159. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1160. return stampAnnotArgs;
  1161. }
  1162. /// <summary>
  1163. /// 签名
  1164. /// </summary>
  1165. /// <returns></returns>
  1166. private AnnotHandlerEventArgs GetSignature()
  1167. {
  1168. AddToPropertyPanel("SignatureAnnotProperty");
  1169. return null;
  1170. }
  1171. private AnnotHandlerEventArgs GetImage()
  1172. {
  1173. StampAnnotArgs stampArgs = new StampAnnotArgs();
  1174. stampArgs.Opacity = 1;
  1175. stampArgs.Type = StampType.IMAGE_STAMP;
  1176. OpenFileDialog openFileDialog = new OpenFileDialog();
  1177. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  1178. if (openFileDialog.ShowDialog() == true)
  1179. {
  1180. stampArgs.ImagePath = openFileDialog.FileName;
  1181. }
  1182. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  1183. if (stampArgs != null)
  1184. stampArgsList.Add(stampArgs);
  1185. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  1186. return stampArgs;
  1187. }
  1188. /// <summary>
  1189. /// 内容选择
  1190. /// </summary>
  1191. /// <param name="annotBtn"></param>
  1192. /// <returns></returns>
  1193. private AnnotHandlerEventArgs GetSnapshotEdit()
  1194. {
  1195. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  1196. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  1197. snapshotArgs.ControlPointColor = Colors.White;
  1198. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  1199. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  1200. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1201. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1202. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  1203. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1204. #region to do
  1205. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  1206. //snapshotArgs.ToolPanel = snapMenu;
  1207. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  1208. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1209. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1210. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  1211. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1212. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  1213. #endregion to do
  1214. StrAnnotToolChecked = "";
  1215. return snapshotArgs;
  1216. }
  1217. #endregion 注释工具
  1218. #region 菜单
  1219. private bool InBookModeSetIsEnabled(MenuItem menuItem)
  1220. {
  1221. if (viewContentViewModel.mainViewModel.IsBookMode)
  1222. {
  1223. menuItem.IsEnabled = false;
  1224. return true;
  1225. }
  1226. else
  1227. {
  1228. menuItem.IsEnabled = true;
  1229. return false;
  1230. }
  1231. }
  1232. private void ExportPicture_MenuItemClick()
  1233. {
  1234. //图片提取
  1235. try
  1236. {
  1237. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1238. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1239. foreach (int pageIndex in imageDict.Keys)
  1240. {
  1241. imageList = imageDict[pageIndex];
  1242. }
  1243. string path = PDFViewer.Document.FileName;
  1244. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1245. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1246. {
  1247. int i = 1;
  1248. int pagenum = 1;
  1249. string choosePath = folderDialog.SelectedPath;
  1250. string sPath = choosePath + "\\" + path + "_Extract Image";
  1251. sPath = GetExportPathName(sPath);
  1252. if (!Directory.Exists(sPath))
  1253. {
  1254. Directory.CreateDirectory(sPath);
  1255. }
  1256. if (Directory.Exists(sPath))
  1257. {
  1258. foreach (System.Drawing.Bitmap image in imageList)
  1259. {
  1260. foreach (var item in imageDict.Keys)
  1261. {
  1262. pagenum = item;
  1263. }
  1264. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1265. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1266. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1267. i++;
  1268. }
  1269. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1270. }
  1271. }
  1272. }
  1273. catch (Exception ex) { }
  1274. }
  1275. public string GetExportPathName(string path)
  1276. {
  1277. int i = 1;
  1278. string outpath = path;
  1279. while (Directory.Exists(outpath))
  1280. {
  1281. outpath = path + $"({i.ToString()})";
  1282. i++;
  1283. }
  1284. return outpath;
  1285. }
  1286. private string GetNum(int num)
  1287. {
  1288. if (num % 10 < 1)
  1289. {
  1290. return "00" + num.ToString();
  1291. }
  1292. if (num % 10 >= 1 && num % 10 < 10)
  1293. {
  1294. return "0" + num.ToString();
  1295. }
  1296. else
  1297. {
  1298. return num.ToString();
  1299. }
  1300. }
  1301. #endregion 菜单
  1302. }
  1303. }