MarkSettingDialogViewModel.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. }
  113. }
  114. private int fontWeightSelectedIndex;
  115. public int FontWeightSelectedIndex
  116. {
  117. get { return fontWeightSelectedIndex; }
  118. set
  119. {
  120. SetProperty(ref fontWeightSelectedIndex, value);
  121. if (value > 0)
  122. {
  123. switch (value)
  124. {
  125. case 0:
  126. fontWeight = FontWeights.Regular;
  127. break;
  128. case 1:
  129. fontWeight = FontWeights.Bold;
  130. break;
  131. case 2:
  132. fontWeight = FontWeights.SemiBold;
  133. break;
  134. case 3:
  135. fontWeight = FontWeights.UltraBold;
  136. break;
  137. default:
  138. break;
  139. }
  140. }
  141. }
  142. }
  143. private FontWeight fontWeight = FontWeights.Regular;
  144. private int fontSize = 12;
  145. private int fontSizeSelectedIndex;
  146. public int FontSizeSelectedIndex
  147. {
  148. get { return fontSizeSelectedIndex; }
  149. set
  150. {
  151. SetProperty(ref fontSizeSelectedIndex, value);
  152. }
  153. }
  154. public List<string> FontFamilys { get; set; }
  155. public List<string> FontWeight { get; set; }
  156. public List<string> FontSizes { get; set; }
  157. public TextAlignment textAlignment { get; set; } = TextAlignment.Left;
  158. public MarkSettingDialogViewModel()
  159. {
  160. OkCommand = new DelegateCommand(ok);
  161. CancelCommand = new DelegateCommand(cancel);
  162. AlignCommand = new DelegateCommand<string>(align);
  163. InitFontFamily();
  164. InitFontWeight();
  165. InitFontSize();
  166. }
  167. private void InitFontFamily()
  168. {
  169. FontFamilys = new List<string>();
  170. FontFamilys.Add("Courier New");
  171. FontFamilys.Add("Arial");
  172. FontFamilys.Add("Times New Roman");
  173. }
  174. private void InitFontWeight()
  175. {
  176. FontWeight = new List<string>();
  177. FontWeight.Add("Regular");
  178. FontWeight.Add("Bold");
  179. FontWeight.Add("Italic");
  180. FontWeight.Add("Bold Italic");
  181. }
  182. private void InitFontSize()
  183. {
  184. FontSizes = new List<string>();
  185. FontSizes.Add("Auto");
  186. }
  187. private void cancel()
  188. {
  189. RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
  190. }
  191. private void ok()
  192. {
  193. AnnotAttribEvent eventargs = AnnotAttribEvent.GetAnnotAttribEvent(annotArgs, annotArgs.GetAnnotAttrib());
  194. eventargs.UpdateAttrib(AnnotAttrib.FillColor,BgColor);
  195. eventargs.UpdateAttrib(AnnotAttrib.NoteText, OvertText);
  196. eventargs.UpdateAttrib(AnnotAttrib.FontColor,FontColor);
  197. eventargs.UpdateAttrib(AnnotAttrib.Color, LineColor);
  198. eventargs.UpdateAttrib(AnnotAttrib.FontSize,fontSize);
  199. eventargs.UpdateAttrib(AnnotAttrib.TextAlign, textAlignment);
  200. eventargs.UpdateAttrib(AnnotAttrib.IsBold, fontWeight==FontWeights.Bold);
  201. if (IsUseText)
  202. {
  203. eventargs.UpdateAttrib(AnnotAttrib.NoteText, string.Empty);
  204. }
  205. eventargs.UpdateAnnot();
  206. RequestClose.Invoke(new DialogResult(ButtonResult.OK));
  207. }
  208. private void align(string tag)
  209. {
  210. switch (tag)
  211. {
  212. case "Left":
  213. textAlignment = TextAlignment.Left;
  214. break;
  215. case "Center":
  216. textAlignment = TextAlignment.Center;
  217. break;
  218. case "Right":
  219. textAlignment = TextAlignment.Right;
  220. break;
  221. case "Strech":
  222. textAlignment = TextAlignment.Justify;
  223. break;
  224. default:
  225. break;
  226. }
  227. }
  228. public bool CanCloseDialog()
  229. {
  230. return true;
  231. }
  232. public void OnDialogClosed()
  233. {
  234. }
  235. public void OnDialogOpened(IDialogParameters parameters)
  236. {
  237. annotArgs = parameters.GetValue<RedactionAnnotArgs>(ParameterNames.DataModel);
  238. BgColor = annotArgs.BgColor;
  239. LineColor = annotArgs.LineColor;
  240. FontColor = annotArgs.FontColor;
  241. OvertText = annotArgs.Content;
  242. switch (annotArgs.FontName)
  243. {
  244. case "Helvetica":
  245. FontFamilySelectedIndex = 1;
  246. break;
  247. case "Times Roman":
  248. FontFamilySelectedIndex = 2;
  249. break;
  250. default:
  251. case "Courier":
  252. FontFamilySelectedIndex = 0;
  253. break;
  254. }
  255. switch (annotArgs.Align)
  256. {
  257. case TextAlignment.Left:
  258. LeftChecked = true;
  259. break;
  260. case TextAlignment.Right:
  261. RightChecked = true;
  262. break;
  263. case TextAlignment.Center:
  264. CenterChecked = true;
  265. break;
  266. case TextAlignment.Justify:
  267. StrechChecked = true;
  268. break;
  269. default:
  270. break;
  271. }
  272. }
  273. }
  274. }