AnnotToolContentViewModel.Function.cs 64 KB

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