Files
SourceCode/PROMS/Volian.Svg.Library/SvgFontSettings.cs
T

140 lines
4.0 KiB
C#

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");
}
#endregion
#region Inheritance
public SvgFontSettings MyParentsSettings { get; set; } = null;
#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
{
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
}
}