StampAnnotPropertyViewModel.cs 26 KB

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