AnnotToolContentViewModel.Function.cs 62 KB

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