AnnotToolContentViewModel.Function.cs 62 KB

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