123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- using PDF_Master.CustomControl.CompositeControl;
- using PDF_Master.Helper;
- using PDF_Master.Model.AnnotPanel;
- using PDF_Master.Properties;
- using PDFSettings;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Media;
- namespace PDF_Master.Model.PropertyPanel.AnnotPanel
- {
- public class TextFont
- {
- //获取本地缓存数据
- public static List<PresetFontItem> GetCachePresetFontList()
- {
- List<PresetFontItem> cacheTempList = new List<PresetFontItem>();
- if (Settings.Default.PresetFontList == null)
- Settings.Default.PresetFontList = new PresetFontList();
- if (Settings.Default.PreinstallFontList == null)
- Settings.Default.PreinstallFontList = new PreinstallFontList();
- if (Settings.Default.PreinstallFontList.Count == 0/*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;
- newItem.mFontFamily = cacheItem.mFontFamily;
- Settings.Default.PresetFontList.Add(newItem);
- //复杂数据类型 , 不可本地缓存到配置文件,需要转换一下(先 string保存,再根据类型缓存)
- var newItem1 = new PreinstallItem();
- newItem1.mTag = cacheItem.mTag;
- newItem1.mTagContent = cacheItem.mTagContent;
- newItem1.mFontStyle = cacheItem.mFontStyle.ToString();
- newItem1.mFontWeight = cacheItem.mFontWeight.ToString();
- newItem1.mFontSize = cacheItem.mFontSize;
- newItem1.mFontFamily = cacheItem.mFontFamily.Source;
- Settings.Default.PreinstallFontList.Add(newItem1);
- }
- Settings.Default.Save();
- }
- else
- {
- //根据 对应的字段 内容 ,对照相对应的类型
- foreach (var item in Settings.Default.PreinstallFontList)
- {
- var newItem = new PresetFontItem();
- newItem.mTag = item.mTag;
- newItem.mTagContent = item.mTagContent;
- switch (item.mFontStyle)
- {
- case "Normal":
- newItem.mFontStyle = FontStyles.Normal;
- break;
- case "Italic":
- newItem.mFontStyle = FontStyles.Italic;
- break;
- case "Oblique":
- newItem.mFontStyle = FontStyles.Oblique;
- break;
- }
- switch (item.mFontWeight)
- {
- case "Bold":
- newItem.mFontWeight = FontWeights.Bold;
- break;
- case "Normal":
- newItem.mFontWeight = FontWeights.Normal;
- break;
- }
- newItem.mFontSize = item.mFontSize;
- newItem.mFontFamily = new FontFamily(item.mFontFamily);
- cacheTempList.Add(newItem);
- }
- //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;
- // newItem.mFontFamily = item.mFontFamily;
- // cacheTempList.Add(newItem);
- //}
- }
- return cacheTempList;
- }
- //保存到本地缓存数据
- public static void SavePresetFontList(List<PresetFontItem> list)
- {
- if (list == null) return;
- if (Settings.Default.PresetFontList == null)
- Settings.Default.PresetFontList = new PresetFontList();
- if (Settings.Default.PreinstallFontList == null)
- Settings.Default.PreinstallFontList = new PreinstallFontList();
- bool isCanSave = false;
- List<PresetFontItem> TempLists = new List<PresetFontItem>();
- foreach (var item in list)
- {
- //根据预设标题 ,找到 相对应数据
- var cacheItem = Settings.Default.PreinstallFontList.FirstOrDefault(temp => temp.mTag == item.mTag);
- if (cacheItem != null)
- {
- //比对数据,如果不一样 ,更新数据
- if (cacheItem.mFontFamily != item.mFontFamily.Source ||
- cacheItem.mFontSize != item.mFontSize ||
- cacheItem.mFontStyle != item.mFontStyle.ToString() ||
- cacheItem.mFontWeight != item.mFontWeight.ToString()
- )
- {
- isCanSave = true;
- var index = Settings.Default.PreinstallFontList.FindIndex(temp => temp.mTag == cacheItem.mTag);
- if (index != -1)
- {
- Settings.Default.PreinstallFontList.Remove(cacheItem);
- var newItem1 = new PreinstallItem();
- newItem1.mTag = item.mTag;
- newItem1.mTagContent = item.mTagContent;
- newItem1.mFontStyle = item.mFontStyle.ToString();
- newItem1.mFontWeight = item.mFontWeight.ToString();
- newItem1.mFontSize = item.mFontSize;
- newItem1.mFontFamily = item.mFontFamily.Source;
- Settings.Default.PreinstallFontList.Insert(index, newItem1);
- }
- //cacheItem.mFontFamily = new FontFamily(item.mFontFamily.Source);
- //cacheItem.mFontSize = item.mFontSize;
- //cacheItem.mFontStyle = item.mFontStyle;
- //cacheItem.mFontWeight = item.mFontWeight;
- 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.mTagContent = itemDefault.mTagContent;
- 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();
- }
- //获取拟定的预设样式
- public static List<PresetFontItem> GetPresetFontStyle()
- {
- List<PresetFontItem> fontStyleList = new List<PresetFontItem>();
- PresetFontItem custom = new PresetFontItem();
- custom.mTag = "Custom";
- custom.mTagContent = App.MainPageLoader.GetString("PresetTextStyle_Customize");
- custom.mFontSize = 24;
- custom.mFontFamily = new FontFamily("Arial");
- custom.mFontStyle = FontStyles.Normal;
- custom.mFontWeight = FontWeights.Normal;
- PresetFontItem h1 = new PresetFontItem();
- h1.mTag = "H1";
- h1.mTagContent = App.MainPageLoader.GetString("PresetTextStyle_H1Title");
- h1.mFontSize = 36;
- h1.mFontFamily = new FontFamily("Arial");
- h1.mFontStyle = FontStyles.Normal;
- h1.mFontWeight = FontWeights.Bold;
- PresetFontItem h2 = new PresetFontItem();
- h2.mTag = "H2";
- h2.mTagContent = App.MainPageLoader.GetString("PresetTextStyle_H2Title");
- h2.mFontSize = 24;
- h2.mFontFamily = new FontFamily("Arial");
- h2.mFontStyle = FontStyles.Normal;
- h2.mFontWeight = FontWeights.Bold;
- PresetFontItem h3 = new PresetFontItem();
- h3.mTag = "H3";
- h3.mTagContent = App.MainPageLoader.GetString("PresetTextStyle_H3Title");
- h3.mFontSize = 18;
- h3.mFontFamily = new FontFamily("Arial");
- h3.mFontStyle = FontStyles.Normal;
- h3.mFontWeight = FontWeights.Bold;
- PresetFontItem b1 = new PresetFontItem();
- b1.mTag = "B1";
- b1.mTagContent = App.MainPageLoader.GetString("PresetTextStyle_B1NormalTextStandard");
- b1.mFontSize = 14;
- b1.mFontFamily = new FontFamily("Arial");
- b1.mFontStyle = FontStyles.Normal;
- b1.mFontWeight = FontWeights.Regular;
- PresetFontItem b2 = new PresetFontItem();
- b2.mTag = "B2";
- b2.mTagContent = App.MainPageLoader.GetString("PresetTextStyle_B2NormalTextSmall");
- b2.mFontSize = 12;
- b2.mFontFamily = new FontFamily("Arial");
- b2.mFontStyle = FontStyles.Normal;
- b2.mFontWeight = FontWeights.Regular;
- PresetFontItem b3 = new PresetFontItem();
- b3.mTag = "B3";
- b3.mTagContent = App.MainPageLoader.GetString("PresetTextStyle_B3Description");
- b3.mFontSize = 11;
- b3.mFontFamily = new FontFamily("Arial");
- b3.mFontStyle = FontStyles.Normal;
- b3.mFontWeight = FontWeights.Regular;
- 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<ComboDataItem> GetFontStyle()
- {
- var FontStyleItems = new List<ComboDataItem>();
- 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;
- }
- internal static List<ComboDataItem> GetFontSize()
- {
- var FontSizeItems = new List<ComboDataItem>();
- ComboDataItem item = new ComboDataItem(8);
- FontSizeItems.Add(item);
- item = new ComboDataItem(9);
- FontSizeItems.Add(item);
- item = new ComboDataItem(10);
- FontSizeItems.Add(item);
- item = new ComboDataItem(11);
- FontSizeItems.Add(item);
- item = new ComboDataItem(12);
- FontSizeItems.Add(item);
- item = new ComboDataItem(14);
- FontSizeItems.Add(item);
- item = new ComboDataItem(16);
- FontSizeItems.Add(item);
- item = new ComboDataItem(18);
- FontSizeItems.Add(item);
- item = new ComboDataItem(20);
- FontSizeItems.Add(item);
- item = new ComboDataItem(22);
- FontSizeItems.Add(item);
- item = new ComboDataItem(24);
- FontSizeItems.Add(item);
- item = new ComboDataItem(26);
- FontSizeItems.Add(item);
- item = new ComboDataItem(28);
- FontSizeItems.Add(item);
- item = new ComboDataItem(36);
- FontSizeItems.Add(item);
- item = new ComboDataItem(48);
- FontSizeItems.Add(item);
- item = new ComboDataItem(72);
- FontSizeItems.Add(item);
- return FontSizeItems;
- }
- public static List<ComboDataItem> GetFamily()
- {
- var FontFamilyItems = new List<ComboDataItem>();
- ComboDataItem item = new ComboDataItem("Courier", "Courier New");
- FontFamilyItems.Add(item);
- item = new ComboDataItem("Arial", "Arial");
- FontFamilyItems.Add(item);
- item = new ComboDataItem(/*"Times-Roman"*/"Times", "Times New Roman");
- FontFamilyItems.Add(item);
- return FontFamilyItems;
- }
- public static List<ComboDataItem> GetFamilyEdit()
- {
- System.Drawing.Text.InstalledFontCollection objFont = new System.Drawing.Text.InstalledFontCollection();
- var FontFamilyItems = new List<ComboDataItem>();
- ComboDataItem item;
- foreach (var itemFam in EditHelper.GetFontFamily())
- {
- string content = itemFam;
- if (itemFam.Equals("Informal"))
- {
- content = "Informal Roman";
- }
- if (itemFam.Equals("Marlett"))
- {
- continue;
- }
- item = new ComboDataItem(DeleteCharacters(itemFam), content);
- FontFamilyItems.Add(item);
- }
- return FontFamilyItems;
- }
- public static string DeleteCharacters(string str)
- {
- str = str.Replace(" ", string.Empty);
- str = str.Replace("-", string.Empty);
- str = str.Replace("_", string.Empty);
- return str;
- }
- public static List<ComboDataItem> GetDateFormats()
- {
- var dateFormatItems = new List<ComboDataItem>();
- foreach (var itemFormat in GetTimesFormats())
- {
- ComboDataItem item = new ComboDataItem(itemFormat, "format");
- dateFormatItems.Add(item);
- }
- return dateFormatItems;
- }
- private static List<string> GetTimesFormats()
- {
- List<string> TimesItems = new List<string>();
- TimesItems.Add("yyyy年M月d日");
- TimesItems.Add("M/d");
- TimesItems.Add("M/d/yy");
- TimesItems.Add("M/d/yyyy");
- TimesItems.Add("MM/dd/yy");
- TimesItems.Add("MM/dd/yyyy");
- TimesItems.Add("d/M/yy");
- TimesItems.Add("d/M/yyyy");
- TimesItems.Add("dd/MM/yy");
- TimesItems.Add("dd/MM/yyyy");
- TimesItems.Add("MM/yy");
- TimesItems.Add("MM/yyyy");
- TimesItems.Add("M.d.yy");
- TimesItems.Add("M.d.yyyy");
- TimesItems.Add("MM.dd.yy");
- TimesItems.Add("MM.dd.yyyy");
- TimesItems.Add("MM.yy");
- TimesItems.Add("MM.yyyy");
- TimesItems.Add("d.M.yy");
- TimesItems.Add("d.M.yyyy");
- TimesItems.Add("dd.MM.yy");
- TimesItems.Add("dd.MM.yyyy");
- TimesItems.Add("yy-MM-dd");
- TimesItems.Add("yyyy-MM-dd");
- return TimesItems;
- }
- }
- }
|