StampAnnotPropertyViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKit.PDFPage;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Microsoft.Win32;
  7. using PDF_Office.Helper;
  8. using PDF_Office.Model;
  9. using PDF_Office.Model.AnnotPanel;
  10. using PDF_Office.Properties;
  11. using Prism.Commands;
  12. using Prism.Mvvm;
  13. using Prism.Regions;
  14. using Prism.Services.Dialogs;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Collections.ObjectModel;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Reflection;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using System.Windows;
  24. using System.Windows.Media;
  25. using System.Windows.Media.Imaging;
  26. using static Dropbox.Api.Files.FileCategory;
  27. namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
  28. {
  29. internal class StampAnnotPropertyViewModel : BindableBase, INavigationAware
  30. {
  31. #region 标准图章相关默认配置(如果需要修改,要留意按顺序一一对应的,如果要支持多语,Path则需要替换成SDK获取图片的方法,并修改对应参数与实现代码)
  32. List<string> Path = new List<string>
  33. {
  34. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Approved.png",
  35. "pack://application:,,,/PDF Office;component/Resources/StampIcons/NotApproved.png",
  36. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Completed.png",
  37. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Final.png",
  38. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Draft.png",
  39. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Confidential.png",
  40. "pack://application:,,,/PDF Office;component/Resources/StampIcons/ForPublicRelease.png",
  41. "pack://application:,,,/PDF Office;component/Resources/StampIcons/NotForPublicRelease.png",
  42. "pack://application:,,,/PDF Office;component/Resources/StampIcons/ForComment.png",
  43. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Void.png",
  44. "pack://application:,,,/PDF Office;component/Resources/StampIcons/PreliminaryResults.png",
  45. "pack://application:,,,/PDF Office;component/Resources/StampIcons/InformationOnly.png",
  46. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Accepted.png",
  47. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Rejected.png",
  48. "pack://application:,,,/PDF Office;component/Resources/StampIcons/Witness.png",
  49. "pack://application:,,,/PDF Office;component/Resources/StampIcons/InitialHere.png",
  50. "pack://application:,,,/PDF Office;component/Resources/StampIcons/SignHere.png",
  51. "pack://application:,,,/PDF Office;component/Resources/StampIcons/revised.png",
  52. "pack://application:,,,/PDF Office;component/Resources/StampIcons/PrivateMark1.png",
  53. "pack://application:,,,/PDF Office;component/Resources/StampIcons/PrivateMark2.png",
  54. "pack://application:,,,/PDF Office;component/Resources/StampIcons/PrivateMark3.png",
  55. };
  56. List<string> StampText = new List<string>
  57. {
  58. "Approved","NotApproved","Completed","Final","Draft","Confidential","ForPublicRelease","NotForPublicRelease",
  59. "ForComment","Void","PreliminaryResults","InformationOnly","Accepted","Rejected","Witness","InitialHere","SignHere",
  60. "revised","PrivateMark#1","PrivateMark#2","PrivateMark#3"
  61. };
  62. List<int> MaxWidth = new List<int>
  63. {
  64. 218,292,234,130,150,280,386,461,282,121,405,366,30,30,133,133,133,173,30,30,30
  65. };
  66. List<int> MaxHeight = new List<int>
  67. {
  68. 66,66,66,66,66,66,66,66,66,66,66,66,30,30,39,39,39,66,30,30,30
  69. };
  70. #endregion
  71. #region 动态图章相关配置(需要支持多语则修改DynamicStampText的内容)
  72. List<string> DynamicStampText = new List<string>
  73. {
  74. "REVISED","REVIEWED","Completed","RECEIVED","APPROVED","CONFIDENTIAL"
  75. };
  76. List<C_TEXTSTAMP_COLOR> DynamicColor = new List<C_TEXTSTAMP_COLOR>
  77. {
  78. C_TEXTSTAMP_COLOR.TEXTSTAMP_RED, C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,
  79. C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,
  80. C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN,C_TEXTSTAMP_COLOR.TEXTSTAMP_RED,
  81. };
  82. #endregion
  83. private string author = "12312";
  84. public string Author
  85. {
  86. get { return author; }
  87. set
  88. {
  89. SetProperty(ref author, value);
  90. }
  91. }
  92. private bool isSetAuthor = false;
  93. public bool IsSetAuthor
  94. {
  95. get { return isSetAuthor; }
  96. set
  97. {
  98. SetProperty(ref isSetAuthor, value);
  99. }
  100. }
  101. private int tabControlSelectedIndex = 0;
  102. public int TabControlSelectedIndex
  103. {
  104. get { return tabControlSelectedIndex; }
  105. set
  106. {
  107. SetProperty(ref tabControlSelectedIndex, value);
  108. if (tabControlSelectedIndex == 0)
  109. {
  110. UnStandard = false;
  111. }
  112. else
  113. {
  114. UnStandard = true;
  115. }
  116. }
  117. }
  118. private int cusListboxIndex = -1;
  119. public int CusListboxIndex
  120. {
  121. get { return cusListboxIndex; }
  122. set
  123. {
  124. SetProperty(ref cusListboxIndex, value);
  125. }
  126. }
  127. private bool unStandard;
  128. /// <summary>
  129. /// 判断当前是否为非标准图章,控制UI展示
  130. /// </summary>
  131. public bool UnStandard
  132. {
  133. get { return unStandard; }
  134. set
  135. {
  136. SetProperty(ref unStandard, value);
  137. }
  138. }
  139. /// <summary>
  140. /// 日期格式
  141. /// </summary>
  142. private string dateType = "F";
  143. private IDialogService dialogs;
  144. public DelegateCommand ShowDialogCommand { get; set; }
  145. private CPDFViewer PDFViewer;
  146. public ObservableCollection<Stamp> StandardStampList { get; set; }
  147. public ObservableCollection<Stamp> DynamicStampList { get; set; }
  148. public ObservableCollection<Stamp> CustomStampList { get; set; }
  149. public StampAnnotPropertyViewModel(IDialogService dialogService)
  150. {
  151. dialogs = dialogService;
  152. StandardStampList = new ObservableCollection<Stamp>();
  153. DynamicStampList = new ObservableCollection<Stamp>();
  154. CustomStampList = new ObservableCollection<Stamp>();
  155. ShowDialogCommand = new DelegateCommand(ShowDialog);
  156. InitStandardStamp();
  157. UpDataDynamicStampList();
  158. LoadSettings();
  159. }
  160. /// <summary>
  161. /// 加载缓存的自定义图章
  162. /// </summary>
  163. private void LoadSettings()
  164. {
  165. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  166. if (stamps != null)
  167. {
  168. for (int i = 0; i < stamps.Count; i++)
  169. {
  170. Stamp customStamp = new Stamp();
  171. customStamp.Opacity = 1;
  172. customStamp.Author = stamps[i].Author;
  173. customStamp.StampText = stamps[i].StampText;
  174. customStamp.StampTextDate = stamps[i].StampTextDate;
  175. customStamp.MaxWidth = stamps[i].ImageWidth;
  176. customStamp.MaxHeight = stamps[i].ImageHeight;
  177. customStamp.SourcePath = stamps[i].SourcePath;
  178. customStamp.Type = stamps[i].Type;
  179. customStamp.TextSharp = stamps[i].TextSharp;
  180. customStamp.TextColor = stamps[i].TextColor;
  181. customStamp.IsCheckedTime = stamps[i].IsCheckedTime;
  182. customStamp.IsCheckedDate = stamps[i].IsCheckedDate;
  183. CustomStampList.Add(customStamp);
  184. }
  185. }
  186. }
  187. /// <summary>
  188. /// 初始化标准图章相关内容
  189. /// </summary>
  190. private void InitStandardStamp()
  191. {
  192. for (int i = 0; i < Path.Count; i++)
  193. {
  194. Stamp standardStamp = new Stamp();
  195. standardStamp.Author = "";
  196. standardStamp.Opacity = 1;
  197. standardStamp.SourcePath = Path[i];
  198. standardStamp.StampText = StampText[i];
  199. standardStamp.MaxWidth = MaxWidth[i];
  200. standardStamp.MaxHeight = MaxHeight[i];
  201. standardStamp.Type = StampType.STANDARD_STAMP;
  202. StandardStampList.Add(standardStamp);
  203. }
  204. }
  205. public bool IsNavigationTarget(NavigationContext navigationContext)
  206. {
  207. return true;
  208. }
  209. public void OnNavigatedFrom(NavigationContext navigationContext)
  210. {
  211. return;
  212. }
  213. public void OnNavigatedTo(NavigationContext navigationContext)
  214. {
  215. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  216. if (PDFViewer == null)
  217. {
  218. return;
  219. }
  220. }
  221. public void SetDynamicStamp(Stamp stamp)
  222. {
  223. int index = DynamicStampList.IndexOf(stamp);
  224. UpDataDynamicStampList();
  225. SetStamp(DynamicStampList[index]);
  226. }
  227. /// <summary>
  228. /// 在PDFView上创建图章的统一方法
  229. /// </summary>
  230. /// <param name="stamp"></param>
  231. public void SetStamp(Stamp stamp)
  232. {
  233. StampAnnotArgs Args = new StampAnnotArgs();
  234. Args.StampText = stamp.StampText;
  235. Args.Author = stamp.Author;
  236. Args.Opacity = stamp.Opacity;
  237. if (stamp.Type == StampType.IMAGE_STAMP)
  238. {
  239. Args.ImageWidth = stamp.MaxWidth;
  240. Args.ImageHeight = stamp.MaxHeight;
  241. }
  242. else
  243. {
  244. Args.MaxWidth = stamp.MaxWidth;
  245. Args.MaxHeight = stamp.MaxHeight;
  246. }
  247. Args.StampTextDate = stamp.StampTextDate;
  248. Args.TextColor = stamp.TextColor;
  249. Args.TextSharp = stamp.TextSharp;
  250. if (!string.IsNullOrEmpty(stamp.SourcePath))
  251. {
  252. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  253. Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
  254. image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
  255. Args.ImageHeight = image.PixelHeight;
  256. Args.ImageWidth = image.PixelWidth;
  257. }
  258. else
  259. {
  260. Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
  261. stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
  262. Args.ImageHeight = stamp.ImageSource.PixelHeight;
  263. Args.ImageWidth = stamp.ImageSource.PixelWidth;
  264. }
  265. Args.Type = stamp.Type;
  266. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  267. PDFViewer.SetToolParam(Args);
  268. }
  269. /// <summary>
  270. /// 更新动态图章对象相关属性
  271. /// </summary>
  272. public void UpDataDynamicStampList()
  273. {
  274. string time = System.DateTime.Now.ToString(dateType);
  275. for (int i = 0; i < DynamicStampText.Count; i++)
  276. {
  277. string date = "";
  278. //区分机密(CONFIDENTIAL)和其他动态图章的区别
  279. if (i < DynamicStampText.Count - 1)
  280. {
  281. date = time;
  282. }
  283. Stamp standardStamp = new Stamp();
  284. if (IsSetAuthor && !string.IsNullOrEmpty(Author))
  285. {
  286. standardStamp.Author = Author;
  287. if (i < DynamicStampText.Count - 1)
  288. {
  289. standardStamp.StampTextDate = "By " + Author + " at " + date;
  290. }
  291. else
  292. {
  293. standardStamp.StampTextDate = Author;
  294. }
  295. }
  296. else
  297. {
  298. standardStamp.StampTextDate = date;
  299. standardStamp.Author = "";
  300. }
  301. var bytes = CPDFStampAnnotation.GetTempTextStampImage(DynamicStampText[i], standardStamp.StampTextDate,
  302. C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT, DynamicColor[i], out int stampWidth, out int stampHeight, out int width, out int height);
  303. PixelFormat fmt = PixelFormats.Bgra32;
  304. BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, bytes, (width * fmt.BitsPerPixel + 7) / 8);
  305. var flags = BindingFlags.NonPublic | BindingFlags.Static;
  306. var dpiProperty = typeof(SystemParameters).GetProperty("Dpi", flags);
  307. int Dpi = (int)dpiProperty.GetValue(null, null);
  308. standardStamp.Opacity = 1;
  309. standardStamp.SourcePath = "";
  310. standardStamp.StampText = DynamicStampText[i];
  311. standardStamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(stampWidth / 72D * DpiHelpers.Dpi);
  312. standardStamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(stampHeight / 72D * DpiHelpers.Dpi);
  313. standardStamp.Type = StampType.TEXT_STAMP;
  314. standardStamp.ImageSource = bps;
  315. standardStamp.IsCheckedDate = true;
  316. standardStamp.IsCheckedTime = true;
  317. switch (DynamicColor[i])
  318. {
  319. case C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE:
  320. break;
  321. case C_TEXTSTAMP_COLOR.TEXTSTAMP_RED:
  322. standardStamp.TextColor = TextStampColor.TEXTSTAMP_RED;
  323. break;
  324. case C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN:
  325. standardStamp.TextColor = TextStampColor.TEXTSTAMP_GREEN;
  326. break;
  327. case C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE:
  328. break;
  329. default:
  330. break;
  331. }
  332. if (DynamicStampList.Count== DynamicStampText.Count)
  333. {
  334. DynamicStampList[i] = standardStamp;
  335. }
  336. else
  337. {
  338. DynamicStampList.Add(standardStamp);
  339. }
  340. }
  341. }
  342. /// <summary>
  343. /// 导出图章
  344. /// </summary>
  345. public void SaveToPath(string FileType, Stamp Item)
  346. {
  347. SaveFileDialog saveFileDialog = new SaveFileDialog();
  348. saveFileDialog.Title = "保存" + FileType + "文件";
  349. saveFileDialog.Filter = "(*)|*." + FileType;
  350. if (saveFileDialog.ShowDialog() == false)
  351. {
  352. return;
  353. }
  354. BitmapEncoder encoder;
  355. if (FileType.ToUpper() == "JPG")
  356. {
  357. encoder = new JpegBitmapEncoder();
  358. }
  359. else
  360. {
  361. encoder = new PngBitmapEncoder();
  362. }
  363. encoder.Frames.Add(BitmapFrame.Create(new Uri(Item.SourcePath)));
  364. string path = saveFileDialog.FileName;
  365. switch (FileType.ToUpper())
  366. {
  367. case "PDF":
  368. CPDFDocument newDoc = CPDFDocument.CreateDocument();
  369. BitmapFrame frame = BitmapFrame.Create(new Uri(Item.SourcePath));
  370. byte[] imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  371. frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  372. newDoc.InsertPage(0, frame.PixelWidth, frame.PixelHeight, imageData, CPDFDocumentImageMode.CPDFDocumentImageModeScaleToFill);
  373. newDoc.WriteToFilePath(path);
  374. break;
  375. case "PNG":
  376. using (FileStream stream = new FileStream(path, FileMode.Create))
  377. {
  378. encoder.Save(stream);
  379. }
  380. break;
  381. default:
  382. break;
  383. }
  384. System.Diagnostics.Process.Start("explorer", "/select,\"" + path + "\"");
  385. }
  386. public void DeleteStamp(Stamp stamp)
  387. {
  388. int index = CustomStampList.IndexOf(stamp);
  389. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  390. CustomStampList.RemoveAt(index);
  391. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  392. stamps.RemoveAt(index);
  393. Settings.Default.Save();
  394. }
  395. public void DeleteAll()
  396. {
  397. foreach (Stamp item in CustomStampList)
  398. {
  399. App.CachePath.AddToDeleteFiles(item.SourcePath);
  400. }
  401. CustomStampList.Clear();
  402. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  403. stamps.Clear();
  404. Settings.Default.Save();
  405. }
  406. private void ShowDialog()
  407. {
  408. switch (TabControlSelectedIndex)
  409. {
  410. case 1:
  411. ShowDynamicPropertyDialog();
  412. break;
  413. case 2:
  414. ShowCustomCreateDialog(null);
  415. break;
  416. default:
  417. break;
  418. }
  419. }
  420. private void ShowDynamicPropertyDialog()
  421. {
  422. bool result = true;
  423. dialogs.ShowDialog(DialogNames.DynamicPropertyDialog, null, e =>
  424. {
  425. if (e.Result != ButtonResult.OK)
  426. {
  427. result = false;
  428. }
  429. DynamicPropertyDialogViewModel DynamicVM = e.Parameters.GetValue<DynamicPropertyDialogViewModel>(ParameterNames.DataModel);
  430. if (DynamicVM != null)
  431. {
  432. Author = DynamicVM.Author;
  433. IsSetAuthor = DynamicVM.IsChecked;
  434. if (Settings.Default.AppProperties.culture == "en-US")
  435. {
  436. dateType = DynamicVM.SelectedIndex == 0 ? "F" : DynamicVM.DateFormatList[DynamicVM.SelectedIndex] + " HH:mm:ss";
  437. }
  438. else
  439. {
  440. dateType = DynamicVM.SelectedIndex == 0 ? "r" : DynamicVM.DateFormatList[DynamicVM.SelectedIndex] + " HH:mm:ss";
  441. }
  442. UpDataDynamicStampList();
  443. }
  444. });
  445. if (!result)
  446. {
  447. return;
  448. }
  449. }
  450. private void ShowCustomCreateDialog(Stamp stamp)
  451. {
  452. bool result = true;
  453. DialogParameters value = new DialogParameters();
  454. value.Add(ParameterNames.DataModel, stamp);
  455. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  456. {
  457. if (e.Result != ButtonResult.OK)
  458. {
  459. result = false;
  460. }
  461. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  462. if (CustomVM != null)
  463. {
  464. CreateCustomStamp(CustomVM);
  465. }
  466. });
  467. if (!result)
  468. {
  469. return;
  470. }
  471. }
  472. public void EditorCustomStamp(Stamp stamp)
  473. {
  474. bool result = true;
  475. DialogParameters value = new DialogParameters();
  476. value.Add(ParameterNames.DataModel, stamp);
  477. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  478. {
  479. if (e.Result != ButtonResult.OK)
  480. {
  481. result = false;
  482. }
  483. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  484. if (CustomVM != null)
  485. {
  486. UpDataCustomStamp(CustomVM, stamp);
  487. }
  488. });
  489. if (!result)
  490. {
  491. return;
  492. }
  493. }
  494. private void UpDataCustomStamp(CustomCreateDialogViewModel viewModel, Stamp oldstamp)
  495. {
  496. Stamp stamp = new Stamp();
  497. stamp.Author = "";
  498. stamp.Opacity = 1;
  499. stamp.SourcePath = viewModel.SaveToPath;
  500. stamp.StampText = viewModel.StampText;
  501. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  502. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  503. stamp.StampTextDate = viewModel.StampTextDate;
  504. stamp.Type = viewModel.Type;
  505. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  506. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  507. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  508. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  509. int index = CustomStampList.IndexOf(oldstamp);
  510. CustomStampList[index] = stamp;
  511. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  512. if (stamps == null)
  513. {
  514. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  515. }
  516. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  517. Stamp customStamp = new Stamp();
  518. annote.Author = stamp.Author;
  519. annote.StampText = stamp.StampText;
  520. annote.StampTextDate = stamp.StampTextDate;
  521. annote.ImageWidth = stamp.MaxWidth;
  522. annote.ImageHeight = stamp.MaxHeight;
  523. annote.SourcePath = stamp.SourcePath;
  524. annote.Type = stamp.Type;
  525. annote.TextSharp = stamp.TextSharp;
  526. annote.TextColor = stamp.TextColor;
  527. annote.IsCheckedDate = stamp.IsCheckedDate;
  528. annote.IsCheckedTime = stamp.IsCheckedTime;
  529. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  530. stamps[index] = annote;
  531. Settings.Default.Save();
  532. }
  533. /// <summary>
  534. /// 创建自定义图章,并且保存到APP缓存
  535. /// </summary>
  536. private void CreateCustomStamp(CustomCreateDialogViewModel viewModel)
  537. {
  538. Stamp stamp = new Stamp();
  539. stamp.Author = "";
  540. stamp.Opacity = 1;
  541. if (viewModel.IsRemoveBackground)
  542. {
  543. if (!string.IsNullOrEmpty(viewModel.SaveToPath))
  544. {
  545. App.CachePath.AddToDeleteFiles(viewModel.SaveToPath);
  546. }
  547. stamp.SourcePath = viewModel.RemoveBackgroundSaveToPath;
  548. }
  549. else
  550. {
  551. stamp.SourcePath = viewModel.SaveToPath;
  552. }
  553. stamp.StampText = viewModel.StampText;
  554. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  555. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  556. stamp.StampTextDate = viewModel.StampTextDate;
  557. stamp.Type = viewModel.Type;
  558. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  559. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  560. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  561. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  562. CustomStampList.Add(stamp);
  563. //缓存数据
  564. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  565. if (stamps == null)
  566. {
  567. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  568. }
  569. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  570. annote.Author = stamp.Author;
  571. annote.StampText = stamp.StampText;
  572. annote.StampTextDate = stamp.StampTextDate;
  573. annote.ImageWidth = stamp.MaxWidth;
  574. annote.ImageHeight = stamp.MaxHeight;
  575. annote.SourcePath = stamp.SourcePath;
  576. annote.Type = stamp.Type;
  577. annote.TextSharp = stamp.TextSharp;
  578. annote.TextColor = stamp.TextColor;
  579. annote.IsCheckedDate = stamp.IsCheckedDate;
  580. annote.IsCheckedTime = stamp.IsCheckedTime;
  581. stamps.Add(annote);
  582. Settings.Default.Save();
  583. SetStamp(stamp);
  584. CusListboxIndex = CustomStampList.Count - 1;
  585. }
  586. }
  587. }