Kaynağa Gözat

属性面板 - 文字字体属性样式

chenrongqian@kdanmobile.com 2 yıl önce
ebeveyn
işleme
663bce66e6

+ 1 - 0
PDF Office/PDF Office.csproj

@@ -492,6 +492,7 @@
     <Compile Include="ViewModels\PropertyPanel\AnnotPanel\SignatureCreateDialogViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\AnnotPanel\SnapshotEditMenuViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\AnnotPanel\StickyNotePropertyViewModel.cs" />
+    <Compile Include="ViewModels\PropertyPanel\FontSetModeVM.cs" />
     <Compile Include="ViewModels\PropertyPanel\PDFEdit\ImageEditPropertyViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\PDFEdit\ImageTextEditPropertyViewModel.cs" />
     <Compile Include="ViewModels\PropertyPanel\PDFEdit\PDFEditVM.cs" />

+ 188 - 0
PDF Office/ViewModels/PropertyPanel/FontSetModeVM.cs

@@ -0,0 +1,188 @@
+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
+
+    }
+    public class FontSetMode : BindableBase
+    {
+        #region 变量
+        public event EventHandler<FontSetModeType> ChangedValue;
+        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
+            {
+                SetProperty(ref _presetTextData, value);
+                if (_presetTextData != null)
+                {
+                    ChangedValue?.Invoke(_presetTextData.ValueStr, FontSetModeType.PresetFontStyes);
+                }
+            }
+        }
+
+        //字体样式
+        private ComboDataItem _fontFamilyData;
+        public ComboDataItem FontFamilyData
+        {
+            get { return _fontFamilyData; }
+            set
+            {
+                SetProperty(ref _fontFamilyData, value);
+                if(_fontFamilyData != null)
+                {
+                    ChangedValue?.Invoke(_fontFamilyData.ValueStr, FontSetModeType.FontFamilys);
+                }
+            }
+        }
+
+        //字体大小
+        private ComboDataItem _fontSizeData = new ComboDataItem(6);
+        public ComboDataItem FontSizeData
+        {
+            get { return _fontSizeData; }
+            set
+            {
+                SetProperty(ref _fontSizeData, value);
+                if(_fontSizeData != null)
+                {
+                    ChangedValue?.Invoke(_fontSizeData.Value, FontSetModeType.FontSizes);
+                }
+            }
+        }
+
+        //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
+            {
+                SetProperty(ref _fontWeightStyleItem, value);
+                if (_fontWeightStyleItem.ValueStr != null && string.IsNullOrEmpty((string)_fontWeightStyleItem.ValueStr) == false)
+                {
+                    if(_fontWeightStyleItem != null)
+                    {
+                        ChangedValue?.Invoke(null, 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 Brush selectColor = new SolidColorBrush(Colors.Black);
+        public Brush SelectColor
+        {
+            get { return selectColor; }
+            set
+            {
+                SetProperty(ref selectColor, value);
+                ChangedValue?.Invoke((selectColor as SolidColorBrush).Color, FontSetModeType.FontColor);
+            }
+        }
+
+        #endregion
+    }
+}