using System; using System.Collections.Generic; using System.Text; using System.Drawing; namespace Volian.Svg.Library { class SvgFontSettings { #region ctor public SvgFontSettings() { ;} public SvgFontSettings(Font myFont) { _FontFamily = myFont.FontFamily.Name; _FontSize = myFont.SizeInPoints.ToString() + "PT"; _SVGFontStyle = ((myFont.Style & FontStyle.Italic) == FontStyle.Italic ? "italic" : "normal"); _FontWeight = ((myFont.Style & FontStyle.Bold) == FontStyle.Bold ? "bold" : "normal"); _TextDecoration = ((myFont.Style & FontStyle.Underline) == FontStyle.Underline ? "underline" : "normal"); } //public SvgFontSettings(string myFontFamily, string myFontSize, string mySvgStyle, string myFontWeight, string myTextDecoration) //{ // _FontFamilyName = myFontFamily; // _FontSize = myFontSize; // _SVGFontStyle = mySvgStyle; // _FontWeight = myFontWeight; // _TextDecoration = myTextDecoration; //} #endregion #region Inheritance private SvgFontSettings _MyParentsSettings = null; public SvgFontSettings MyParentsSettings { get { return _MyParentsSettings; } set { _MyParentsSettings = value; } } #endregion #region Internal Inherited Properties protected string InheritedFontFamily { get { if (_FontFamily != "") return _FontFamily; if (_MyParentsSettings != null) return _MyParentsSettings.InheritedFontFamily; // Default return "Arial"; // Absolute Default } } protected string InheritedFontSize { get { if (_FontSize != "") return _FontSize; // Current Value if (_MyParentsSettings != null) return _MyParentsSettings.InheritedFontSize; // Default return "9PT"; // Absolute Default } } protected string InheritedFontStyle { get { if (_SVGFontStyle != "") return _SVGFontStyle; // Current Value if (_MyParentsSettings != null) return _MyParentsSettings.InheritedFontStyle;// Default return "normal"; // Absolute Default } } protected string InheritedFontWeight { get { if (_FontWeight != "") return _FontWeight;// Current Value if (_MyParentsSettings != null) return _MyParentsSettings.InheritedFontWeight;// Default return "normal"; // Absolute Default } } protected string InheritedTextDecoration { get { if (_TextDecoration != "") return _TextDecoration;// Current Value if (_MyParentsSettings != null) return _MyParentsSettings.InheritedTextDecoration;// Default return "normal"; // Absolute Default } } #endregion #region Scale private float _Scale = 1; internal float Scale { get { return _Scale; } set { _Scale = value; Font = null; } } #endregion #region Inherited Values private Font _Font=null; public Font Font { get { if (_Font == null) { _Font = new Font(InheritedFontFamily, _Scale * SvgMeasurement.StringToPoints(InheritedFontSize), (InheritedFontStyle == "italic" ? FontStyle.Italic : FontStyle.Regular) | (InheritedFontWeight == "bold" ? FontStyle.Bold : FontStyle.Regular) | (InheritedTextDecoration == "underline" ? FontStyle.Underline : FontStyle.Regular) , GraphicsUnit.Point); } return _Font; } set { // This was disposing fonts that are saved in our static dictionary. // caused problems with the step editor display after printing (found with Wolf Creek Chem procedure RW-G02 Step 6.1.17) - jsj 7/14/2017 //if (_Font != null) //{ // Console.WriteLine("font dispose {0}, {1}", _Font, _Font.Style); // //_Font.Dispose(); //} if (value != null) { _FontFamily = value.FontFamily.Name; _FontSize = value.SizeInPoints.ToString() + "PT"; _SVGFontStyle = ((value.Style & FontStyle.Italic) == FontStyle.Italic ? "italic" : "normal"); _FontWeight = ((value.Style & FontStyle.Bold) == FontStyle.Bold ? "bold" : "normal"); _TextDecoration = ((value.Style & FontStyle.Underline) == FontStyle.Underline ? "underline" : "normal"); } _Font = value; } } #endregion #region Public Properties private string _FontFamily = string.Empty; public string FontFamily { get { return _FontFamily; } set { _FontFamily = value; Font = null; } } private string _FontSize = string.Empty; public string FontSize { get { return _FontSize; } set { _FontSize = value; Font = null; } } private string _SVGFontStyle = string.Empty; public string SVGFontStyle { get { return _SVGFontStyle; } set { _SVGFontStyle = value; Font = null; } } private string _FontWeight = string.Empty; public string FontWeight { get { return _FontWeight; } set { _FontWeight = value; Font = null; } } private string _TextDecoration = string.Empty; public string TextDecoration { get { return _TextDecoration; } set { _TextDecoration = value; Font = null; } } #endregion } }