AnnotToolContentViewModel.Function.cs 58 KB

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