StampAnnotPropertyViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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_Master.Helper;
  8. using PDF_Master.Model;
  9. using PDF_Master.Model.AnnotPanel;
  10. using PDF_Master.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_Master.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 Master;component/Resources/StampIcons/Approved.png",
  35. "pack://application:,,,/PDF Master;component/Resources/StampIcons/NotApproved.png",
  36. "pack://application:,,,/PDF Master;component/Resources/StampIcons/Completed.png",
  37. "pack://application:,,,/PDF Master;component/Resources/StampIcons/Final.png",
  38. "pack://application:,,,/PDF Master;component/Resources/StampIcons/Draft.png",
  39. "pack://application:,,,/PDF Master;component/Resources/StampIcons/Confidential.png",
  40. "pack://application:,,,/PDF Master;component/Resources/StampIcons/ForPublicRelease.png",
  41. "pack://application:,,,/PDF Master;component/Resources/StampIcons/NotForPublicRelease.png",
  42. "pack://application:,,,/PDF Master;component/Resources/StampIcons/ForComment.png",
  43. "pack://application:,,,/PDF Master;component/Resources/StampIcons/Void.png",
  44. "pack://application:,,,/PDF Master;component/Resources/StampIcons/PreliminaryResults.png",
  45. "pack://application:,,,/PDF Master;component/Resources/StampIcons/InformationOnly.png",
  46. "pack://application:,,,/PDF Master;component/Resources/StampIcons/Accepted.png",
  47. "pack://application:,,,/PDF Master;component/Resources/StampIcons/Rejected.png",
  48. "pack://application:,,,/PDF Master;component/Resources/StampIcons/Witness.png",
  49. "pack://application:,,,/PDF Master;component/Resources/StampIcons/InitialHere.png",
  50. "pack://application:,,,/PDF Master;component/Resources/StampIcons/SignHere.png",
  51. "pack://application:,,,/PDF Master;component/Resources/StampIcons/revised.png",
  52. "pack://application:,,,/PDF Master;component/Resources/StampIcons/PrivateMark1.png",
  53. "pack://application:,,,/PDF Master;component/Resources/StampIcons/PrivateMark2.png",
  54. "pack://application:,,,/PDF Master;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. private ViewContentViewModel viewContentViewModel;
  147. public ObservableCollection<Stamp> StandardStampList { get; set; }
  148. public ObservableCollection<Stamp> DynamicStampList { get; set; }
  149. public ObservableCollection<Stamp> CustomStampList { get; set; }
  150. public StampAnnotPropertyViewModel(IDialogService dialogService)
  151. {
  152. dialogs = dialogService;
  153. StandardStampList = new ObservableCollection<Stamp>();
  154. DynamicStampList = new ObservableCollection<Stamp>();
  155. CustomStampList = new ObservableCollection<Stamp>();
  156. ShowDialogCommand = new DelegateCommand(ShowDialog);
  157. InitStandardStamp();
  158. UpDataDynamicStampList();
  159. LoadSettings();
  160. }
  161. /// <summary>
  162. /// 加载缓存的自定义图章
  163. /// </summary>
  164. private void LoadSettings()
  165. {
  166. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  167. if (stamps != null)
  168. {
  169. for (int i = 0; i < stamps.Count; i++)
  170. {
  171. Stamp customStamp = new Stamp();
  172. customStamp.Opacity = 1;
  173. customStamp.Author = stamps[i].Author;
  174. customStamp.StampText = stamps[i].StampText;
  175. customStamp.StampTextDate = stamps[i].StampTextDate;
  176. customStamp.MaxWidth = stamps[i].ImageWidth;
  177. customStamp.MaxHeight = stamps[i].ImageHeight;
  178. customStamp.SourcePath = stamps[i].SourcePath;
  179. customStamp.Type = stamps[i].Type;
  180. customStamp.TextSharp = stamps[i].TextSharp;
  181. customStamp.TextColor = stamps[i].TextColor;
  182. customStamp.IsCheckedTime = stamps[i].IsCheckedTime;
  183. customStamp.IsCheckedDate = stamps[i].IsCheckedDate;
  184. CustomStampList.Add(customStamp);
  185. }
  186. }
  187. }
  188. /// <summary>
  189. /// 初始化标准图章相关内容
  190. /// </summary>
  191. private void InitStandardStamp()
  192. {
  193. for (int i = 0; i < Path.Count; i++)
  194. {
  195. Stamp standardStamp = new Stamp();
  196. standardStamp.Author = "";
  197. standardStamp.Opacity = 1;
  198. standardStamp.SourcePath = Path[i];
  199. standardStamp.StampText = StampText[i];
  200. standardStamp.MaxWidth = MaxWidth[i];
  201. standardStamp.MaxHeight = MaxHeight[i];
  202. standardStamp.Type = StampType.STANDARD_STAMP;
  203. StandardStampList.Add(standardStamp);
  204. }
  205. }
  206. public bool IsNavigationTarget(NavigationContext navigationContext)
  207. {
  208. return true;
  209. }
  210. public void OnNavigatedFrom(NavigationContext navigationContext)
  211. {
  212. return;
  213. }
  214. public void OnNavigatedTo(NavigationContext navigationContext)
  215. {
  216. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  217. if (PDFViewer == null)
  218. {
  219. return;
  220. }
  221. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  222. }
  223. public void Close()
  224. {
  225. PDFViewer.SetMouseMode(MouseModes.PanTool);
  226. viewContentViewModel.IsPropertyOpen = false;
  227. }
  228. public void SetDynamicStamp(Stamp stamp)
  229. {
  230. int index = DynamicStampList.IndexOf(stamp);
  231. UpDataDynamicStampList();
  232. SetStamp(DynamicStampList[index]);
  233. }
  234. /// <summary>
  235. /// 在PDFView上创建图章的统一方法
  236. /// </summary>
  237. /// <param name="stamp"></param>
  238. public void SetStamp(Stamp stamp)
  239. {
  240. StampAnnotArgs Args = new StampAnnotArgs();
  241. Args.StampText = stamp.StampText;
  242. Args.Author = stamp.Author;
  243. Args.Opacity = stamp.Opacity;
  244. if (stamp.Type == StampType.IMAGE_STAMP)
  245. {
  246. Args.ImageWidth = stamp.MaxWidth;
  247. Args.ImageHeight = stamp.MaxHeight;
  248. }
  249. else
  250. {
  251. Args.MaxWidth = stamp.MaxWidth;
  252. Args.MaxHeight = stamp.MaxHeight;
  253. }
  254. Args.StampTextDate = stamp.StampTextDate;
  255. Args.TextColor = stamp.TextColor;
  256. Args.TextSharp = stamp.TextSharp;
  257. if (!string.IsNullOrEmpty(stamp.SourcePath))
  258. {
  259. BitmapImage image = new BitmapImage(new Uri(stamp.SourcePath));
  260. Args.ImageArray = new byte[image.PixelWidth * image.PixelHeight * 4];
  261. image.CopyPixels(Args.ImageArray, image.PixelWidth * 4, 0);
  262. Args.ImageHeight = image.PixelHeight;
  263. Args.ImageWidth = image.PixelWidth;
  264. }
  265. else
  266. {
  267. Args.ImageArray = new byte[stamp.ImageSource.PixelWidth * stamp.ImageSource.PixelHeight * 4];
  268. stamp.ImageSource.CopyPixels(Args.ImageArray, stamp.ImageSource.PixelWidth * 4, 0);
  269. Args.ImageHeight = stamp.ImageSource.PixelHeight;
  270. Args.ImageWidth = stamp.ImageSource.PixelWidth;
  271. }
  272. Args.Type = stamp.Type;
  273. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  274. PDFViewer.SetToolParam(Args);
  275. }
  276. /// <summary>
  277. /// 更新动态图章对象相关属性
  278. /// </summary>
  279. public void UpDataDynamicStampList()
  280. {
  281. string time = System.DateTime.Now.ToString(dateType);
  282. for (int i = 0; i < DynamicStampText.Count; i++)
  283. {
  284. string date = "";
  285. //区分机密(CONFIDENTIAL)和其他动态图章的区别
  286. if (i < DynamicStampText.Count - 1)
  287. {
  288. date = time;
  289. }
  290. Stamp standardStamp = new Stamp();
  291. if (IsSetAuthor && !string.IsNullOrEmpty(Author))
  292. {
  293. standardStamp.Author = Author;
  294. if (i < DynamicStampText.Count - 1)
  295. {
  296. standardStamp.StampTextDate = "By " + Author + " at " + date;
  297. }
  298. else
  299. {
  300. standardStamp.StampTextDate = Author;
  301. }
  302. }
  303. else
  304. {
  305. standardStamp.StampTextDate = date;
  306. standardStamp.Author = "";
  307. }
  308. var bytes = CPDFStampAnnotation.GetTempTextStampImage(DynamicStampText[i], standardStamp.StampTextDate,
  309. C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT, DynamicColor[i], out int stampWidth, out int stampHeight, out int width, out int height);
  310. PixelFormat fmt = PixelFormats.Bgra32;
  311. BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, bytes, (width * fmt.BitsPerPixel + 7) / 8);
  312. var flags = BindingFlags.NonPublic | BindingFlags.Static;
  313. var dpiProperty = typeof(SystemParameters).GetProperty("Dpi", flags);
  314. int Dpi = (int)dpiProperty.GetValue(null, null);
  315. standardStamp.Opacity = 1;
  316. standardStamp.SourcePath = "";
  317. standardStamp.StampText = DynamicStampText[i];
  318. standardStamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(stampWidth / 72D * DpiHelpers.Dpi);
  319. standardStamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(stampHeight / 72D * DpiHelpers.Dpi);
  320. standardStamp.Type = StampType.TEXT_STAMP;
  321. standardStamp.ImageSource = bps;
  322. standardStamp.IsCheckedDate = true;
  323. standardStamp.IsCheckedTime = true;
  324. switch (DynamicColor[i])
  325. {
  326. case C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE:
  327. break;
  328. case C_TEXTSTAMP_COLOR.TEXTSTAMP_RED:
  329. standardStamp.TextColor = TextStampColor.TEXTSTAMP_RED;
  330. break;
  331. case C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN:
  332. standardStamp.TextColor = TextStampColor.TEXTSTAMP_GREEN;
  333. break;
  334. case C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE:
  335. break;
  336. default:
  337. break;
  338. }
  339. if (DynamicStampList.Count== DynamicStampText.Count)
  340. {
  341. DynamicStampList[i] = standardStamp;
  342. }
  343. else
  344. {
  345. DynamicStampList.Add(standardStamp);
  346. }
  347. }
  348. }
  349. /// <summary>
  350. /// 导出图章
  351. /// </summary>
  352. public void SaveToPath(string FileType, Stamp Item)
  353. {
  354. SaveFileDialog saveFileDialog = new SaveFileDialog();
  355. saveFileDialog.Title = "保存" + FileType + "文件";
  356. saveFileDialog.Filter = "(*)|*." + FileType;
  357. if (saveFileDialog.ShowDialog() == false)
  358. {
  359. return;
  360. }
  361. BitmapEncoder encoder;
  362. if (FileType.ToUpper() == "JPG")
  363. {
  364. encoder = new JpegBitmapEncoder();
  365. }
  366. else
  367. {
  368. encoder = new PngBitmapEncoder();
  369. }
  370. encoder.Frames.Add(BitmapFrame.Create(new Uri(Item.SourcePath)));
  371. string path = saveFileDialog.FileName;
  372. switch (FileType.ToUpper())
  373. {
  374. case "PDF":
  375. CPDFDocument newDoc = CPDFDocument.CreateDocument();
  376. BitmapFrame frame = BitmapFrame.Create(new Uri(Item.SourcePath));
  377. byte[] imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  378. frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  379. newDoc.InsertPage(0, frame.PixelWidth, frame.PixelHeight, imageData, CPDFDocumentImageMode.CPDFDocumentImageModeScaleToFill);
  380. newDoc.WriteToFilePath(path);
  381. break;
  382. case "PNG":
  383. using (FileStream stream = new FileStream(path, FileMode.Create))
  384. {
  385. encoder.Save(stream);
  386. }
  387. break;
  388. default:
  389. break;
  390. }
  391. System.Diagnostics.Process.Start("explorer", "/select,\"" + path + "\"");
  392. }
  393. public void DeleteStamp(Stamp stamp)
  394. {
  395. int index = CustomStampList.IndexOf(stamp);
  396. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  397. CustomStampList.RemoveAt(index);
  398. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  399. stamps.RemoveAt(index);
  400. Settings.Default.Save();
  401. }
  402. public void DeleteAll()
  403. {
  404. foreach (Stamp item in CustomStampList)
  405. {
  406. App.CachePath.AddToDeleteFiles(item.SourcePath);
  407. }
  408. CustomStampList.Clear();
  409. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  410. stamps.Clear();
  411. Settings.Default.Save();
  412. }
  413. private void ShowDialog()
  414. {
  415. switch (TabControlSelectedIndex)
  416. {
  417. case 1:
  418. ShowDynamicPropertyDialog();
  419. break;
  420. case 2:
  421. ShowCustomCreateDialog(null);
  422. break;
  423. default:
  424. break;
  425. }
  426. }
  427. private void ShowDynamicPropertyDialog()
  428. {
  429. bool result = true;
  430. dialogs.ShowDialog(DialogNames.DynamicPropertyDialog, null, e =>
  431. {
  432. if (e.Result != ButtonResult.OK)
  433. {
  434. result = false;
  435. }
  436. DynamicPropertyDialogViewModel DynamicVM = e.Parameters.GetValue<DynamicPropertyDialogViewModel>(ParameterNames.DataModel);
  437. if (DynamicVM != null)
  438. {
  439. Author = DynamicVM.Author;
  440. IsSetAuthor = DynamicVM.IsChecked;
  441. if (Settings.Default.AppProperties.culture == "en-US")
  442. {
  443. dateType = DynamicVM.SelectedIndex == 0 ? "F" : DynamicVM.DateFormatList[DynamicVM.SelectedIndex] + " HH:mm:ss";
  444. }
  445. else
  446. {
  447. dateType = DynamicVM.SelectedIndex == 0 ? "r" : DynamicVM.DateFormatList[DynamicVM.SelectedIndex] + " HH:mm:ss";
  448. }
  449. UpDataDynamicStampList();
  450. }
  451. });
  452. if (!result)
  453. {
  454. return;
  455. }
  456. }
  457. private void ShowCustomCreateDialog(Stamp stamp)
  458. {
  459. bool result = true;
  460. DialogParameters value = new DialogParameters();
  461. value.Add(ParameterNames.DataModel, stamp);
  462. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  463. {
  464. if (e.Result != ButtonResult.OK)
  465. {
  466. result = false;
  467. }
  468. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  469. if (CustomVM != null)
  470. {
  471. CreateCustomStamp(CustomVM);
  472. }
  473. });
  474. if (!result)
  475. {
  476. return;
  477. }
  478. }
  479. public void EditorCustomStamp(Stamp stamp)
  480. {
  481. bool result = true;
  482. DialogParameters value = new DialogParameters();
  483. value.Add(ParameterNames.DataModel, stamp);
  484. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  485. {
  486. if (e.Result != ButtonResult.OK)
  487. {
  488. result = false;
  489. }
  490. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  491. if (CustomVM != null)
  492. {
  493. UpDataCustomStamp(CustomVM, stamp);
  494. }
  495. });
  496. if (!result)
  497. {
  498. return;
  499. }
  500. }
  501. private void UpDataCustomStamp(CustomCreateDialogViewModel viewModel, Stamp oldstamp)
  502. {
  503. Stamp stamp = new Stamp();
  504. stamp.Author = "";
  505. stamp.Opacity = 1;
  506. stamp.SourcePath = viewModel.SaveToPath;
  507. stamp.StampText = viewModel.StampText;
  508. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  509. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  510. stamp.StampTextDate = viewModel.StampTextDate;
  511. stamp.Type = viewModel.Type;
  512. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  513. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  514. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  515. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  516. int index = CustomStampList.IndexOf(oldstamp);
  517. CustomStampList[index] = stamp;
  518. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  519. if (stamps == null)
  520. {
  521. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  522. }
  523. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  524. Stamp customStamp = new Stamp();
  525. annote.Author = stamp.Author;
  526. annote.StampText = stamp.StampText;
  527. annote.StampTextDate = stamp.StampTextDate;
  528. annote.ImageWidth = stamp.MaxWidth;
  529. annote.ImageHeight = stamp.MaxHeight;
  530. annote.SourcePath = stamp.SourcePath;
  531. annote.Type = stamp.Type;
  532. annote.TextSharp = stamp.TextSharp;
  533. annote.TextColor = stamp.TextColor;
  534. annote.IsCheckedDate = stamp.IsCheckedDate;
  535. annote.IsCheckedTime = stamp.IsCheckedTime;
  536. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  537. stamps[index] = annote;
  538. Settings.Default.Save();
  539. }
  540. /// <summary>
  541. /// 创建自定义图章,并且保存到APP缓存
  542. /// </summary>
  543. private void CreateCustomStamp(CustomCreateDialogViewModel viewModel)
  544. {
  545. Stamp stamp = new Stamp();
  546. stamp.Author = "";
  547. stamp.Opacity = 1;
  548. if (viewModel.IsRemoveBackground)
  549. {
  550. if (!string.IsNullOrEmpty(viewModel.SaveToPath))
  551. {
  552. App.CachePath.AddToDeleteFiles(viewModel.SaveToPath);
  553. }
  554. stamp.SourcePath = viewModel.RemoveBackgroundSaveToPath;
  555. }
  556. else
  557. {
  558. stamp.SourcePath = viewModel.SaveToPath;
  559. }
  560. stamp.StampText = viewModel.StampText;
  561. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  562. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  563. stamp.StampTextDate = viewModel.StampTextDate;
  564. stamp.Type = viewModel.Type;
  565. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  566. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  567. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  568. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  569. CustomStampList.Add(stamp);
  570. //缓存数据
  571. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  572. if (stamps == null)
  573. {
  574. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  575. }
  576. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  577. annote.Author = stamp.Author;
  578. annote.StampText = stamp.StampText;
  579. annote.StampTextDate = stamp.StampTextDate;
  580. annote.ImageWidth = stamp.MaxWidth;
  581. annote.ImageHeight = stamp.MaxHeight;
  582. annote.SourcePath = stamp.SourcePath;
  583. annote.Type = stamp.Type;
  584. annote.TextSharp = stamp.TextSharp;
  585. annote.TextColor = stamp.TextColor;
  586. annote.IsCheckedDate = stamp.IsCheckedDate;
  587. annote.IsCheckedTime = stamp.IsCheckedTime;
  588. stamps.Add(annote);
  589. Settings.Default.Save();
  590. SetStamp(stamp);
  591. CusListboxIndex = CustomStampList.Count - 1;
  592. }
  593. }
  594. }