using ComPDFKit.PDFAnnotation; using PDF_Master.CustomControl.CompositeControl; using PDF_Master.Model.PropertyPanel.AnnotPanel; using PDFSettings; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; namespace PDF_Master.Model.AnnotPanel { //属性触发事件的标识 public enum FontSetModeType { PresetFontStyes, FontFamilys, FontSizes, FontWeight_Style, FontColor, TextAlignment } //设置字体大小、字体内容排版、字体颜色、字体样式、字重 public class FontBoard : BindableBase { #region 变量 protected event EventHandler ChangedValue; protected bool IsCanSave = false; public List FontFamilyItems { get; protected set; } public List FontStyleItems { get; protected set; } public List PresetFontItems { get; protected set; } public List PresetFontList = new List(); #endregion #region 初始化下拉框或列表默认的数据 protected void InitBaseVariable() { InitBase_PresetFontStyles(); InitBase_FontFamilys(); InitBase_FontStyles(); } //预设字体样式 private void InitBase_PresetFontStyles() { PresetFontItems = new List(); PresetFontList = TextFont.GetCachePresetFontList(); foreach (var item in PresetFontList) { ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent); PresetFontItems.Add(itemData); } } //字体 private void InitBase_FontFamilys() { FontFamilyItems = TextFont.GetFamily(); } //字重 private void InitBase_FontStyles() { FontStyleItems = TextFont.GetFontStyle(); } #endregion #region 属性 private ComboDataItem _currentPresetFont; public ComboDataItem CurrentPresetFont { get { return _currentPresetFont; } set { bool isChange = IsEqualStrComboData(_currentPresetFont, value); SetProperty(ref _currentPresetFont, value); if (isChange) { ChangedValue?.Invoke(_currentPresetFont.ValueStr, FontSetModeType.PresetFontStyes); } } } #region 字体样式 //下拉框列表 private ComboDataItem _currentFontFamily; public ComboDataItem CurrentFontFamily { get { return _currentFontFamily; } set { bool isChange = IsEqualStrComboData(_currentFontFamily, value); SetProperty(ref _currentFontFamily, value); if (isChange) { ChangedValue?.Invoke(_currentFontFamily.ValueStr, FontSetModeType.FontFamilys); } } } #endregion #region 字体大小 //下拉框列表:字体大小 private ComboDataItem _currentFontSize = new ComboDataItem(6); public ComboDataItem CurrentFontSize { get { return _currentFontSize; } set { bool isChange = IsEqualComboData(_currentFontSize, value); if (isChange && value.Value > 0) SetProperty(ref _currentFontSize, value); if (isChange && value.Value > 0) { ChangedValue?.Invoke(_currentFontSize.Value, FontSetModeType.FontSizes); } } } #endregion //FontStyle & FontWeight private FontStyle _fontStyle; public FontStyle FontStyleItem { get { return _fontStyle; } set { SetProperty(ref _fontStyle, value); } } private FontWeight _fontWeight; public FontWeight FontWeightItem { get { return _fontWeight; } set { SetProperty(ref _fontWeight, value); } } private ComboDataItem _currrentFontWeightStyle; public ComboDataItem CurrrentFontWeightStyle { get { return _currrentFontWeightStyle; } set { bool isChange = IsEqualStrComboData(_currrentFontWeightStyle, value); SetProperty(ref _currrentFontWeightStyle, value); if (isChange) { ChangedValue?.Invoke(_currrentFontWeightStyle, FontSetModeType.FontWeight_Style); } } } protected void UpdateFontWeight_Style() { switch (CurrrentFontWeightStyle.ValueStr) { case "Regular": FontStyleItem = FontStyles.Normal; FontWeightItem = FontWeights.Normal; break; case "Bold": FontStyleItem = FontStyles.Normal; FontWeightItem = FontWeights.Bold; break; case "Italic": FontStyleItem = FontStyles.Italic; FontWeightItem = FontWeights.Normal; break; case "Bold Italic": FontStyleItem = FontStyles.Italic; FontWeightItem = FontWeights.Bold; break; } } private C_TEXT_ALIGNMENT _textAlignment; public C_TEXT_ALIGNMENT TextAlignmentItem { get { return _textAlignment; } set { SetProperty(ref _textAlignment, value); } } //颜色 private Brush selectColor = new SolidColorBrush(Colors.Black); public Brush SelectColor { get { return selectColor; } set { SetProperty(ref selectColor, value); if (IsCanSave) { ChangedValue?.Invoke((selectColor as SolidColorBrush).Color, FontSetModeType.FontColor); } else { CurrentFontColor = selectColor; } } } private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent); public Brush CurrentFontColor { get { return _currentFontColor; } set { SetProperty(ref _currentFontColor, value); } } private bool IsEqualComboData(ComboDataItem oldValue, ComboDataItem newValue) { if (newValue == null || IsCanSave == false) return false; if (oldValue != null && newValue != null) { if (oldValue.Value != newValue.Value) return true; } return false; } private bool IsEqualStrComboData(ComboDataItem oldValue, ComboDataItem newValue) { if (newValue == null || string.IsNullOrEmpty(newValue.ValueStr) == true || IsCanSave == false) return false; if (oldValue != null && newValue != null) { if (oldValue.ValueStr != newValue.ValueStr) return true; } return false; } #endregion #region 列表选中赋值 protected void GetFontWeights_Style(FontStyle fontStyle, FontWeight fontWeights) { string strValue = ""; string strContent = ""; if (fontStyle == FontStyles.Normal) { if (fontWeights == FontWeights.Normal) { strValue = "Regular"; strContent = "常规"; } else { strValue = "Bold"; strContent = "粗体"; } } else { if (fontWeights == FontWeights.Normal) { strValue = "Italic"; strContent = "斜体"; } else { strValue = "Bold Italic"; strContent = "粗斜体"; } } CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent); } protected void GetCurrentFontSize(int size) { CurrentFontSize = new ComboDataItem(size); } protected void GetCurrentFontFamily(string fontFamily, string uiStr) { CurrentFontFamily = new ComboDataItem(fontFamily, uiStr); } #endregion } //设置字体大小、字体内容排版、字体颜色、字体样式、字重 public class FontBoardVm : BindableBase { #region 变量 public List FontFamilyItems { get; protected set; } public List FontStyleItems { get; protected set; } public List PresetFontItems { get; protected set; } public List PresetFontList = new List(); public FontBoardVm(bool isInitdata) { if (isInitdata) InitBaseVariable(); } #endregion #region 初始化下拉框或列表默认的数据 protected void InitBaseVariable() { InitBase_PresetFontStyles(); InitBase_FontFamilys(); InitBase_FontStyles(); } //预设字体样式 private void InitBase_PresetFontStyles() { PresetFontItems = new List(); PresetFontList = TextFont.GetCachePresetFontList(); foreach (var item in PresetFontList) { ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent); PresetFontItems.Add(itemData); } } //字体 private void InitBase_FontFamilys() { FontFamilyItems = TextFont.GetFamily(); } //字重 private void InitBase_FontStyles() { FontStyleItems = TextFont.GetFontStyle(); } #endregion #region 属性 private ComboDataItem _currentPresetFont = new ComboDataItem("custom", "Custom"); public ComboDataItem CurrentPresetFont { get { return _currentPresetFont; } set => SetProperty(ref _currentPresetFont, value); } #region 字体样式 //下拉框列表 private ComboDataItem _currentFontFamily = new ComboDataItem("Arial", "Helvetica"); public ComboDataItem CurrentFontFamily { get { return _currentFontFamily; } set => SetProperty(ref _currentFontFamily, value); } #endregion #region 字体大小 //下拉框列表:字体大小 private ComboDataItem _currentFontSize = new ComboDataItem(6); public ComboDataItem CurrentFontSize { get { return _currentFontSize; } set => SetProperty(ref _currentFontSize, value); } #endregion //FontStyle & FontWeight private FontStyle _fontStyleItem; public FontStyle FontStyleItem { get { return _fontStyleItem; } set { SetProperty(ref _fontStyleItem, value); } } private FontWeight _fontWeight; public FontWeight FontWeightItem { get { return _fontWeight; } set { SetProperty(ref _fontWeight, value); } } private ComboDataItem _currrentFontWeightStyle = new ComboDataItem("Regular", "Regular"); public ComboDataItem CurrrentFontWeightStyle { get { return _currrentFontWeightStyle; } set => SetProperty(ref _currrentFontWeightStyle, value); } public void UpdateFontWeight_Style() { switch (CurrrentFontWeightStyle.ValueStr) { case "Regular": FontStyleItem = FontStyles.Normal; FontWeightItem = FontWeights.Normal; break; case "Bold": FontStyleItem = FontStyles.Normal; FontWeightItem = FontWeights.Bold; break; case "Italic": FontStyleItem = FontStyles.Italic; FontWeightItem = FontWeights.Normal; break; case "Bold Italic": FontStyleItem = FontStyles.Italic; FontWeightItem = FontWeights.Bold; break; } } //文字内容对齐 private string _strtextAlign; public string StrTextAlign { get { return _strtextAlign; } set { SetProperty(ref _strtextAlign, value); } } //颜色 private Brush _fontColor = new SolidColorBrush(Colors.Black); public Brush FontColor { get { return _fontColor; } set { SetProperty(ref _fontColor, value); CurrentFontColor = _fontColor; } } private Brush _currentFontColor = new SolidColorBrush(Colors.Transparent); public Brush CurrentFontColor { get { return _currentFontColor; } set => SetProperty(ref _currentFontColor, value); } //外部UI引用,判断是否选中左对齐、居中对齐、右对齐,或都不选中 public string strAglinState { get; private set; } //VM赋值 public void SetStrAglinState(string str) { strAglinState = str; } #endregion #region 列表选中赋值 public void GetFontWeights_Style(FontStyle fontStyle, FontWeight fontWeights) { string strValue = ""; string strContent = ""; if (fontStyle == FontStyles.Normal) { if (fontWeights == FontWeights.Normal) { strValue = "Regular"; strContent = "常规"; } else { strValue = "Bold"; strContent = "粗体"; } } else { if (fontWeights == FontWeights.Normal) { strValue = "Italic"; strContent = "斜体"; } else { strValue = "Bold Italic"; strContent = "粗斜体"; } } CurrrentFontWeightStyle = new ComboDataItem(strValue, strContent); } public void GetCurrentFontSize(int size) { CurrentFontSize = new ComboDataItem(size); } public void GetCurrentFontFamily(string fontFamily, string uiStr) { CurrentFontFamily = new ComboDataItem(fontFamily, uiStr); } #endregion } }