AnnotToolContentViewModel.Function.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463
  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. freehandArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreehand] as FreehandAnnotArgs;
  552. freehandArgs.AnnotIndex = -1;
  553. freehandArgs.PageIndex = -1;
  554. freehandArgs.ClientRect = Rect.Empty;
  555. }
  556. selectedArgs = new List<AnnotHandlerEventArgs>();
  557. selectedArgs.Add(freehandArgs);
  558. }
  559. else
  560. {
  561. freehandArgs = selectedArgs[0] as FreehandAnnotArgs;
  562. if (NavigatedToFillAndSignVM(selectedArgs, "Freehand"))
  563. {
  564. return freehandArgs;
  565. }
  566. }
  567. AddToPropertyPanel("FreehandAnnotProperty", "Freehand", selectedArgs);
  568. return freehandArgs;
  569. }
  570. /// <summary>
  571. /// 文本
  572. /// </summary>
  573. /// <param name="selectedArgs"></param>
  574. /// <returns></returns>
  575. private AnnotHandlerEventArgs GetFreetext(List<AnnotHandlerEventArgs> selectedArgs = null)
  576. {
  577. FreeTextAnnotArgs freetextArgs = null;
  578. TextAlignment textAlignment;
  579. if (selectedArgs == null || selectedArgs.Count == 0)
  580. {
  581. freetextArgs = new FreeTextAnnotArgs();
  582. var annotate = Settings.Default.AppProperties.Annotate;
  583. if (annotate != null)
  584. {
  585. freetextArgs.FontColor = annotate.TextAnnoteColor;
  586. }
  587. else
  588. {
  589. freetextArgs.FontColor = Colors.Black;
  590. }
  591. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] == null)
  592. {
  593. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(freetextArgs.EventType);
  594. if (defaultAnnot == null)
  595. {
  596. defaultAnnot = new DefaultAnnotProperty();
  597. defaultAnnot.AnnotToolType = freetextArgs.EventType;
  598. defaultAnnot.ForgoundColor = freetextArgs.FontColor;
  599. defaultAnnot.BorderColor = Colors.Transparent;
  600. defaultAnnot.BackgroundColor = Colors.White;
  601. defaultAnnot.Opacity = 1;
  602. defaultAnnot.FontFamily = Settings.Default.AppProperties.Annotate.TextFontFamaily;
  603. defaultAnnot.FontSize = 14;
  604. defaultAnnot.TextAlign = TextAlignment.Left;
  605. defaultAnnot.Thickness = 0;
  606. defaultAnnot.NoteText = string.Empty;
  607. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  608. Settings.Default.Save();
  609. }
  610. freetextArgs.FontColor = defaultAnnot.ForgoundColor;
  611. freetextArgs.LineColor = defaultAnnot.BorderColor;
  612. freetextArgs.BgColor = defaultAnnot.BackgroundColor;
  613. freetextArgs.Transparency = defaultAnnot.Opacity;
  614. freetextArgs.FontFamily = new FontFamily(defaultAnnot.FontFamily);
  615. freetextArgs.FontSize = defaultAnnot.FontSize;
  616. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  617. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  618. freetextArgs.LineWidth = defaultAnnot.Thickness;
  619. int align = (int)Settings.Default.AppProperties.Annotate.TextAlign;
  620. if (align == 0)
  621. textAlignment = TextAlignment.Left;
  622. else if (align == 1)
  623. textAlignment = TextAlignment.Center;
  624. else
  625. textAlignment = TextAlignment.Right;
  626. freetextArgs.Align = textAlignment;
  627. }
  628. else
  629. {
  630. FreeTextAnnotArgs freeText = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotFreeText] as FreeTextAnnotArgs;
  631. freetextArgs = SetFreetextArgs(freeText);
  632. //freetextArgs = SetFreetextArgs(freeText);
  633. //freetextArgs.Content = string.Empty;
  634. //freetextArgs.TextContent = string.Empty;
  635. }
  636. if (freetextArgs != null)
  637. {
  638. selectedArgs = new List<AnnotHandlerEventArgs>();
  639. selectedArgs.Add(freetextArgs);
  640. SelectTextCreateAnnot(freetextArgs);
  641. }
  642. }
  643. else
  644. {
  645. FreeTextAnnotArgs freeText = selectedArgs[0] as FreeTextAnnotArgs;
  646. freetextArgs = SetFreetextArgs(freeText);
  647. textAlignment = freetextArgs.Align;
  648. if (NavigatedToFillAndSignVM(selectedArgs, "Freetext"))
  649. {
  650. return freetextArgs;
  651. }
  652. }
  653. AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs);
  654. return freetextArgs;
  655. }
  656. private FreeTextAnnotArgs SetFreetextArgs(FreeTextAnnotArgs defaultAnnot)
  657. {
  658. FreeTextAnnotArgs freetextArgs = new FreeTextAnnotArgs();
  659. freetextArgs.FontColor = defaultAnnot.FontColor;
  660. freetextArgs.LineColor = defaultAnnot.LineColor;
  661. freetextArgs.BgColor = defaultAnnot.BgColor;
  662. freetextArgs.Transparency = defaultAnnot.Transparency;
  663. freetextArgs.FontFamily = defaultAnnot.FontFamily;
  664. freetextArgs.FontSize = defaultAnnot.FontSize;
  665. freetextArgs.FontWeight = defaultAnnot.FontWeight;
  666. freetextArgs.FontStyle = defaultAnnot.FontStyle;
  667. freetextArgs.LineWidth = defaultAnnot.LineWidth;
  668. freetextArgs.Align = defaultAnnot.Align;
  669. return freetextArgs;
  670. }
  671. private void SelectTextCreateAnnot(FreeTextAnnotArgs freeText)
  672. {
  673. List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
  674. if (selectList != null && selectList.Count > 0)
  675. {
  676. foreach (TextSelectNode selectNode in selectList)
  677. {
  678. FreeTextAnnotArgs textArgs = new FreeTextAnnotArgs();
  679. Rect clientRect = Rect.Empty;
  680. foreach (Rect rawRect in selectNode.RawRect)
  681. {
  682. clientRect.Union(rawRect);
  683. }
  684. if (clientRect.IsEmpty == false)
  685. {
  686. clientRect = new Rect(
  687. clientRect.Left / 72D * 96D,
  688. clientRect.Top / 72D * 96D,
  689. clientRect.Width / 72D * 96D,
  690. clientRect.Height / 72D * 96D);
  691. textArgs.ClientRect = DpiHelpers.GetDpiRelatedRect(clientRect);
  692. //textArgs.Transparency = 1;
  693. //textArgs.BgColor = Colors.Transparent;
  694. //textArgs.LineColor = Colors.Red;
  695. //textArgs.LineWidth = 2;
  696. textArgs.Transparency = freeText.Transparency;
  697. textArgs.BgColor = freeText.BgColor;
  698. textArgs.LineColor = freeText.LineColor;
  699. textArgs.LineWidth = freeText.LineWidth;
  700. textArgs.TextContent = selectNode.SelectText;
  701. PDFViewer.CreatePageAnnot(selectNode.PageIndex, textArgs);
  702. }
  703. break;
  704. }
  705. }
  706. }
  707. //获取选中文字内容的区域大小,以及内容内容所在的页码
  708. private Tuple<int, Rect> DrawRectCreateAnnot()
  709. {
  710. List<TextSelectNode> selectList = PDFViewer.GetSelectTextInfo();
  711. Rect clientRect = Rect.Empty;
  712. int pageIndex = -1;
  713. if (selectList != null && selectList.Count > 0)
  714. {
  715. pageIndex = selectList[0].PageIndex;
  716. }
  717. if (selectList != null && selectList.Count > 0)
  718. {
  719. foreach (TextSelectNode selectNode in selectList)
  720. {
  721. foreach (Rect rawRect in selectNode.RawRect)
  722. {
  723. clientRect.Union(rawRect);
  724. }
  725. int dpi = DpiHelpers.Dpi;
  726. if (clientRect.IsEmpty == false)
  727. {
  728. clientRect = new Rect(
  729. clientRect.Left / 72D * dpi,
  730. clientRect.Top / 72D * dpi,
  731. clientRect.Width / 72D * dpi,
  732. clientRect.Height / 72D * dpi);
  733. }
  734. break;
  735. }
  736. }
  737. if (clientRect != Rect.Empty && pageIndex > -1)
  738. {
  739. return new Tuple<int, Rect>(pageIndex, clientRect);
  740. }
  741. return null;
  742. }
  743. /// <summary>
  744. /// 根据选中的文本内容,来创建指定大小的注释。
  745. /// </summary>
  746. /// <param name="annotArgs"></param>
  747. private AnnotHandlerEventArgs CreateAnnotFromSelectPageText(AnnotHandlerEventArgs annotArgs)
  748. {
  749. AnnotHandlerEventArgs annotHandler = null;
  750. //点击注释工具,在阅读页根据选中的文本内容,创建注释矩形大小
  751. var drawRectTuple = DrawRectCreateAnnot();
  752. if (drawRectTuple != null)
  753. {
  754. if (annotArgs is LinkAnnotArgs linkAnnot)
  755. {
  756. linkAnnot.ClientRect = drawRectTuple.Item2;
  757. linkAnnot.URI = string.Empty;
  758. linkAnnot.LinkType = LINK_TYPE.GOTO;
  759. linkAnnot.DestIndex = drawRectTuple.Item1;
  760. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, linkAnnot);
  761. annotHandler = linkAnnot;
  762. }
  763. if (annotArgs is SquareAnnotArgs squareAnnot)
  764. {
  765. squareAnnot.ClientRect = drawRectTuple.Item2;
  766. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, squareAnnot);
  767. annotHandler = squareAnnot;
  768. }
  769. if (annotArgs is CircleAnnotArgs circleAnnot)
  770. {
  771. circleAnnot.ClientRect = drawRectTuple.Item2;
  772. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, circleAnnot);
  773. annotHandler = circleAnnot;
  774. }
  775. if (annotArgs is LineAnnotArgs lineAnnot)
  776. {
  777. lineAnnot.ClientRect = drawRectTuple.Item2;
  778. PDFViewer.CreatePageAnnot(drawRectTuple.Item1, lineAnnot);
  779. annotHandler = lineAnnot;
  780. }
  781. }
  782. return annotHandler;
  783. }
  784. //Event导航到填写与签名的属性面板
  785. private bool NavigatedToFillAndSignVM(List<AnnotHandlerEventArgs> annots, string tag)
  786. {
  787. if (viewContentViewModel.FillAndSign != null && viewContentViewModel.FillAndSign.Count > 0 && annots != null && annots.Count > 0)
  788. {
  789. var annotFillAndSign = viewContentViewModel.FillAndSign.FirstOrDefault(temp => temp.PageIndex == annots[0].PageIndex && temp.AnnotIndex == annots[0].AnnotIndex);
  790. if (annotFillAndSign != null)
  791. {
  792. this.events.GetEvent<FillAndSignEvent>().Publish(new FillAndSigntEventArgs { Action = tag, AppUnicode = App.mainWindowViewModel.SelectedItem.Unicode, Annots = annots });
  793. return true;
  794. }
  795. }
  796. return false;
  797. }
  798. private void FromFillAndSign(FillAndSigntEventArgs obj)
  799. {
  800. if (obj != null)
  801. {
  802. if (string.IsNullOrEmpty(obj.Action) == false)
  803. {
  804. if (obj.Action == "Clear")
  805. {
  806. viewContentViewModel.AnnotSignatures.Clear();
  807. }
  808. }
  809. }
  810. }
  811. /// <summary>
  812. /// 便签
  813. /// </summary>
  814. /// <param name="selectedArgs"></param>
  815. /// <returns></returns>
  816. private AnnotHandlerEventArgs GetStickyNote(List<AnnotHandlerEventArgs> selectedArgs = null)
  817. {
  818. StickyAnnotArgs stickyAnnotArgs = new StickyAnnotArgs();
  819. if (selectedArgs == null || selectedArgs.Count == 0)
  820. {
  821. var annotate = Settings.Default.AppProperties.Annotate;
  822. if (annotate != null)
  823. {
  824. stickyAnnotArgs.Color = annotate.NoteAnnoteColor;
  825. }
  826. else
  827. {
  828. stickyAnnotArgs.Color = Color.FromRgb(0xFF, 0x81, 0x33);
  829. }
  830. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] == null)
  831. {
  832. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(stickyAnnotArgs.EventType);
  833. if (defaultAnnot == null)
  834. {
  835. defaultAnnot = new DefaultAnnotProperty();
  836. defaultAnnot.AnnotToolType = stickyAnnotArgs.EventType;
  837. defaultAnnot.NoteText = string.Empty;
  838. defaultAnnot.Opacity = 1;
  839. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  840. Settings.Default.Save();
  841. }
  842. stickyAnnotArgs.Transparency = defaultAnnot.Opacity;
  843. //希望defaultAnnot里面可以缓存这个名字 2023/4/4
  844. stickyAnnotArgs.IconName = "Comment";
  845. }
  846. else
  847. {
  848. stickyAnnotArgs = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSticky] as StickyAnnotArgs;
  849. stickyAnnotArgs.Content = string.Empty;
  850. stickyAnnotArgs.StickyNote = string.Empty;
  851. //希望defaultAnnot里面可以缓存这个名字 2023/4/4
  852. stickyAnnotArgs.IconName = "Comment";
  853. }
  854. if (stickyAnnotArgs != null)
  855. {
  856. selectedArgs = new List<AnnotHandlerEventArgs>();
  857. selectedArgs.Add(stickyAnnotArgs);
  858. }
  859. }
  860. else
  861. {
  862. stickyAnnotArgs = selectedArgs[0] as StickyAnnotArgs;
  863. }
  864. List<AnnotHandlerEventArgs> stickyAnnotArgsList = new List<AnnotHandlerEventArgs>();
  865. if (stickyAnnotArgs != null)
  866. stickyAnnotArgsList.Add(stickyAnnotArgs);
  867. AddToPropertyPanel("StickyNoteProperty", "StickyNote", selectedArgs);
  868. return stickyAnnotArgs;
  869. }
  870. /// <summary>
  871. /// 矩形
  872. /// </summary>
  873. /// <param name="selectedArgs"></param>
  874. /// <returns></returns>
  875. public AnnotHandlerEventArgs GetRect(List<AnnotHandlerEventArgs> selectedArgs = null)
  876. {
  877. SquareAnnotArgs squareArgs = null;
  878. if (selectedArgs == null || selectedArgs.Count == 0)
  879. {
  880. squareArgs = new SquareAnnotArgs();
  881. var annotate = Settings.Default.AppProperties.Annotate;
  882. if (annotate != null)
  883. {
  884. squareArgs.BgColor = annotate.RectangleFillColor;
  885. squareArgs.LineColor = annotate.RectangleBorderColor;
  886. }
  887. else
  888. {
  889. squareArgs.LineColor = Colors.Red;
  890. squareArgs.BgColor = Colors.Red;
  891. }
  892. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] == null)
  893. {
  894. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(squareArgs.EventType);
  895. if (defaultAnnot == null)
  896. {
  897. defaultAnnot = new DefaultAnnotProperty();
  898. defaultAnnot.AnnotToolType = squareArgs.EventType;
  899. defaultAnnot.Thickness = 1;
  900. defaultAnnot.Opacity = 1;
  901. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  902. Settings.Default.Save();
  903. }
  904. squareArgs.LineWidth = defaultAnnot.Thickness;
  905. squareArgs.Transparency = defaultAnnot.Opacity;
  906. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  907. {
  908. squareArgs.LineDash = DashStyles.Solid;
  909. }
  910. else
  911. {
  912. var collect = new DoubleCollection();
  913. foreach (var item in defaultAnnot.DashArray)
  914. {
  915. collect.Add(item);
  916. }
  917. if (squareArgs.LineDash == null)
  918. squareArgs.LineDash = new DashStyle();
  919. squareArgs.LineDash.Dashes = collect;
  920. }
  921. }
  922. else
  923. {
  924. SquareAnnotArgs squareAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotSquare] as SquareAnnotArgs;
  925. squareArgs.BgColor = squareAnnot.BgColor;
  926. squareArgs.LineColor = squareAnnot.LineColor;
  927. squareArgs.LineWidth = squareAnnot.LineWidth;
  928. squareArgs.Transparency = squareAnnot.Transparency;
  929. squareArgs.LineDash = squareAnnot.LineDash;
  930. squareArgs.ClientRect = Rect.Empty;
  931. }
  932. if (squareArgs != null)
  933. {
  934. selectedArgs = new List<AnnotHandlerEventArgs>();
  935. selectedArgs.Add(squareArgs);
  936. if (StrAnnotToolChecked == "Rect")
  937. {
  938. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(squareArgs);
  939. if (annotHandler is SquareAnnotArgs annotArgs)
  940. {
  941. selectedArgs.Clear();
  942. selectedArgs.Add(annotArgs);
  943. PropertyPanel.IsSelectedTextAddShape = true;
  944. }
  945. }
  946. }
  947. }
  948. else
  949. {
  950. squareArgs = selectedArgs[0] as SquareAnnotArgs;
  951. }
  952. AddToPropertyPanel("SharpsAnnotProperty", "Rect", selectedArgs);
  953. return squareArgs;
  954. }
  955. /// <summary>
  956. /// 圆
  957. /// </summary>
  958. /// <param name="selectedArgs"></param>
  959. /// <returns></returns>
  960. public AnnotHandlerEventArgs GetCircle(List<AnnotHandlerEventArgs> selectedArgs = null)
  961. {
  962. CircleAnnotArgs circleAnnotArgs = null;
  963. if (selectedArgs == null || selectedArgs.Count == 0)
  964. {
  965. circleAnnotArgs = new CircleAnnotArgs();
  966. var annotate = Settings.Default.AppProperties.Annotate;
  967. if (annotate != null)
  968. {
  969. circleAnnotArgs.LineColor = annotate.CircleBorderColor;
  970. circleAnnotArgs.BgColor = annotate.CircleFillColor;
  971. }
  972. else
  973. {
  974. circleAnnotArgs.LineColor = Colors.Red;
  975. circleAnnotArgs.BgColor = Colors.Red;
  976. }
  977. if (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] == null)
  978. {
  979. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(circleAnnotArgs.EventType);
  980. if (defaultAnnot == null)
  981. {
  982. defaultAnnot = new DefaultAnnotProperty();
  983. defaultAnnot.AnnotToolType = circleAnnotArgs.EventType;
  984. defaultAnnot.Thickness = 1;
  985. defaultAnnot.Opacity = 1;
  986. defaultAnnot.NoteText = string.Empty;
  987. defaultAnnot.DashArray = null;
  988. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  989. Settings.Default.Save();
  990. }
  991. circleAnnotArgs.LineWidth = defaultAnnot.Thickness;
  992. circleAnnotArgs.Transparency = defaultAnnot.Opacity;
  993. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  994. {
  995. circleAnnotArgs.LineDash = DashStyles.Solid;
  996. }
  997. else
  998. {
  999. var collect = new DoubleCollection();
  1000. foreach (var item in defaultAnnot.DashArray)
  1001. {
  1002. collect.Add(item);
  1003. }
  1004. if (circleAnnotArgs.LineDash == null)
  1005. circleAnnotArgs.LineDash = new DashStyle();
  1006. circleAnnotArgs.LineDash.Dashes = collect;
  1007. }
  1008. }
  1009. else
  1010. {
  1011. CircleAnnotArgs circleAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotCircle] as CircleAnnotArgs;
  1012. circleAnnotArgs.LineColor = circleAnnot.LineColor;
  1013. circleAnnotArgs.BgColor = circleAnnot.BgColor;
  1014. circleAnnotArgs.LineWidth = circleAnnot.LineWidth;
  1015. circleAnnotArgs.Transparency = circleAnnot.Transparency;
  1016. circleAnnotArgs.LineDash = circleAnnot.LineDash;
  1017. circleAnnotArgs.ClientRect = Rect.Empty;
  1018. }
  1019. if (circleAnnotArgs != null)
  1020. {
  1021. selectedArgs = new List<AnnotHandlerEventArgs>();
  1022. selectedArgs.Add(circleAnnotArgs);
  1023. if (StrAnnotToolChecked == "Rect")
  1024. {
  1025. AnnotHandlerEventArgs annotHandler = CreateAnnotFromSelectPageText(circleAnnotArgs);
  1026. if (annotHandler is CircleAnnotArgs annotArgs)
  1027. {
  1028. selectedArgs.Clear();
  1029. selectedArgs.Add(annotArgs);
  1030. PropertyPanel.IsSelectedTextAddShape = true;
  1031. }
  1032. }
  1033. }
  1034. }
  1035. else
  1036. {
  1037. circleAnnotArgs = selectedArgs[0] as CircleAnnotArgs;
  1038. }
  1039. AddToPropertyPanel("SharpsAnnotProperty", "Circle", selectedArgs);
  1040. return circleAnnotArgs;
  1041. }
  1042. /// <summary>
  1043. /// 箭头 线
  1044. /// </summary>
  1045. /// <param name="TagStr"></param>
  1046. /// <param name="selectedArgs"></param>
  1047. /// <returns></returns>
  1048. public AnnotHandlerEventArgs GetArrowLine(string TagStr, List<AnnotHandlerEventArgs> selectedArgs = null)
  1049. {
  1050. LineAnnotArgs lineArgs = new LineAnnotArgs();
  1051. if (selectedArgs == null || selectedArgs.Count == 0)
  1052. {
  1053. //var annotate = Settings.Default.AppProperties.Annotate;
  1054. //if (annotate != null)
  1055. //{
  1056. // lineArgs.LineColor = annotate.LineColor;
  1057. //}
  1058. //else
  1059. //{
  1060. // lineArgs.LineColor = Colors.Red;
  1061. //}
  1062. //lineArgs.LineColor = Colors.Red;
  1063. lineArgs.HeadLineType = C_LINE_TYPE.LINETYPE_NONE;
  1064. bool isLastAnnot = false;
  1065. if (TagStr == "Line")
  1066. {
  1067. lineArgs.LineColor = (LineColor as SolidColorBrush).Color;
  1068. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_NONE;
  1069. isLastAnnot = (PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] != null ? true : false);
  1070. }
  1071. else
  1072. {
  1073. lineArgs.LineColor = (ArrowColor as SolidColorBrush).Color;
  1074. lineArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
  1075. isLastAnnot = (PropertyPanel.LastArrowAnnot != null ? true : false);
  1076. }
  1077. if (isLastAnnot == false)
  1078. {
  1079. var defaultAnnot = SettingHelper.GetAnnotDefaultProperty(lineArgs.EventType);
  1080. if (defaultAnnot == null)
  1081. {
  1082. defaultAnnot = new DefaultAnnotProperty();
  1083. defaultAnnot.AnnotToolType = lineArgs.EventType;
  1084. defaultAnnot.Thickness = 1;
  1085. defaultAnnot.Opacity = 1;
  1086. defaultAnnot.NoteText = string.Empty;
  1087. defaultAnnot.DashArray = null;
  1088. SettingHelper.SetAnnotDefaultProperty(defaultAnnot);
  1089. Settings.Default.Save();
  1090. }
  1091. lineArgs.LineDash = DashStyles.Solid;
  1092. lineArgs.LineWidth = defaultAnnot.Thickness;
  1093. lineArgs.Transparency = defaultAnnot.Opacity;
  1094. if (defaultAnnot.DashArray == null || defaultAnnot.DashArray.Count == 0)
  1095. {
  1096. lineArgs.LineDash = DashStyles.Solid;
  1097. }
  1098. else
  1099. {
  1100. var collect = new DoubleCollection();
  1101. foreach (var item in defaultAnnot.DashArray)
  1102. {
  1103. collect.Add(item);
  1104. }
  1105. if (lineArgs.LineDash == null)
  1106. lineArgs.LineDash = new DashStyle();
  1107. lineArgs.LineDash.Dashes = collect;
  1108. }
  1109. }
  1110. else
  1111. {
  1112. LineAnnotArgs lineAnnot = null;
  1113. if (lineArgs.TailLineType == C_LINE_TYPE.LINETYPE_ARROW)
  1114. {
  1115. lineAnnot = PropertyPanel.LastArrowAnnot as LineAnnotArgs;
  1116. }
  1117. else
  1118. {
  1119. lineAnnot = PropertyPanel.LastAnnotDict[AnnotArgsType.AnnotLine] as LineAnnotArgs;
  1120. }
  1121. lineArgs.LineColor = lineAnnot.LineColor;
  1122. lineArgs.HeadLineType = lineAnnot.HeadLineType;
  1123. lineArgs.TailLineType = lineAnnot.TailLineType;
  1124. lineArgs.LineWidth = lineAnnot.LineWidth;
  1125. lineArgs.Transparency = lineAnnot.Transparency;
  1126. lineArgs.LineDash = lineAnnot.LineDash;
  1127. }
  1128. if (lineArgs != null)
  1129. {
  1130. selectedArgs = new List<AnnotHandlerEventArgs>();
  1131. selectedArgs.Add(lineArgs);
  1132. }
  1133. }
  1134. else
  1135. {
  1136. lineArgs = selectedArgs[0] as LineAnnotArgs;
  1137. }
  1138. AddToPropertyPanel("SharpsAnnotProperty", TagStr, selectedArgs);
  1139. return lineArgs;
  1140. }
  1141. /// <summary>
  1142. /// 图章
  1143. /// </summary>
  1144. /// <returns></returns>
  1145. private AnnotHandlerEventArgs GetStamp()
  1146. {
  1147. StampAnnotArgs stampAnnotArgs = new StampAnnotArgs();
  1148. stampAnnotArgs.Opacity = 1;
  1149. stampAnnotArgs.StampText = "APPROVED";
  1150. stampAnnotArgs.Type = StampType.STANDARD_STAMP;
  1151. List<AnnotHandlerEventArgs> stampAnnotArgsList = new List<AnnotHandlerEventArgs>();
  1152. if (stampAnnotArgs != null)
  1153. stampAnnotArgsList.Add(stampAnnotArgs);
  1154. if (string.IsNullOrEmpty(StrAnnotToolChecked) || StrAnnotToolChecked != "Stamp")
  1155. {
  1156. if (IsNoSelectMenu)
  1157. {
  1158. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1159. return stampAnnotArgs;
  1160. }
  1161. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  1162. return stampAnnotArgs;
  1163. }
  1164. AddToPropertyPanel("StampAnnotProperty", null, stampAnnotArgsList);
  1165. return stampAnnotArgs;
  1166. }
  1167. /// <summary>
  1168. /// 签名
  1169. /// </summary>
  1170. /// <returns></returns>
  1171. private AnnotHandlerEventArgs GetSignature()
  1172. {
  1173. AddToPropertyPanel("SignatureAnnotProperty");
  1174. return null;
  1175. }
  1176. private AnnotHandlerEventArgs GetImage()
  1177. {
  1178. StampAnnotArgs stampArgs = new StampAnnotArgs();
  1179. stampArgs.Opacity = 1;
  1180. stampArgs.Type = StampType.IMAGE_STAMP;
  1181. OpenFileDialog openFileDialog = new OpenFileDialog();
  1182. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  1183. if (openFileDialog.ShowDialog() == true)
  1184. {
  1185. stampArgs.ImagePath = openFileDialog.FileName;
  1186. }
  1187. List<AnnotHandlerEventArgs> stampArgsList = new List<AnnotHandlerEventArgs>();
  1188. if (stampArgs != null)
  1189. stampArgsList.Add(stampArgs);
  1190. AddToPropertyPanel("ImageAnnotProperty", null, stampArgsList);
  1191. return stampArgs;
  1192. }
  1193. /// <summary>
  1194. /// 内容选择
  1195. /// </summary>
  1196. /// <param name="annotBtn"></param>
  1197. /// <returns></returns>
  1198. private AnnotHandlerEventArgs GetSnapshotEdit()
  1199. {
  1200. SnapshotEditToolArgs snapshotArgs = new SnapshotEditToolArgs();
  1201. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = new SnapshotEditMenuViewModel();
  1202. snapshotArgs.ControlPointColor = Colors.White;
  1203. snapshotArgs.BgColor = Color.FromArgb(0x99, 0x00, 0x00, 0x00);
  1204. snapshotArgs.LineColor = Color.FromArgb(0xFF, 0x47, 0x7E, 0xDE);
  1205. SnapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1206. SnapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1207. SnapshotEditMenuViewModel.SnapToolEvent -= SnapshotEditMenuViewModel_SnapToolEvent;
  1208. SnapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1209. #region to do
  1210. //SnapshotEditMenu snapMenu = new SnapshotEditMenu();
  1211. //snapshotArgs.ToolPanel = snapMenu;
  1212. //SnapshotEditMenuViewModel snapshotEditMenuViewModel = (SnapshotEditMenuViewModel)snapMenu.DataContext;
  1213. //snapshotEditMenuViewModel.SnapToolArgs = snapshotArgs;
  1214. //snapshotEditMenuViewModel.PDFViewer = PDFViewer;
  1215. //snapshotEditMenuViewModel.ToggleBtn = annotBtn;
  1216. //snapshotEditMenuViewModel.SnapToolEvent += SnapshotEditMenuViewModel_SnapToolEvent;
  1217. //SnapshotEditMenuViewModel = snapshotEditMenuViewModel;
  1218. #endregion to do
  1219. StrAnnotToolChecked = "";
  1220. return snapshotArgs;
  1221. }
  1222. #endregion 注释工具
  1223. #region 菜单
  1224. private bool InBookModeSetIsEnabled(MenuItem menuItem)
  1225. {
  1226. if (viewContentViewModel.mainViewModel.IsBookMode)
  1227. {
  1228. menuItem.IsEnabled = false;
  1229. return true;
  1230. }
  1231. else
  1232. {
  1233. menuItem.IsEnabled = true;
  1234. return false;
  1235. }
  1236. }
  1237. private void ExportPicture_MenuItemClick()
  1238. {
  1239. //图片提取
  1240. try
  1241. {
  1242. List<System.Drawing.Bitmap> imageList = new List<System.Drawing.Bitmap>();
  1243. Dictionary<int, List<System.Drawing.Bitmap>> imageDict = PDFViewer?.GetSelectedImages();
  1244. foreach (int pageIndex in imageDict.Keys)
  1245. {
  1246. imageList = imageDict[pageIndex];
  1247. }
  1248. string path = PDFViewer.Document.FileName;
  1249. System.Windows.Forms.FolderBrowserDialog folderDialog = new FolderBrowserDialog();
  1250. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  1251. {
  1252. int i = 1;
  1253. int pagenum = 1;
  1254. string choosePath = folderDialog.SelectedPath;
  1255. string sPath = choosePath + "\\" + path + "_Extract Image";
  1256. sPath = GetExportPathName(sPath);
  1257. if (!Directory.Exists(sPath))
  1258. {
  1259. Directory.CreateDirectory(sPath);
  1260. }
  1261. if (Directory.Exists(sPath))
  1262. {
  1263. foreach (System.Drawing.Bitmap image in imageList)
  1264. {
  1265. foreach (var item in imageDict.Keys)
  1266. {
  1267. pagenum = item;
  1268. }
  1269. string filename = path + "_" + "Page" + (pagenum + 1).ToString() + "_" + GetNum(i);
  1270. string savePath = System.IO.Path.Combine(sPath, filename + ".jpg");
  1271. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  1272. i++;
  1273. }
  1274. System.Diagnostics.Process.Start("explorer", "/select,\"" + sPath + "\"");
  1275. }
  1276. }
  1277. }
  1278. catch (Exception ex) { }
  1279. }
  1280. public string GetExportPathName(string path)
  1281. {
  1282. int i = 1;
  1283. string outpath = path;
  1284. while (Directory.Exists(outpath))
  1285. {
  1286. outpath = path + $"({i.ToString()})";
  1287. i++;
  1288. }
  1289. return outpath;
  1290. }
  1291. private string GetNum(int num)
  1292. {
  1293. if (num % 10 < 1)
  1294. {
  1295. return "00" + num.ToString();
  1296. }
  1297. if (num % 10 >= 1 && num % 10 < 10)
  1298. {
  1299. return "0" + num.ToString();
  1300. }
  1301. else
  1302. {
  1303. return num.ToString();
  1304. }
  1305. }
  1306. #endregion 菜单
  1307. }
  1308. }