AnnotToolContentViewModel.Function.cs 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574
  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. StrAnnotToolChecked = "";
  303. return;
  304. }
  305. annotArgs = GetStamp();
  306. break;
  307. case "Image":
  308. annotArgs = GetImage();
  309. break;
  310. case "Signature"://签名
  311. //判断本地有没有token,没有显示登录,有再判断登录状态
  312. if (!viewContentViewModel.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 (!viewContentViewModel.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 = 14;
  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.FontFamily = new FontFamily(defaultAnnot.FontFamily);
  682. freetextArgs.FontSize = defaultAnnot.FontSize;
  683. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  684. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  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.FontFamily = defaultAnnot.FontFamily;
  732. freetextArgs.FontSize = defaultAnnot.FontSize;
  733. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  734. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  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. stickyAnnotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
  930. stickyAnnotArgs.Content = string.Empty;
  931. stickyAnnotArgs.StickyNote = string.Empty;
  932. //希望defaultAnnot里面可以缓存这个名字 2023/4/4
  933. stickyAnnotArgs.IconName = "Comment";
  934. }
  935. if (stickyAnnotArgs != null)
  936. {
  937. selectedArgs = new List<AnnotHandlerEventArgs>();
  938. selectedArgs.Add(stickyAnnotArgs);
  939. }
  940. }
  941. else
  942. {
  943. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  944. }
  945. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  946. if (stickyAnnotArgs != null)
  947. stickyAnnotArgsList.Add(stickyAnnotArgs);
  948. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  949. return stickyAnnotArgs;
  950. }
  951. /// <summary>
  952. /// 矩形
  953. /// </summary>
  954. /// <param name="selectedArgs"></param>
  955. /// <returns></returns>
  956. public AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  957. {
  958. SquareAnnotArgs squareArgs = null;
  959. if (selectedArgs == null || selectedArgs.Count == 0)
  960. {
  961. squareArgs = new SquareAnnotArgs();
  962. var annotate = Settings.Default.AppProperties.Annotate;
  963. if (annotate != null)
  964. {
  965. squareArgs.BgColor = annotate.RectangleFillColor;
  966. squareArgs.LineColor = annotate.RectangleBorderColor;
  967. }
  968. else
  969. {
  970. squareArgs.LineColor = Colors.Red;
  971. squareArgs.BgColor = Colors.Red;
  972. }
  973. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] == null)
  974. {
  975. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  976. if (defaultAnnot == null)
  977. {
  978. defaultAnnot = new DefaultAnnotProperty();
  979. defaultAnnot.AnnotToolType = squareArgs.EventType;
  980. defaultAnnot.Thickness = 1;
  981. defaultAnnot.Opacity = 1;
  982. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  983. Settings.Default.Save();
  984. }
  985. squareArgs.LineWidth = defaultAnnot.Thickness;
  986. squareArgs.Transparency = defaultAnnot.Opacity;
  987. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  988. {
  989. squareArgs.LineDash = DashStyles.Solid;
  990. }
  991. else
  992. {
  993. var collect = new DoubleCollection();
  994. foreach (var item in defaultAnnot.DashArray)
  995. {
  996. collect.Add(item);
  997. }
  998. if (squareArgs.LineDash == null)
  999. squareArgs.LineDash = new DashStyle();
  1000. squareArgs.LineDash.Dashes = collect;
  1001. }
  1002. }
  1003. else
  1004. {
  1005. SquareAnnotArgs squareAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
  1006. squareArgs.BgColor = squareAnnot.BgColor;
  1007. squareArgs.LineColor = squareAnnot.LineColor;
  1008. squareArgs.LineWidth = squareAnnot.LineWidth;
  1009. squareArgs.Transparency = squareAnnot.Transparency;
  1010. squareArgs.LineDash = squareAnnot.LineDash;
  1011. squareArgs.ClientRect = Rect.Empty;
  1012. }
  1013. if (squareArgs != null)
  1014. {
  1015. selectedArgs = new List<AnnotHandlerEventArgs>();
  1016. selectedArgs.Add(squareArgs);
  1017. if (StrAnnotToolChecked == "Rect")
  1018. {
  1019. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(squareArgs);
  1020. if (annotHandler is SquareAnnotArgs annotArgs)
  1021. {
  1022. selectedArgs.Clear();
  1023. selectedArgs.Add(annotArgs);
  1024. }
  1025. }
  1026. }
  1027. }
  1028. else
  1029. {
  1030. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  1031. }
  1032. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  1033. return squareArgs;
  1034. }
  1035. /// <summary>
  1036. /// 圆
  1037. /// </summary>
  1038. /// <param name="selectedArgs"></param>
  1039. /// <returns></returns>
  1040. public AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  1041. {
  1042. CircleAnnotArgs circleAnnotArgs = null;
  1043. if (selectedArgs == null || selectedArgs.Count == 0)
  1044. {
  1045. circleAnnotArgs = new CircleAnnotArgs();
  1046. var annotate = Settings.Default.AppProperties.Annotate;
  1047. if (annotate != null)
  1048. {
  1049. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  1050. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  1051. }
  1052. else
  1053. {
  1054. circleAnnotArgs.LineColor = Colors.Red;
  1055. circleAnnotArgs.BgColor = Colors.Red;
  1056. }
  1057. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] == null)
  1058. {
  1059. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  1060. if (defaultAnnot == null)
  1061. {
  1062. defaultAnnot = new DefaultAnnotProperty();
  1063. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  1064. defaultAnnot.Thickness = 1;
  1065. defaultAnnot.Opacity = 1;
  1066. defaultAnnot.NoteText = string.Empty;
  1067. defaultAnnot.DashArray = null;
  1068. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  1069. Settings.Default.Save();
  1070. }
  1071. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  1072. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  1073. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  1074. {
  1075. circleAnnotArgs.LineDash = DashStyles.Solid;
  1076. }
  1077. else
  1078. {
  1079. var collect = new DoubleCollection();
  1080. foreach (var item in defaultAnnot.DashArray)
  1081. {
  1082. collect.Add(item);
  1083. }
  1084. if (circleAnnotArgs.LineDash == null)
  1085. circleAnnotArgs.LineDash = new DashStyle();
  1086. circleAnnotArgs.LineDash.Dashes = collect;
  1087. }
  1088. }
  1089. else
  1090. {
  1091. CircleAnnotArgs circleAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
  1092. circleAnnotArgs.LineColor = circleAnnot.LineColor;
  1093. circleAnnotArgs.BgColor = circleAnnot.BgColor;
  1094. circleAnnotArgs.LineWidth = circleAnnot.LineWidth;
  1095. circleAnnotArgs.Transparency = circleAnnot.Transparency;
  1096. circleAnnotArgs.LineDash = circleAnnot.LineDash;
  1097. circleAnnotArgs.ClientRect = Rect.Empty;
  1098. }
  1099. if (circleAnnotArgs != null)
  1100. {
  1101. selectedArgs = new List<AnnotHandlerEventArgs>();
  1102. selectedArgs.Add(circleAnnotArgs);
  1103. if (StrAnnotToolChecked == "Rect")
  1104. {
  1105. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(circleAnnotArgs);
  1106. if (annotHandler is CircleAnnotArgs annotArgs)
  1107. {
  1108. selectedArgs.Clear();
  1109. selectedArgs.Add(annotArgs);
  1110. }
  1111. }
  1112. }
  1113. }
  1114. else
  1115. {
  1116. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  1117. }
  1118. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  1119. return circleAnnotArgs;
  1120. }
  1121. /// <summary>
  1122. /// 箭头 线
  1123. /// </summary>
  1124. /// <param name="TagStr"></param>
  1125. /// <param name="selectedArgs"></param>
  1126. /// <returns></returns>
  1127. public AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  1128. {
  1129. LineAnnotArgs lineArgs = new LineAnnotArgs();
  1130. if (selectedArgs == null || selectedArgs.Count == 0)
  1131. {
  1132. //var annotate = Settings.Default.AppProperties.Annotate;
  1133. //if (annotate != null)
  1134. //{
  1135. // lineArgs.LineColor = annotate.LineColor;
  1136. //}
  1137. //else
  1138. //{
  1139. // lineArgs.LineColor = Colors.Red;
  1140. //}
  1141. //lineArgs.LineColor = Colors.Red;
  1142. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  1143. bool isLastAnnot = false;
  1144. if (TagStr == "Line")
  1145. {
  1146. lineArgs.LineColor = (LineColor as SolidColorBrush).Color;
  1147. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  1148. isLastAnnot = (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
  1149. }
  1150. else
  1151. {
  1152. lineArgs.LineColor = (ArrowColor as SolidColorBrush).Color;
  1153. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  1154. isLastAnnot = (PropertyPanel.LastArrowAnnot != null ? true : false);
  1155. }
  1156. if (isLastAnnot == false)
  1157. {
  1158. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  1159. if (defaultAnnot == null)
  1160. {
  1161. defaultAnnot = new DefaultAnnotProperty();
  1162. defaultAnnot.AnnotToolType = lineArgs.EventType;
  1163. defaultAnnot.Thickness = 1;
  1164. defaultAnnot.Opacity = 1;
  1165. defaultAnnot.NoteText = string.Empty;
  1166. defaultAnnot.DashArray = null;
  1167. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  1168. Settings.Default.Save();
  1169. }
  1170. lineArgs.LineDash = DashStyles.Solid;
  1171. lineArgs.LineWidth = defaultAnnot.Thickness;
  1172. lineArgs.Transparency = defaultAnnot.Opacity;
  1173. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  1174. {
  1175. lineArgs.LineDash = DashStyles.Solid;
  1176. }
  1177. else
  1178. {
  1179. var collect = new DoubleCollection();
  1180. foreach (var item in defaultAnnot.DashArray)
  1181. {
  1182. collect.Add(item);
  1183. }
  1184. if (lineArgs.LineDash == null)
  1185. lineArgs.LineDash = new DashStyle();
  1186. lineArgs.LineDash.Dashes = collect;
  1187. }
  1188. }
  1189. else
  1190. {
  1191. LineAnnotArgs lineAnnot = null;
  1192. if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
  1193. {
  1194. lineAnnot = PropertyPanel.LastArrowAnnot as LineAnnotArgs;
  1195. }
  1196. else
  1197. {
  1198. lineAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
  1199. }
  1200. lineArgs.LineColor = lineAnnot.LineColor;
  1201. lineArgs.HeadLineType = lineAnnot.HeadLineType;
  1202. lineArgs.TailLineType = lineAnnot.TailLineType;
  1203. lineArgs.LineWidth = lineAnnot.LineWidth;
  1204. lineArgs.Transparency = lineAnnot.Transparency;
  1205. lineArgs.LineDash = lineAnnot.LineDash;
  1206. }
  1207. if (lineArgs != null)
  1208. {
  1209. selectedArgs = new List<AnnotHandlerEventArgs>();
  1210. selectedArgs.Add(lineArgs);
  1211. if (StrAnnotToolChecked == "Rect")
  1212. {
  1213. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(lineArgs);
  1214. if (annotHandler is LineAnnotArgs annotArgs)
  1215. {
  1216. selectedArgs.Clear();
  1217. selectedArgs.Add(annotArgs);
  1218. }
  1219. }
  1220. }
  1221. }
  1222. else
  1223. {
  1224. lineArgs = selectedArgs[0] as LineAnnotArgs;
  1225. }
  1226. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  1227. return lineArgs;
  1228. }
  1229. /// <summary>
  1230. /// 图章
  1231. /// </summary>
  1232. /// <returns></returns>
  1233. private AnnotHandlerEventArgs GetStamp()
  1234. {
  1235. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  1236. stampAnnotArgs.Opacity = 1;
  1237. stampAnnotArgs.StampText = "APPROVED";
  1238. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  1239. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  1240. if (stampAnnotArgs != null)
  1241. stampAnnotArgsList.Add(stampAnnotArgs);
  1242. if (string.IsNullOrEmpty(StrAnnotToolChecked))
  1243. {
  1244. if (IsNoSelectMenu)
  1245. {
  1246. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1247. return stampAnnotArgs;
  1248. }
  1249. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1250. return stampAnnotArgs;
  1251. }
  1252. //已选中注释工具的前提下,选中页面已经添加的图章注释时,右侧属性面板显示空状态(不自动收起)
  1253. if (StrAnnotToolChecked != "Stamp" && string.IsNullOrEmpty(StrAnnotToolChecked) == false)
  1254. {
  1255. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1256. ShowPropertyPanel(true);
  1257. return stampAnnotArgs;
  1258. }
  1259. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1260. return stampAnnotArgs;
  1261. }
  1262. /// <summary>
  1263. /// 签名
  1264. /// </summary>
  1265. /// <returns></returns>
  1266. private AnnotHandlerEventArgs GetSignature()
  1267. {
  1268. AddToPropertyPanel("SignatureAnnotProperty");
  1269. return null;
  1270. }
  1271. private AnnotHandlerEventArgs GetImage()
  1272. {
  1273. StampAnnotArgs stampArgs = new StampAnnotArgs();
  1274. stampArgs.Opacity = 1;
  1275. stampArgs.Type = StampType.IMAGE_STAMP;
  1276. OpenFileDialog openFileDialog = new OpenFileDialog();
  1277. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  1278. if (openFileDialog.ShowDialog() == true)
  1279. {
  1280. stampArgs.ImagePath = openFileDialog.FileName;
  1281. }
  1282. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  1283. if (stampArgs != null)
  1284. stampArgsList.Add(stampArgs);
  1285. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  1286. return stampArgs;
  1287. }
  1288. /// <summary>
  1289. /// 内容选择
  1290. /// </summary>
  1291. /// <param name="annotBtn"></param>
  1292. /// <returns></returns>
  1293. private AnnotHandlerEventArgs GetSnapshotEdit()
  1294. {
  1295. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  1296. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  1297. snapshotArgs.ControlPointColor = Colors.White;
  1298. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  1299. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  1300. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1301. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1302. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  1303. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1304. #region to do
  1305. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  1306. //snapshotArgs.ToolPanel = snapMenu;
  1307. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  1308. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1309. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1310. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  1311. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1312. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  1313. #endregion to do
  1314. StrAnnotToolChecked = "";
  1315. return snapshotArgs;
  1316. }
  1317. #endregion 注释工具
  1318. #region 菜单
  1319. private bool InBookModeSetIsHidden(object obj)
  1320. {
  1321. bool flag = false;
  1322. if (obj is MenuItem menuItem)
  1323. {
  1324. if (viewContentViewModel.mainViewModel.IsBookMode)
  1325. {
  1326. menuItem.Visibility = Visibility.Collapsed;
  1327. return true;
  1328. }
  1329. else
  1330. {
  1331. menuItem.Visibility = Visibility.Visible;
  1332. return false;
  1333. }
  1334. }
  1335. if (obj is Separator separator)
  1336. {
  1337. if (viewContentViewModel.mainViewModel.IsBookMode)
  1338. {
  1339. separator.Visibility = Visibility.Collapsed;
  1340. return true;
  1341. }
  1342. else
  1343. {
  1344. separator.Visibility = Visibility.Visible;
  1345. return false;
  1346. }
  1347. }
  1348. return flag;
  1349. }
  1350. private void ExportPicture_MenuItemClick()
  1351. {
  1352. //图片提取
  1353. try
  1354. {
  1355. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1356. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1357. foreach (int pageIndex in imageDict.Keys)
  1358. {
  1359. imageList = imageDict[pageIndex];
  1360. }
  1361. string path = PDFViewer.Document.FileName;
  1362. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1363. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1364. {
  1365. int i = 1;
  1366. int pagenum = 1;
  1367. string choosePath = folderDialog.SelectedPath;
  1368. string sPath = choosePath + "\\" + path + "_Extract Image";
  1369. sPath = GetExportPathName(sPath);
  1370. if (!Directory.Exists(sPath))
  1371. {
  1372. Directory.CreateDirectory(sPath);
  1373. }
  1374. if (Directory.Exists(sPath))
  1375. {
  1376. foreach (System.Drawing.Bitmap image in imageList)
  1377. {
  1378. foreach (var item in imageDict.Keys)
  1379. {
  1380. pagenum = item;
  1381. }
  1382. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1383. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1384. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1385. i++;
  1386. }
  1387. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1388. }
  1389. }
  1390. }
  1391. catch (Exception ex) { }
  1392. }
  1393. public string GetExportPathName(string path)
  1394. {
  1395. int i = 1;
  1396. string outpath = path;
  1397. while (Directory.Exists(outpath))
  1398. {
  1399. outpath = path + $"({i.ToString()})";
  1400. i++;
  1401. }
  1402. return outpath;
  1403. }
  1404. private string GetNum(int num)
  1405. {
  1406. if (num % 10 < 1)
  1407. {
  1408. return "00" + num.ToString();
  1409. }
  1410. if (num % 10 >= 1 && num % 10 < 10)
  1411. {
  1412. return "0" + num.ToString();
  1413. }
  1414. else
  1415. {
  1416. return num.ToString();
  1417. }
  1418. }
  1419. #endregion 菜单
  1420. }
  1421. }