AnnotToolContentViewModel.Function.cs 61 KB

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