123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- using ComPDFKit.PDFAnnotation;
- using PDF_Office.CustomControl.CompositeControl;
- using PDF_Office.Model.PropertyPanel.AnnotPanel;
- 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_Office.ViewModels.PropertyPanel
- {
- //属性触发事件的标识
- public enum FontSetModeType
- {
- PresetFontStyes,
- FontFamilys,
- FontSizes,
- FontWeight_Style,
- FontColor,
- TextAlignment
- }
- public class FontSetMode : BindableBase
- {
- #region 变量
- protected event EventHandler<FontSetModeType> ChangedValue;
- protected bool IsCanSave = false;
- public List<ComboDataItem> FontFamilyItems { get; protected set; }
- public List<ComboDataItem> FontStyleItems { get; protected set; }
- public List<ComboDataItem> PresetTextItems { get; protected set; }
- public List<FontStyleItem> FontStyleList = new List<FontStyleItem>();
- #endregion
- #region 初始化下拉框或列表默认的数据
- protected void InitBaseVariable()
- {
- InitBase_PresetFontStyles();
- InitBase_FontFamilys();
- InitBase_FontStyles();
- }
- //预设字体样式
- private void InitBase_PresetFontStyles()
- {
- PresetTextItems = new List<ComboDataItem>();
- FontStyleList = TextFont.GetPresetFontStyle();
- foreach (var item in FontStyleList)
- {
- ComboDataItem itemData = new ComboDataItem(item.mTag, item.mTagContent);
- PresetTextItems.Add(itemData);
- }
- }
- //字体
- private void InitBase_FontFamilys()
- {
- FontFamilyItems = TextFont.GetFamily();
- }
- //字重
- private void InitBase_FontStyles()
- {
- FontStyleItems = TextFont.GetFontStyle();
- }
- #endregion
- #region 属性
- private ComboDataItem _presetTextData;
- public ComboDataItem PresetTextData
- {
- get { return _presetTextData; }
- set
- {
- bool isChange = IsEqualStrComboData(_presetTextData, value);
- SetProperty(ref _presetTextData, value);
- if (isChange)
- {
- ChangedValue?.Invoke(_presetTextData.ValueStr, FontSetModeType.PresetFontStyes);
- }
- }
- }
- #region 字体样式
- //下拉框列表
- private ComboDataItem _fontFamilyData;
- public ComboDataItem FontFamilyData
- {
- get { return _fontFamilyData; }
- set
- {
- bool isChange = IsEqualStrComboData(_fontFamilyData, value);
- SetProperty(ref _fontFamilyData, value);
- if (isChange)
- {
- ChangedValue?.Invoke(_fontFamilyData.ValueStr, FontSetModeType.FontFamilys);
- }
- }
- }
- #endregion
- #region 字体大小
- //下拉框列表:字体大小
- private ComboDataItem _fontSizeData = new ComboDataItem(6);
- public ComboDataItem FontSizeData
- {
- get { return _fontSizeData; }
- set
- {
- bool isChange = IsEqualComboData(_fontSizeData, value);
- if(value.Value > 0)
- SetProperty(ref _fontSizeData, value);
- if (isChange && value.Value > 0)
- {
- ChangedValue?.Invoke(_fontSizeData.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 _fontWeightStyleItem;
- public ComboDataItem FontWeightStyleItem
- {
- get { return _fontWeightStyleItem; }
- set
- {
- bool isChange = IsEqualStrComboData(_presetTextData, value);
- SetProperty(ref _fontWeightStyleItem, value);
- if (isChange)
- {
- ChangedValue?.Invoke(_fontWeightStyleItem, FontSetModeType.FontWeight_Style);
- }
- }
- }
- protected void UpdateFontWeight_Style()
- {
- switch (FontWeightStyleItem.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);
- CurrentColor = (selectColor as SolidColorBrush).Color;
- }
-
- }
- }
- private Color currentColor = Colors.Black;
- public Color CurrentColor
- {
- get { return currentColor; }
- set
- {
- SetProperty(ref currentColor, 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 SelectedFontWeights_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 = "粗斜体";
- }
-
- }
- FontWeightStyleItem = new ComboDataItem(strValue, strContent);
- }
- #endregion
- }
- }
|