AnnotToolContentViewModel.Function.cs 56 KB

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