AnnotToolContentViewModel.Function.cs 58 KB

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