AnnotToolContentViewModel.Function.cs 65 KB

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