AnnotToolContentViewModel.Function.cs 54 KB

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