AnnotToolContentViewModel.Function.cs 62 KB

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