AnnotToolContentViewModel.Function.cs 60 KB

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