StampAnnotPropertyViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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.ClearSelectAnnots();
  274. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  275. PDFViewer.SetToolParam(Args);
  276. }
  277. /// <summary>
  278. /// 更新动态图章对象相关属性
  279. /// </summary>
  280. public void UpDataDynamicStampList()
  281. {
  282. string time = System.DateTime.Now.ToString(dateType);
  283. for (int i = 0; i < DynamicStampText.Count; i++)
  284. {
  285. string date = "";
  286. //区分机密(CONFIDENTIAL)和其他动态图章的区别
  287. if (i < DynamicStampText.Count - 1)
  288. {
  289. date = time;
  290. }
  291. Stamp standardStamp = new Stamp();
  292. if (IsSetAuthor && !string.IsNullOrEmpty(Author))
  293. {
  294. standardStamp.Author = Author;
  295. if (i < DynamicStampText.Count - 1)
  296. {
  297. standardStamp.StampTextDate = "By " + Author + " at " + date;
  298. }
  299. else
  300. {
  301. standardStamp.StampTextDate = Author;
  302. }
  303. }
  304. else
  305. {
  306. standardStamp.StampTextDate = date;
  307. standardStamp.Author = "";
  308. }
  309. var bytes = CPDFStampAnnotation.GetTempTextStampImage(DynamicStampText[i], standardStamp.StampTextDate,
  310. C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT, DynamicColor[i], out int stampWidth, out int stampHeight, out int width, out int height);
  311. PixelFormat fmt = PixelFormats.Bgra32;
  312. BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, bytes, (width * fmt.BitsPerPixel + 7) / 8);
  313. var flags = BindingFlags.NonPublic | BindingFlags.Static;
  314. var dpiProperty = typeof(SystemParameters).GetProperty("Dpi", flags);
  315. int Dpi = (int)dpiProperty.GetValue(null, null);
  316. standardStamp.Opacity = 1;
  317. standardStamp.SourcePath = "";
  318. standardStamp.StampText = DynamicStampText[i];
  319. standardStamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(stampWidth / 72D * DpiHelpers.Dpi);
  320. standardStamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(stampHeight / 72D * DpiHelpers.Dpi);
  321. standardStamp.Type = StampType.TEXT_STAMP;
  322. standardStamp.ImageSource = bps;
  323. standardStamp.IsCheckedDate = true;
  324. standardStamp.IsCheckedTime = true;
  325. switch (DynamicColor[i])
  326. {
  327. case C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE:
  328. break;
  329. case C_TEXTSTAMP_COLOR.TEXTSTAMP_RED:
  330. standardStamp.TextColor = TextStampColor.TEXTSTAMP_RED;
  331. break;
  332. case C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN:
  333. standardStamp.TextColor = TextStampColor.TEXTSTAMP_GREEN;
  334. break;
  335. case C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE:
  336. break;
  337. default:
  338. break;
  339. }
  340. if (DynamicStampList.Count== DynamicStampText.Count)
  341. {
  342. DynamicStampList[i] = standardStamp;
  343. }
  344. else
  345. {
  346. DynamicStampList.Add(standardStamp);
  347. }
  348. }
  349. }
  350. /// <summary>
  351. /// 导出图章
  352. /// </summary>
  353. public void SaveToPath(string FileType, Stamp Item)
  354. {
  355. SaveFileDialog saveFileDialog = new SaveFileDialog();
  356. saveFileDialog.Title = "保存" + FileType + "文件";
  357. saveFileDialog.Filter = "(*)|*." + FileType;
  358. if (saveFileDialog.ShowDialog() == false)
  359. {
  360. return;
  361. }
  362. BitmapEncoder encoder;
  363. if (FileType.ToUpper() == "JPG")
  364. {
  365. encoder = new JpegBitmapEncoder();
  366. }
  367. else
  368. {
  369. encoder = new PngBitmapEncoder();
  370. }
  371. encoder.Frames.Add(BitmapFrame.Create(new Uri(Item.SourcePath)));
  372. string path = saveFileDialog.FileName;
  373. switch (FileType.ToUpper())
  374. {
  375. case "PDF":
  376. CPDFDocument newDoc = CPDFDocument.CreateDocument();
  377. BitmapFrame frame = BitmapFrame.Create(new Uri(Item.SourcePath));
  378. byte[] imageData = new byte[frame.PixelWidth * frame.PixelHeight * 4];
  379. frame.CopyPixels(imageData, frame.PixelWidth * 4, 0);
  380. newDoc.InsertPage(0, frame.PixelWidth, frame.PixelHeight, imageData, CPDFDocumentImageMode.CPDFDocumentImageModeScaleToFill);
  381. newDoc.WriteToFilePath(path);
  382. break;
  383. case "PNG":
  384. using (FileStream stream = new FileStream(path, FileMode.Create))
  385. {
  386. encoder.Save(stream);
  387. }
  388. break;
  389. default:
  390. break;
  391. }
  392. System.Diagnostics.Process.Start("explorer", "/select,\"" + path + "\"");
  393. }
  394. public void DeleteStamp(Stamp stamp)
  395. {
  396. int index = CustomStampList.IndexOf(stamp);
  397. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  398. CustomStampList.RemoveAt(index);
  399. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  400. stamps.RemoveAt(index);
  401. Settings.Default.Save();
  402. }
  403. public void DeleteAll()
  404. {
  405. foreach (Stamp item in CustomStampList)
  406. {
  407. App.CachePath.AddToDeleteFiles(item.SourcePath);
  408. }
  409. CustomStampList.Clear();
  410. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  411. stamps.Clear();
  412. Settings.Default.Save();
  413. }
  414. private void ShowDialog()
  415. {
  416. switch (TabControlSelectedIndex)
  417. {
  418. case 1:
  419. ShowDynamicPropertyDialog();
  420. break;
  421. case 2:
  422. ShowCustomCreateDialog(null);
  423. break;
  424. default:
  425. break;
  426. }
  427. }
  428. private void ShowDynamicPropertyDialog()
  429. {
  430. bool result = true;
  431. dialogs.ShowDialog(DialogNames.DynamicPropertyDialog, null, e =>
  432. {
  433. if (e.Result != ButtonResult.OK)
  434. {
  435. result = false;
  436. }
  437. DynamicPropertyDialogViewModel DynamicVM = e.Parameters.GetValue<DynamicPropertyDialogViewModel>(ParameterNames.DataModel);
  438. if (DynamicVM != null)
  439. {
  440. Author = DynamicVM.Author;
  441. IsSetAuthor = DynamicVM.IsChecked;
  442. if (Settings.Default.AppProperties.culture == "en-US")
  443. {
  444. dateType = DynamicVM.SelectedIndex == 0 ? "F" : DynamicVM.DateFormatList[DynamicVM.SelectedIndex] + " HH:mm:ss";
  445. }
  446. else
  447. {
  448. dateType = DynamicVM.SelectedIndex == 0 ? "r" : DynamicVM.DateFormatList[DynamicVM.SelectedIndex] + " HH:mm:ss";
  449. }
  450. UpDataDynamicStampList();
  451. }
  452. });
  453. if (!result)
  454. {
  455. return;
  456. }
  457. }
  458. private void ShowCustomCreateDialog(Stamp stamp)
  459. {
  460. bool result = true;
  461. DialogParameters value = new DialogParameters();
  462. value.Add(ParameterNames.DataModel, stamp);
  463. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  464. {
  465. if (e.Result != ButtonResult.OK)
  466. {
  467. result = false;
  468. }
  469. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  470. if (CustomVM != null)
  471. {
  472. CreateCustomStamp(CustomVM);
  473. }
  474. });
  475. if (!result)
  476. {
  477. return;
  478. }
  479. }
  480. public void EditorCustomStamp(Stamp stamp)
  481. {
  482. bool result = true;
  483. DialogParameters value = new DialogParameters();
  484. value.Add(ParameterNames.DataModel, stamp);
  485. dialogs.ShowDialog(DialogNames.CustomCreateDialog, value, e =>
  486. {
  487. if (e.Result != ButtonResult.OK)
  488. {
  489. result = false;
  490. }
  491. CustomCreateDialogViewModel CustomVM = e.Parameters.GetValue<CustomCreateDialogViewModel>(ParameterNames.DataModel);
  492. if (CustomVM != null)
  493. {
  494. UpDataCustomStamp(CustomVM, stamp);
  495. }
  496. });
  497. if (!result)
  498. {
  499. return;
  500. }
  501. }
  502. private void UpDataCustomStamp(CustomCreateDialogViewModel viewModel, Stamp oldstamp)
  503. {
  504. Stamp stamp = new Stamp();
  505. stamp.Author = "";
  506. stamp.Opacity = 1;
  507. stamp.SourcePath = viewModel.SaveToPath;
  508. stamp.StampText = viewModel.StampText;
  509. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  510. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  511. stamp.StampTextDate = viewModel.StampTextDate;
  512. stamp.Type = viewModel.Type;
  513. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  514. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  515. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  516. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  517. int index = CustomStampList.IndexOf(oldstamp);
  518. CustomStampList[index] = stamp;
  519. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  520. if (stamps == null)
  521. {
  522. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  523. }
  524. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  525. Stamp customStamp = new Stamp();
  526. annote.Author = stamp.Author;
  527. annote.StampText = stamp.StampText;
  528. annote.StampTextDate = stamp.StampTextDate;
  529. annote.ImageWidth = stamp.MaxWidth;
  530. annote.ImageHeight = stamp.MaxHeight;
  531. annote.SourcePath = stamp.SourcePath;
  532. annote.Type = stamp.Type;
  533. annote.TextSharp = stamp.TextSharp;
  534. annote.TextColor = stamp.TextColor;
  535. annote.IsCheckedDate = stamp.IsCheckedDate;
  536. annote.IsCheckedTime = stamp.IsCheckedTime;
  537. App.CachePath.AddToDeleteFiles(stamp.SourcePath);
  538. stamps[index] = annote;
  539. Settings.Default.Save();
  540. }
  541. /// <summary>
  542. /// 创建自定义图章,并且保存到APP缓存
  543. /// </summary>
  544. private void CreateCustomStamp(CustomCreateDialogViewModel viewModel)
  545. {
  546. Stamp stamp = new Stamp();
  547. stamp.Author = "";
  548. stamp.Opacity = 1;
  549. if (viewModel.IsRemoveBackground)
  550. {
  551. if (!string.IsNullOrEmpty(viewModel.SaveToPath))
  552. {
  553. App.CachePath.AddToDeleteFiles(viewModel.SaveToPath);
  554. }
  555. stamp.SourcePath = viewModel.RemoveBackgroundSaveToPath;
  556. }
  557. else
  558. {
  559. stamp.SourcePath = viewModel.SaveToPath;
  560. }
  561. stamp.StampText = viewModel.StampText;
  562. stamp.MaxWidth = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampWidth / 72D * DpiHelpers.Dpi);
  563. stamp.MaxHeight = (int)DpiHelpers.GetDpiUnrelatedNum(viewModel.StampHeight / 72D * DpiHelpers.Dpi);
  564. stamp.StampTextDate = viewModel.StampTextDate;
  565. stamp.Type = viewModel.Type;
  566. stamp.TextColor = (TextStampColor)(int)viewModel.Color;
  567. stamp.TextSharp = (TextStampSharp)(int)viewModel.Shape;
  568. stamp.IsCheckedDate = viewModel.IsCheckedDate;
  569. stamp.IsCheckedTime = viewModel.IsCheckedTime;
  570. CustomStampList.Add(stamp);
  571. //缓存数据
  572. PDFSettings.CustomStampList stamps = Settings.Default.CustomStampList;
  573. if (stamps == null)
  574. {
  575. stamps = Settings.Default.CustomStampList = new PDFSettings.CustomStampList();
  576. }
  577. PDFSettings.StampAnnote annote = new PDFSettings.StampAnnote();
  578. annote.Author = stamp.Author;
  579. annote.StampText = stamp.StampText;
  580. annote.StampTextDate = stamp.StampTextDate;
  581. annote.ImageWidth = stamp.MaxWidth;
  582. annote.ImageHeight = stamp.MaxHeight;
  583. annote.SourcePath = stamp.SourcePath;
  584. annote.Type = stamp.Type;
  585. annote.TextSharp = stamp.TextSharp;
  586. annote.TextColor = stamp.TextColor;
  587. annote.IsCheckedDate = stamp.IsCheckedDate;
  588. annote.IsCheckedTime = stamp.IsCheckedTime;
  589. stamps.Add(annote);
  590. Settings.Default.Save();
  591. SetStamp(stamp);
  592. CusListboxIndex = CustomStampList.Count - 1;
  593. }
  594. }
  595. }