using PDF_Office.CustomControl.CompositeControl; using PDF_Office.Properties; using PDFSettings; 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.Model.PropertyPanel.AnnotPanel { public class TextFont { //获取本地缓存数据 public static List GetCachePresetFontList() { List cacheTempList = new List(); if (Settings.Default.PresetFontList == null) Settings.Default.PresetFontList = new PresetFontList(); if (Settings.Default.PresetFontList.Count == 0) { cacheTempList = GetPresetFontStyle(); foreach(var cacheItem in cacheTempList) { var newItem = new PresetFontItem(); newItem.mTag = cacheItem.mTag; newItem.mTagContent = cacheItem.mTagContent; newItem.mFontStyle = cacheItem.mFontStyle; newItem.mFontWeight = cacheItem.mFontWeight; newItem.mFontSize = cacheItem.mFontSize; Settings.Default.PresetFontList.Add(newItem); } Settings.Default.Save(); } else { foreach (var item in Settings.Default.PresetFontList) { var newItem = new PresetFontItem(); newItem.mTag = item.mTag; newItem.mTagContent = item.mTagContent; newItem.mFontStyle = item.mFontStyle; newItem.mFontWeight = item.mFontWeight; newItem.mFontSize = item.mFontSize; cacheTempList.Add(newItem); } } return cacheTempList; } //保存到本地缓存数据 public static void SavePresetFontList(List list) { if (list == null) return; if(Settings.Default.PresetFontList == null) Settings.Default.PresetFontList = new PresetFontList(); bool isCanSave = false; List TempLists = new List(); foreach (var item in list) { var cacheItem = Settings.Default.PresetFontList.FirstOrDefault(temp => temp.mTag == item.mTag); if (cacheItem != null) { if(cacheItem.mFontFamily != item.mFontFamily || cacheItem.mFontSize != item.mFontSize || cacheItem.mFontStyle != item.mFontStyle || cacheItem.mFontWeight != item.mFontWeight ) { isCanSave = true; } break; } else { TempLists.Add(item); } } foreach(var itemTemp in TempLists) { Settings.Default.PresetFontList.Add(itemTemp); } if (isCanSave) Settings.Default.Save(); } public static void BackDefaultPresetFontStyle(string tag) { bool isCanSave = false; var list = GetPresetFontStyle(); var itemDefault = list.FirstOrDefault(temp => temp.mTag == tag); if (Settings.Default.PresetFontList == null) Settings.Default.PresetFontList = new PresetFontList(); if(Settings.Default.PresetFontList.Count == 0) { Settings.Default.PresetFontList.Add(itemDefault); isCanSave = true; } else { foreach (var item in Settings.Default.PresetFontList) { if (item.mTag == itemDefault.mTag) { item.mFontFamily = itemDefault.mFontFamily; item.mFontWeight = itemDefault.mFontWeight; item.mFontStyle = itemDefault.mFontStyle; item.mFontSize = itemDefault.mFontSize; isCanSave = true; break; } } } if (isCanSave == true) Settings.Default.Save(); } //获取拟定的预设样式 private static List GetPresetFontStyle() { List fontStyleList = new List(); PresetFontItem custom = new PresetFontItem(); custom.mTag = "custom"; custom.mTagContent = "自定义"; custom.mFontSize = 24; custom.mFontFamily = new FontFamily("Helvatica"); custom.mFontStyle = FontStyles.Normal; custom.mFontWeight = FontWeights.Normal; PresetFontItem h1 = new PresetFontItem(); h1.mTag = "H1"; h1.mTagContent = "H1大标题"; h1.mFontSize = 36; h1.mFontFamily = new FontFamily("Helvatica"); h1.mFontStyle = FontStyles.Normal; h1.mFontWeight = FontWeights.Normal; PresetFontItem h2 = new PresetFontItem(); h2.mTag = "H2"; h2.mTagContent = "h2(标准)"; h2.mFontSize = 24; h2.mFontFamily = new FontFamily("Helvatica"); h2.mFontStyle = FontStyles.Normal; h2.mFontWeight = FontWeights.Bold; PresetFontItem h3 = new PresetFontItem(); h3.mTag = "H3"; h3.mTagContent = "H3小标题"; h3.mFontSize = 18; h3.mFontFamily = new FontFamily("Helvatica"); h3.mFontStyle = FontStyles.Normal; h3.mFontWeight = FontWeights.Bold; PresetFontItem b1 = new PresetFontItem(); b1.mTag = "B1"; b1.mTagContent = "B1标题"; b1.mFontSize = 14; b1.mFontFamily = new FontFamily("Helvatica"); b1.mFontStyle = FontStyles.Normal; b1.mFontWeight = FontWeights.Normal; PresetFontItem b2 = new PresetFontItem(); b2.mTag = "B2"; b2.mTagContent = "B2标题"; b2.mFontSize = 12; b2.mFontFamily = new FontFamily("Helvatica"); b2.mFontStyle = FontStyles.Normal; b2.mFontWeight = FontWeights.Normal; PresetFontItem b3 = new PresetFontItem(); b3.mTag = "B3"; b3.mTagContent = "B3标题"; b3.mFontSize = 11; b3.mFontFamily = new FontFamily("Helvatica"); b3.mFontStyle = FontStyles.Normal; b3.mFontWeight = FontWeights.Normal; fontStyleList.Add(custom); fontStyleList.Add(h1); fontStyleList.Add(h2); fontStyleList.Add(h3); fontStyleList.Add(b1); fontStyleList.Add(b2); fontStyleList.Add(b3); return fontStyleList; } public static List GetFontStyle() { var FontStyleItems = new List(); ComboDataItem item = new ComboDataItem("Regular", "Regular"); FontStyleItems.Add(item); item = new ComboDataItem("Bold", "Bold"); FontStyleItems.Add(item); item = new ComboDataItem("Italic", "Italic"); FontStyleItems.Add(item); item = new ComboDataItem("Bold Italic", "Bold Italic"); FontStyleItems.Add(item); return FontStyleItems; } public static List GetFamily() { var FontFamilyItems = new List(); ComboDataItem item = new ComboDataItem("Courier", "Courier New"); FontFamilyItems.Add(item); item = new ComboDataItem("Helvetica", "Helvetica"); FontFamilyItems.Add(item); item = new ComboDataItem("Times-Roman", "Times New Roman"); FontFamilyItems.Add(item); return FontFamilyItems; } } }