AnnotToolContentViewModel.Function.cs 58 KB

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