AnnotCommon.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. using ComPDFKitViewer.AnnotEvent;
  2. using PDF_Office.CustomControl.CompositeControl;
  3. using PDF_Office.Helper;
  4. using PDF_Office.Properties;
  5. using PDFSettings;
  6. using Prism.Mvvm;
  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.Media;
  13. namespace PDF_Office.Model.AnnotPanel
  14. {
  15. //注释的通用属性
  16. public class AnnotCommon : BindableBase
  17. {
  18. //注释类型
  19. private AnnotArgsType _annotType;
  20. public AnnotArgsType AnnotType
  21. {
  22. get { return _annotType; }
  23. set => SetProperty(ref _annotType, value);
  24. }
  25. //注释类型名称
  26. private string _annotTypeTitle;
  27. public string AnnotTypeTitle
  28. {
  29. get { return _annotTypeTitle; }
  30. set => SetProperty(ref _annotTypeTitle, value);
  31. }
  32. #region 线条
  33. //线条粗细大小
  34. private double _annotThickness = 1;
  35. public double AnnotThickness
  36. {
  37. get { return _annotThickness; }
  38. set => SetProperty(ref _annotThickness, value);
  39. }
  40. //线条样式
  41. private DashStyle dash = new DashStyle();
  42. public DashStyle Dash
  43. {
  44. get { return dash; }
  45. set => SetProperty(ref dash, value);
  46. }
  47. #endregion 线条
  48. #region 填充
  49. //填充颜色透明度
  50. private double fillOpacity = 1;
  51. public double FillOpacity
  52. {
  53. get { return fillOpacity; }
  54. set => SetProperty(ref fillOpacity, value);
  55. }
  56. //当前填充颜色
  57. private Brush _currentFillColor = new SolidColorBrush(Colors.Transparent);
  58. public Brush CurrentFillColor
  59. {
  60. get { return _currentFillColor; }
  61. set => SetProperty(ref _currentFillColor, value);
  62. }
  63. //填充颜色
  64. private Brush fillColor = new SolidColorBrush(Colors.Transparent);
  65. public Brush FillColor
  66. {
  67. get { return fillColor; }
  68. set { SetProperty(ref fillColor, value); CurrentFillColor = fillColor; }
  69. }
  70. //边框颜色集合
  71. private List<ColorItem> _colorItems = new List<ColorItem>();
  72. public List<ColorItem> ColorItems
  73. {
  74. get { return _colorItems; }
  75. set => SetProperty(ref _colorItems, value);
  76. }
  77. //填充颜色集合
  78. private List<ColorItem> _fillColorItems = new List<ColorItem>();
  79. public List<ColorItem> FillColorItems
  80. {
  81. get { return _fillColorItems; }
  82. set => SetProperty(ref _fillColorItems, value);
  83. }
  84. #endregion 填充
  85. #region 边框
  86. //边框颜色透明度
  87. private double _borderOpacity = 1;
  88. public double BorderOpacity
  89. {
  90. get { return _borderOpacity; }
  91. set => SetProperty(ref _borderOpacity, value);
  92. }
  93. private Brush _borderColor = new SolidColorBrush(Colors.Transparent);
  94. public Brush BorderColor
  95. {
  96. get { return _borderColor; }
  97. set { SetProperty(ref _borderColor, value); CurrentBorderColor = _borderColor; }
  98. }
  99. //当前边框颜色
  100. private Brush _currentBorderColor = new SolidColorBrush(Colors.Transparent);
  101. public Brush CurrentBorderColor
  102. {
  103. get { return _currentBorderColor; }
  104. set => SetProperty(ref _currentBorderColor, value);
  105. }
  106. private Brush _fontColor = new SolidColorBrush(Colors.Transparent);
  107. public Brush FontColor
  108. {
  109. get { return _fontColor; }
  110. set { SetProperty(ref _fontColor, value); CurrentFontColor = _fontColor; }
  111. }
  112. //当前边框颜色
  113. private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent);
  114. public Brush CurrentFontColor
  115. {
  116. get { return _currentFontColor; }
  117. set => SetProperty(ref _currentFontColor, value);
  118. }
  119. //外部UI引用,判断是否选中实线、虚线、或都不选中
  120. public string strDashStyle { get; private set; }
  121. //VM赋值
  122. public void SetStrDashStyle(string str)
  123. {
  124. strDashStyle = str;
  125. }
  126. //外部UI引用,其他:例如形状注释类型
  127. public string strOtherTag { get; private set; }
  128. //VM赋值
  129. public void SetOtherTag(string str)
  130. {
  131. strOtherTag = str;
  132. }
  133. #endregion
  134. #region 多选
  135. //多选注释:用处 - 多选注释使得下拉框为空内容,刷新最新的UI布局
  136. private bool _isMultiSelected = false;
  137. public bool IsMultiSelected
  138. {
  139. get { return _isMultiSelected; }
  140. set => SetProperty(ref _isMultiSelected, value);
  141. }
  142. #endregion
  143. /// <summary>
  144. /// VM触发到外部UI事件
  145. /// </summary>
  146. public event EventHandler<object> SelectedAnnotInvokeToUI;
  147. //Todo:由于考虑到有些UI在VM不太方便处理,因此需要触发该函数到外部xaml.cs里更改UI属性。
  148. //更改多个属性:value可为键值对集合
  149. //适应范围:若VM在Loaded进行绑定,需要UI初始化之后,才能起到作用
  150. public void InvokeToUI(object sender, object value)
  151. {
  152. SelectedAnnotInvokeToUI?.Invoke(sender, value);
  153. }
  154. }
  155. //注释的通用颜色集合
  156. public class AnnotColorList
  157. {
  158. //用于高亮注释颜色
  159. public static List<ColorItem> GetColorList(ColorSelectorType type)
  160. {
  161. ColorSelectorItem cacheColorItem = null;
  162. if (Settings.Default.ColorSelectors == null)
  163. {
  164. Settings.Default.ColorSelectors = new ColorSelectorList();
  165. }
  166. else
  167. {
  168. //是否存在某类型的颜色列表
  169. cacheColorItem = Settings.Default.ColorSelectors.FirstOrDefault(temp => temp.SelectorType == type);
  170. }
  171. List<ColorItem> Items = GetSpecifiedColorList(type);
  172. if (cacheColorItem== null)
  173. {
  174. SaveInitSelector(Items, type);
  175. }
  176. else
  177. {
  178. //若存在,同步缓存里的数据
  179. foreach(var item in Items)
  180. {
  181. var selector = SettingHelper.GetColorSelectorItem(type, item.Index);
  182. if (selector != null)
  183. {
  184. item.Color = new SolidColorBrush(selector.color);
  185. }
  186. }
  187. }
  188. return Items;
  189. }
  190. //缓存第一次初始化数据
  191. private static void SaveInitSelector(List<ColorItem> colors, ColorSelectorType type)
  192. {
  193. if (Settings.Default.ColorSelectors == null)
  194. {
  195. Settings.Default.ColorSelectors = new ColorSelectorList();
  196. }
  197. foreach (var item in colors)
  198. {
  199. ColorSelectorItem colorSelectorItem = new ColorSelectorItem();
  200. colorSelectorItem.color = (item.Color as SolidColorBrush).Color;
  201. colorSelectorItem.SelectorType = type;
  202. colorSelectorItem.Index = item.Index;
  203. colorSelectorItem.IsChangedColor = false;
  204. Settings.Default.ColorSelectors.Add(colorSelectorItem);
  205. }
  206. Settings.Default.Save();
  207. }
  208. //选取某类型第一次初始化(默认值)的颜色列表
  209. private static List<ColorItem> GetSpecifiedColorList(ColorSelectorType type)
  210. {
  211. List<ColorItem> Items = null;
  212. switch (type)
  213. {
  214. case ColorSelectorType.Highlight:
  215. Items = GetHighlightColorList();
  216. break;
  217. case ColorSelectorType.Border:
  218. Items = GetBorderColorList();
  219. break;
  220. case ColorSelectorType.Fill:
  221. Items = GetFillColorList();
  222. break;
  223. case ColorSelectorType.Sticky:
  224. Items = GetStyleColorList();
  225. break;
  226. default:
  227. Items = GetHighlightColorList();
  228. break;
  229. }
  230. return Items;
  231. }
  232. //用于高亮注释颜色
  233. private static List<ColorItem> GetHighlightColorList()
  234. {
  235. List<ColorItem> HighlightItems = new List<ColorItem>();
  236. HighlightItems = new List<ColorItem>();
  237. ColorItem colorItem = new ColorItem(Color.FromArgb(0xff, 0xff, 0xC7, 0x00), 0);
  238. HighlightItems.Add(colorItem);
  239. colorItem = new ColorItem(Color.FromArgb(0xff, 0xFC, 0x1F, 0x1F), 1);
  240. HighlightItems.Add(colorItem);
  241. colorItem = new ColorItem(Color.FromArgb(0xff, 0x3E, 0xED, 0x92), 2);
  242. HighlightItems.Add(colorItem);
  243. colorItem = new ColorItem(Color.FromArgb(0xff, 0x47, 0xC8, 0xFF), 3);
  244. HighlightItems.Add(colorItem);
  245. return HighlightItems;
  246. }
  247. //用于边框颜色
  248. private static List<ColorItem> GetBorderColorList()
  249. {
  250. List<ColorItem> BorderItems = new List<ColorItem>();
  251. BorderItems = new List<ColorItem>();
  252. ColorItem colorItem = new ColorItem(Color.FromArgb(0xff, 0xFC, 0x1F, 0x1F), 0);
  253. BorderItems.Add(colorItem);
  254. colorItem = new ColorItem(Color.FromArgb(0xff, 0x29, 0x53, 0x93), 1);
  255. BorderItems.Add(colorItem);
  256. colorItem = new ColorItem(Color.FromArgb(0xff, 0x1E, 0x89, 0x56), 2);
  257. BorderItems.Add(colorItem);
  258. colorItem = new ColorItem(Color.FromArgb(0xff, 0xB8, 0x08, 0xD4), 3);
  259. BorderItems.Add(colorItem);
  260. return BorderItems;
  261. }
  262. //用于填充颜色
  263. private static List<ColorItem> GetFillColorList()
  264. {
  265. List<ColorItem> FillItems = new List<ColorItem>();
  266. FillItems = new List<ColorItem>();
  267. ColorItem colorItem = new ColorItem(Colors.Transparent, 0);
  268. FillItems.Add(colorItem);
  269. colorItem = new ColorItem(Color.FromArgb(0xff, 0xff, 0xff, 0xff), 1);
  270. FillItems.Add(colorItem);
  271. colorItem = new ColorItem(Color.FromArgb(0xff, 0xDF, 0xE1, 0xE4), 2);
  272. FillItems.Add(colorItem);
  273. colorItem = new ColorItem(Color.FromArgb(0xff, 0xFF, 0xF1, 0xC1), 3);
  274. FillItems.Add(colorItem);
  275. return FillItems;
  276. }
  277. //用于注释样式颜色:如便签样式颜色
  278. private static List<ColorItem> GetStyleColorList()
  279. {
  280. List<ColorItem> StyleItems = new List<ColorItem>();
  281. StyleItems = new List<ColorItem>();
  282. ColorItem colorItem = new ColorItem(Color.FromArgb(0xff, 0xff, 0xD5, 0x73), 0);
  283. StyleItems.Add(colorItem);
  284. colorItem = new ColorItem(Color.FromArgb(0xff, 0xF8, 0x59, 0xC8), 1);
  285. StyleItems.Add(colorItem);
  286. colorItem = new ColorItem(Color.FromArgb(0xff, 0x1A, 0xD5, 0x98), 2);
  287. StyleItems.Add(colorItem);
  288. colorItem = new ColorItem(Color.FromArgb(0xff, 0x68, 0xAC, 0xF8), 3);
  289. StyleItems.Add(colorItem);
  290. return StyleItems;
  291. }
  292. }
  293. }