AnnotateModel.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. using ComPDFKitViewer.AnnotEvent;
  2. using PDF_Master.Helper;
  3. using PDF_Master.Properties;
  4. using PDFSettings;
  5. using Prism.Mvvm;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Media;
  13. namespace PDF_Master.Model.SettingsDialog
  14. {
  15. public class AnnotateModel:BindableBase
  16. {
  17. private Color highLightColor;
  18. public Color HighLightColor
  19. {
  20. get { return highLightColor; }
  21. set
  22. {
  23. SetProperty(ref highLightColor, value);
  24. }
  25. }
  26. private Color underLineColor;
  27. public Color UnderLineColor
  28. {
  29. get { return underLineColor; }
  30. set
  31. {
  32. SetProperty(ref underLineColor, value);
  33. }
  34. }
  35. private Color strikethroughColor;
  36. public Color StrikethroughColor
  37. {
  38. get { return strikethroughColor; }
  39. set
  40. {
  41. SetProperty(ref strikethroughColor, value);
  42. }
  43. }
  44. private Color freeHandColor;
  45. public Color FreeHandColor
  46. {
  47. get { return freeHandColor; }
  48. set
  49. {
  50. SetProperty(ref freeHandColor, value);
  51. }
  52. }
  53. private Color textAnnoteColor;
  54. public Color TextAnnoteColor
  55. {
  56. get { return textAnnoteColor; }
  57. set
  58. {
  59. SetProperty(ref textAnnoteColor, value);
  60. }
  61. }
  62. private Color noteAnnoteColor;
  63. public Color NoteAnnoteColor
  64. {
  65. get { return noteAnnoteColor; }
  66. set
  67. {
  68. SetProperty(ref noteAnnoteColor, value);
  69. }
  70. }
  71. private Color rectangleBorderColor;
  72. public Color RectangleBorderColor
  73. {
  74. get { return rectangleBorderColor; }
  75. set
  76. {
  77. SetProperty(ref rectangleBorderColor, value);
  78. }
  79. }
  80. private Color rectangleFillColor;
  81. public Color RectangleFillColor
  82. {
  83. get { return rectangleFillColor; }
  84. set
  85. {
  86. SetProperty(ref rectangleFillColor, value);
  87. }
  88. }
  89. private Color circleBorderColor;
  90. public Color CircleBorderColor
  91. {
  92. get { return circleBorderColor; }
  93. set
  94. {
  95. SetProperty(ref circleBorderColor, value);
  96. }
  97. }
  98. private Color circleFillColor;
  99. public Color CircleFillColor
  100. {
  101. get { return circleFillColor; }
  102. set
  103. {
  104. SetProperty(ref circleFillColor, value);
  105. }
  106. }
  107. private Color lineColor;
  108. public Color LineColor
  109. {
  110. get { return lineColor; }
  111. set
  112. {
  113. SetProperty(ref lineColor, value);
  114. }
  115. }
  116. private Color arrowColor;
  117. public Color ArrowColor
  118. {
  119. get { return arrowColor; }
  120. set
  121. {
  122. SetProperty(ref arrowColor, value);
  123. }
  124. }
  125. private TextAlignment textAlign;
  126. public TextAlignment TextAlign
  127. {
  128. get { return textAlign; }
  129. set
  130. {
  131. SetProperty(ref textAlign, value);
  132. }
  133. }
  134. private string textFontFamaily;
  135. public string TextFontFamaily
  136. {
  137. get { return textFontFamaily; }
  138. set
  139. {
  140. SetProperty(ref textFontFamaily, value);
  141. }
  142. }
  143. private string anchoredFamaily;
  144. public string AnchoredFamaily
  145. {
  146. get { return anchoredFamaily; }
  147. set
  148. {
  149. SetProperty(ref anchoredFamaily, value);
  150. }
  151. }
  152. public AnnotateModel()
  153. {
  154. InitFromSettings();
  155. }
  156. private void InitFromSettings()
  157. {
  158. var annote = Settings.Default.AppProperties.Annotate;
  159. this.HighLightColor = annote.HighLightColor;
  160. this.UnderLineColor = annote.UnderLineColor;
  161. this.StrikethroughColor = annote.StrikethroughColor;
  162. this.FreeHandColor = annote.FreeHandColor;
  163. this.TextAnnoteColor = annote.TextAnnoteColor;
  164. this.NoteAnnoteColor = annote.NoteAnnoteColor;
  165. this.RectangleBorderColor = annote.RectangleBorderColor;
  166. this.RectangleFillColor = annote.RectangleFillColor;
  167. this.CircleBorderColor = annote.CircleBorderColor;
  168. this.CircleFillColor = annote.CircleFillColor;
  169. this.LineColor = annote.LineColor;
  170. this.ArrowColor = annote.ArrowColor;
  171. this.TextFontFamaily = annote.TextFontFamaily;
  172. this.AnchoredFamaily = annote.AnchoredFamaily;
  173. this.TextAlign = annote.TextAlign;
  174. }
  175. private void SaveDefaultAnnotSettings()
  176. {
  177. var highLightAnnot = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  178. highLightAnnot.ForgoundColor = this.HighLightColor;
  179. SetDefautAnnotProperties(highLightAnnot);
  180. var UnderLineAnnot = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  181. UnderLineAnnot.ForgoundColor = this.UnderLineColor;
  182. SetDefautAnnotProperties(UnderLineAnnot);
  183. var StrikethroughColor = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  184. StrikethroughColor.ForgoundColor = this.strikethroughColor;
  185. SetDefautAnnotProperties(StrikethroughColor);
  186. var FreeHandAnnot = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  187. FreeHandAnnot.ForgoundColor = this.FreeHandColor;
  188. SetDefautAnnotProperties(FreeHandAnnot);
  189. var TextAnnoteAnnot = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  190. TextAnnoteAnnot.ForgoundColor = this.textAnnoteColor;
  191. SetDefautAnnotProperties(TextAnnoteAnnot);
  192. var NoteAnnoteAnnot = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  193. NoteAnnoteAnnot.ForgoundColor = this.NoteAnnoteColor;
  194. SetDefautAnnotProperties(NoteAnnoteAnnot);
  195. var RectangleAnnot = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  196. RectangleAnnot.BorderColor = this.RectangleBorderColor;
  197. RectangleAnnot.BackgroundColor = this.RectangleFillColor;
  198. SetDefautAnnotProperties(RectangleAnnot);
  199. var AnnotLineAnnot = GetAnnotDefault(AnnotArgsType.AnnotLine);
  200. AnnotLineAnnot.BorderColor = this.LineColor;
  201. SetDefautAnnotProperties(AnnotLineAnnot);
  202. var ArrowAnnot = GetAnnotDefault(AnnotArgsType.AnnotLine,"Arrow");
  203. AnnotLineAnnot.BorderColor = this.LineColor;
  204. SetDefautAnnotProperties(AnnotLineAnnot);
  205. Settings.Default.Save();
  206. }
  207. private void SetDefautAnnotProperties(DefaultAnnotProperty annotProperty)
  208. {
  209. if (Settings.Default.DefautAnnotProperties == null)
  210. {
  211. Settings.Default.DefautAnnotProperties = new DefaultAnnotProperties();
  212. }
  213. Settings.Default.DefautAnnotProperties.SetAnnotProperty(annotProperty);
  214. }
  215. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType,string saveKey="")
  216. {
  217. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType,saveKey);
  218. if (Annot == null)
  219. {
  220. Annot = new DefaultAnnotProperty();
  221. }
  222. return Annot;
  223. }
  224. public void Save()
  225. {
  226. AnnotatePropertyClass annote = new AnnotatePropertyClass();
  227. annote.HighLightColor = this.HighLightColor;
  228. annote.UnderLineColor = this.UnderLineColor;
  229. annote.StrikethroughColor = this.StrikethroughColor;
  230. annote.FreeHandColor = this.FreeHandColor;
  231. annote.TextAnnoteColor = this.TextAnnoteColor;
  232. annote.NoteAnnoteColor = this.NoteAnnoteColor;
  233. annote.RectangleBorderColor = this.RectangleBorderColor;
  234. annote.RectangleFillColor = this.RectangleFillColor;
  235. annote.CircleBorderColor = this.CircleBorderColor;
  236. annote.CircleFillColor = this.CircleFillColor;
  237. annote.LineColor = this.LineColor;
  238. annote.ArrowColor = this.ArrowColor;
  239. annote.TextFontFamaily = this.TextFontFamaily;
  240. annote.AnchoredFamaily = this.AnchoredFamaily;
  241. annote.TextAlign = this.TextAlign;
  242. Settings.Default.AppProperties.Annotate = annote;
  243. SaveDefaultAnnotSettings();
  244. }
  245. /// <summary>
  246. /// 重置
  247. /// </summary>
  248. public void Reset()
  249. {
  250. var defualtannote = new AnnotatePropertyClass();
  251. this.HighLightColor = defualtannote.HighLightColor;
  252. this.UnderLineColor = defualtannote.UnderLineColor;
  253. this.StrikethroughColor = defualtannote.StrikethroughColor;
  254. this.FreeHandColor = defualtannote.FreeHandColor;
  255. this.TextAnnoteColor = defualtannote.TextAnnoteColor;
  256. this.NoteAnnoteColor = defualtannote.NoteAnnoteColor;
  257. this.RectangleBorderColor = defualtannote.RectangleBorderColor;
  258. this.RectangleFillColor = defualtannote.RectangleFillColor;
  259. this.CircleBorderColor = defualtannote.CircleBorderColor;
  260. this.CircleFillColor = defualtannote.CircleFillColor;
  261. this.LineColor = defualtannote.LineColor;
  262. this.ArrowColor = defualtannote.ArrowColor;
  263. this.TextFontFamaily = defualtannote.TextFontFamaily;
  264. this.AnchoredFamaily = defualtannote.AnchoredFamaily;
  265. this.TextAlign = defualtannote.TextAlign;
  266. }
  267. }
  268. }