AnnotateModel.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using ComPDFKitViewer.AnnotEvent;
  2. using PDF_Office.Helper;
  3. using PDF_Office.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_Office.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 TextAlignment textAlign;
  117. public TextAlignment TextAlign
  118. {
  119. get { return textAlign; }
  120. set
  121. {
  122. SetProperty(ref textAlign, value);
  123. }
  124. }
  125. private string textFontFamaily;
  126. public string TextFontFamaily
  127. {
  128. get { return textFontFamaily; }
  129. set
  130. {
  131. SetProperty(ref textFontFamaily, value);
  132. }
  133. }
  134. private string anchoredFamaily;
  135. public string AnchoredFamaily
  136. {
  137. get { return anchoredFamaily; }
  138. set
  139. {
  140. SetProperty(ref anchoredFamaily, value);
  141. }
  142. }
  143. public AnnotateModel()
  144. {
  145. InitFromSettings();
  146. }
  147. private void InitFromSettings()
  148. {
  149. var annote = Settings.Default.AppProperties.Annotate;
  150. this.HighLightColor = annote.HighLightColor;
  151. this.UnderLineColor = annote.UnderLineColor;
  152. this.StrikethroughColor = annote.StrikethroughColor;
  153. this.FreeHandColor = annote.FreeHandColor;
  154. this.TextAnnoteColor = annote.TextAnnoteColor;
  155. this.NoteAnnoteColor = annote.NoteAnnoteColor;
  156. this.RectangleBorderColor = annote.RectangleBorderColor;
  157. this.RectangleFillColor = annote.RectangleFillColor;
  158. this.CircleBorderColor = annote.CircleBorderColor;
  159. this.CircleFillColor = annote.CircleFillColor;
  160. this.LineColor = annote.LineColor;
  161. this.TextFontFamaily = annote.TextFontFamaily;
  162. this.AnchoredFamaily = annote.AnchoredFamaily;
  163. this.TextAlign = annote.TextAlign;
  164. }
  165. private void SaveDefaultAnnotSettings()
  166. {
  167. var highLightAnnot = GetAnnotDefault(AnnotArgsType.AnnotHighlight);
  168. highLightAnnot.ForgoundColor = this.HighLightColor;
  169. SetDefautAnnotProperties(highLightAnnot);
  170. var UnderLineAnnot = GetAnnotDefault(AnnotArgsType.AnnotUnderline);
  171. UnderLineAnnot.ForgoundColor = this.UnderLineColor;
  172. SetDefautAnnotProperties(UnderLineAnnot);
  173. var StrikethroughColor = GetAnnotDefault(AnnotArgsType.AnnotStrikeout);
  174. StrikethroughColor.ForgoundColor = this.strikethroughColor;
  175. SetDefautAnnotProperties(StrikethroughColor);
  176. var FreeHandAnnot = GetAnnotDefault(AnnotArgsType.AnnotFreehand);
  177. FreeHandAnnot.ForgoundColor = this.FreeHandColor;
  178. SetDefautAnnotProperties(FreeHandAnnot);
  179. var TextAnnoteAnnot = GetAnnotDefault(AnnotArgsType.AnnotFreeText);
  180. TextAnnoteAnnot.ForgoundColor = this.textAnnoteColor;
  181. SetDefautAnnotProperties(TextAnnoteAnnot);
  182. var NoteAnnoteAnnot = GetAnnotDefault(AnnotArgsType.AnnotSticky);
  183. NoteAnnoteAnnot.ForgoundColor = this.NoteAnnoteColor;
  184. SetDefautAnnotProperties(NoteAnnoteAnnot);
  185. var RectangleAnnot = GetAnnotDefault(AnnotArgsType.AnnotSquare);
  186. RectangleAnnot.BorderColor = this.RectangleBorderColor;
  187. RectangleAnnot.BackgroundColor = this.RectangleFillColor;
  188. SetDefautAnnotProperties(RectangleAnnot);
  189. var AnnotLineAnnot = GetAnnotDefault(AnnotArgsType.AnnotLine);
  190. AnnotLineAnnot.BorderColor = this.LineColor;
  191. SetDefautAnnotProperties(AnnotLineAnnot);
  192. Settings.Default.Save();
  193. }
  194. private void SetDefautAnnotProperties(DefaultAnnotProperty annotProperty)
  195. {
  196. if (Settings.Default.DefautAnnotProperties == null)
  197. {
  198. Settings.Default.DefautAnnotProperties = new DefaultAnnotProperties();
  199. }
  200. Settings.Default.DefautAnnotProperties.SetAnnotProperty(annotProperty);
  201. }
  202. private DefaultAnnotProperty GetAnnotDefault(AnnotArgsType annotArgsType)
  203. {
  204. var Annot = SettingHelper.GetAnnotDefaultProperty(annotArgsType);
  205. if (Annot == null)
  206. {
  207. Annot = new DefaultAnnotProperty();
  208. }
  209. return Annot;
  210. }
  211. public void Save()
  212. {
  213. AnnotatePropertyClass annote = new AnnotatePropertyClass();
  214. annote.HighLightColor = this.HighLightColor;
  215. annote.UnderLineColor = this.UnderLineColor;
  216. annote.StrikethroughColor = this.StrikethroughColor;
  217. annote.FreeHandColor = this.FreeHandColor;
  218. annote.TextAnnoteColor = this.TextAnnoteColor;
  219. annote.NoteAnnoteColor = this.NoteAnnoteColor;
  220. annote.RectangleBorderColor = this.RectangleBorderColor;
  221. annote.RectangleFillColor = this.RectangleFillColor;
  222. annote.CircleBorderColor = this.CircleBorderColor;
  223. annote.CircleFillColor = this.CircleFillColor;
  224. annote.LineColor = this.LineColor;
  225. annote.TextFontFamaily = this.TextFontFamaily;
  226. annote.AnchoredFamaily = this.AnchoredFamaily;
  227. annote.TextAlign = this.TextAlign;
  228. Settings.Default.AppProperties.Annotate = annote;
  229. SaveDefaultAnnotSettings();
  230. }
  231. public void Reset()
  232. {
  233. InitFromSettings();
  234. }
  235. }
  236. }