// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; namespace Spludlow.Drawing { public class FontInfo { public string Name; public bool UniCode; public float Size; public FontStyle FontStyles; public FontInfo(string fontInfoText) { string[] words = Spludlow.Text.Split(fontInfoText, ',', true, false); if (words.Length < 2) throw new ApplicationException("FontInfo; Must have at least 2 words 'name, size': " + fontInfoText); this.Name = words[0]; this.UniCode = false; if (this.Name.EndsWith("*") == true) { this.Name = this.Name.Substring(0, this.Name.Length - 1); this.UniCode = true; } try { this.Size = Single.Parse(words[1]); } catch (Exception ee) { throw new ApplicationException("FontInfo; Bad Point size: " + words[1], ee); } this.FontStyles = FontStyle.Regular; for (int index = 2; index < words.Length; ++index) { try { FontStyle fontStyle = (FontStyle)Enum.Parse(typeof(FontStyle), words[index]); this.FontStyles |= fontStyle; } catch (Exception ee) { throw new ApplicationException("FontInfo; Bad font style: " + words[index], ee); } } } public string NameWithStyle() { StringBuilder result = new StringBuilder(this.Name); if (this.FontStyles.HasFlag(FontStyle.Bold) == true) result.Append(", Bold"); if (this.FontStyles.HasFlag(FontStyle.Italic) == true) result.Append(", Italic"); return result.ToString(); } public void RemoveBoldItalic() { this.FontStyles &= ~FontStyle.Bold; this.FontStyles &= ~FontStyle.Italic; } } }