MarkSettingDialogViewModel.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using PDF_Master.Model;
  4. using Prism.Commands;
  5. using Prism.Mvvm;
  6. using Prism.Services.Dialogs;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Media;
  14. namespace PDF_Master.ViewModels.Dialog.Redaction
  15. {
  16. public class MarkSettingDialogViewModel : BindableBase, IDialogAware
  17. {
  18. public string Title => "";
  19. public event Action<IDialogResult> RequestClose;
  20. private RedactionAnnotArgs annotArgs;
  21. public DelegateCommand OkCommand { get; set; }
  22. public DelegateCommand CancelCommand { get; set; }
  23. public DelegateCommand<string> AlignCommand { get; set; }
  24. private Color lineColor;
  25. public Color LineColor
  26. {
  27. get { return lineColor; }
  28. set
  29. {
  30. SetProperty(ref lineColor, value);
  31. }
  32. }
  33. private Color bgColor;
  34. public Color BgColor
  35. {
  36. get { return bgColor; }
  37. set
  38. {
  39. SetProperty(ref bgColor, value);
  40. }
  41. }
  42. private Color fontColor;
  43. public Color FontColor
  44. {
  45. get { return fontColor; }
  46. set
  47. {
  48. SetProperty(ref fontColor, value);
  49. }
  50. }
  51. private bool isUserText;
  52. public bool IsUseText
  53. {
  54. get { return isUserText; }
  55. set
  56. {
  57. SetProperty(ref isUserText, value);
  58. }
  59. }
  60. private bool leftChecked = true;
  61. public bool LeftChecked
  62. {
  63. get { return leftChecked; }
  64. set
  65. {
  66. SetProperty(ref leftChecked, value);
  67. }
  68. }
  69. private bool centerChecked;
  70. public bool CenterChecked
  71. {
  72. get { return centerChecked; }
  73. set
  74. {
  75. SetProperty(ref centerChecked, value);
  76. }
  77. }
  78. private bool rightChecked;
  79. public bool RightChecked
  80. {
  81. get { return rightChecked; }
  82. set
  83. {
  84. SetProperty(ref rightChecked, value);
  85. }
  86. }
  87. private bool strechChecked;
  88. public bool StrechChecked
  89. {
  90. get { return strechChecked; }
  91. set
  92. {
  93. SetProperty(ref strechChecked, value);
  94. }
  95. }
  96. private string overText;
  97. public string OvertText
  98. {
  99. get { return overText; }
  100. set
  101. {
  102. SetProperty(ref overText, value);
  103. }
  104. }
  105. private int fontFamilySelectedIndex;
  106. public int FontFamilySelectedIndex
  107. {
  108. get { return fontFamilySelectedIndex; }
  109. set
  110. {
  111. SetProperty(ref fontFamilySelectedIndex, value);
  112. if(value>0)
  113. {
  114. switch (value)
  115. {
  116. case 0:
  117. fontFamily = "Courier";
  118. break;
  119. case 1:
  120. fontFamily = "Helvetica";
  121. break;
  122. case 2:
  123. fontFamily = "Times Roman";
  124. break;
  125. default:
  126. break;
  127. }
  128. }
  129. }
  130. }
  131. private string fontFamily = "";
  132. private int fontWeightSelectedIndex;
  133. public int FontWeightSelectedIndex
  134. {
  135. get { return fontWeightSelectedIndex; }
  136. set
  137. {
  138. SetProperty(ref fontWeightSelectedIndex, value);
  139. if (value > 0)
  140. {
  141. switch (value)
  142. {
  143. case 0:
  144. fontWeight = FontWeights.Regular;
  145. break;
  146. case 1:
  147. fontWeight = FontWeights.Bold;
  148. break;
  149. case 2:
  150. fontWeight = FontWeights.SemiBold;
  151. break;
  152. case 3:
  153. fontWeight = FontWeights.UltraBold;
  154. break;
  155. default:
  156. break;
  157. }
  158. }
  159. }
  160. }
  161. private FontWeight fontWeight = FontWeights.Regular;
  162. private int fontSize = 12;
  163. private int fontSizeSelectedIndex;
  164. public int FontSizeSelectedIndex
  165. {
  166. get { return fontSizeSelectedIndex; }
  167. set
  168. {
  169. SetProperty(ref fontSizeSelectedIndex, value);
  170. }
  171. }
  172. public List<string> FontFamilys { get; set; }
  173. public List<string> FontWeight { get; set; }
  174. public List<string> FontSizes { get; set; }
  175. public TextAlignment textAlignment { get; set; } = TextAlignment.Left;
  176. public MarkSettingDialogViewModel()
  177. {
  178. OkCommand = new DelegateCommand(ok);
  179. CancelCommand = new DelegateCommand(cancel);
  180. AlignCommand = new DelegateCommand<string>(align);
  181. InitFontFamily();
  182. InitFontWeight();
  183. InitFontSize();
  184. }
  185. private void InitFontFamily()
  186. {
  187. FontFamilys = new List<string>();
  188. FontFamilys.Add("Courier New");
  189. FontFamilys.Add("Arial");
  190. FontFamilys.Add("Times New Roman");
  191. }
  192. private void InitFontWeight()
  193. {
  194. FontWeight = new List<string>();
  195. FontWeight.Add("Regular");
  196. FontWeight.Add("Bold");
  197. FontWeight.Add("Italic");
  198. FontWeight.Add("Bold Italic");
  199. }
  200. private void InitFontSize()
  201. {
  202. FontSizes = new List<string>();
  203. FontSizes.Add("Auto");
  204. }
  205. private void cancel()
  206. {
  207. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  208. }
  209. private void ok()
  210. {
  211. AnnotAttribEvent eventargs = AnnotAttribEvent.GetAnnotAttribEvent(annotArgs, annotArgs.GetAnnotAttrib());
  212. eventargs.UpdateAttrib(AnnotAttrib.FillColor,BgColor);
  213. eventargs.UpdateAttrib(AnnotAttrib.NoteText, OvertText);
  214. eventargs.UpdateAttrib(AnnotAttrib.FontColor,FontColor);
  215. eventargs.UpdateAttrib(AnnotAttrib.Color, LineColor);
  216. eventargs.UpdateAttrib(AnnotAttrib.FontSize,fontSize);
  217. eventargs.UpdateAttrib(AnnotAttrib.TextAlign, textAlignment);
  218. eventargs.UpdateAttrib(AnnotAttrib.FontWeight, fontWeight);
  219. if (IsUseText)
  220. {
  221. eventargs.UpdateAttrib(AnnotAttrib.NoteText, string.Empty);
  222. }
  223. eventargs.UpdateAnnot();
  224. RequestClose.Invoke(new DialogResult(ButtonResult.OK));
  225. }
  226. private void align(string tag)
  227. {
  228. switch (tag)
  229. {
  230. case "Left":
  231. textAlignment = TextAlignment.Left;
  232. break;
  233. case "Center":
  234. textAlignment = TextAlignment.Center;
  235. break;
  236. case "Right":
  237. textAlignment = TextAlignment.Right;
  238. break;
  239. case "Strech":
  240. textAlignment = TextAlignment.Justify;
  241. break;
  242. default:
  243. break;
  244. }
  245. }
  246. public bool CanCloseDialog()
  247. {
  248. return true;
  249. }
  250. public void OnDialogClosed()
  251. {
  252. }
  253. public void OnDialogOpened(IDialogParameters parameters)
  254. {
  255. annotArgs = parameters.GetValue<RedactionAnnotArgs>(ParameterNames.DataModel);
  256. BgColor = annotArgs.BgColor;
  257. LineColor = annotArgs.LineColor;
  258. FontColor = annotArgs.FontColor;
  259. OvertText = annotArgs.Content;
  260. switch (annotArgs.FontFamily.ToString())
  261. {
  262. case "Helvetica":
  263. FontFamilySelectedIndex = 1;
  264. break;
  265. case "Times Roman":
  266. FontFamilySelectedIndex = 2;
  267. break;
  268. default:
  269. case "Courier":
  270. FontFamilySelectedIndex = 0;
  271. break;
  272. }
  273. switch (annotArgs.Align)
  274. {
  275. case TextAlignment.Left:
  276. LeftChecked = true;
  277. break;
  278. case TextAlignment.Right:
  279. RightChecked = true;
  280. break;
  281. case TextAlignment.Center:
  282. CenterChecked = true;
  283. break;
  284. case TextAlignment.Justify:
  285. StrechChecked = true;
  286. break;
  287. default:
  288. break;
  289. }
  290. }
  291. }
  292. }