aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/Font.cs
blob: 9b4285a476cf817f633e15dda7121d6b252363e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using Cairo;

namespace go
{
	public enum FontStyle
	{
		Normal,
		Bold,
		Italic,
		Underlined
	}
	public class Font
	{
		#region CTOR
		public Font ()
		{
		}
		#endregion

		string _name = "droid";
		int _size = 12;
		FontStyle _style = FontStyle.Normal;

		public string Name {
			get { return _name; }
			set { _name = value; }
		}
		public int Size {
			get { return _size; }
			set { _size = value; }
		}
		public FontStyle Style {
			get { return _style; }
			set { _style = value; }
		}

		public FontSlant Slant {
			get{ 
				switch (Style) {
				case FontStyle.Normal:
				default:
					return FontSlant.Normal;
				case FontStyle.Italic:
					return FontSlant.Italic;
				}			
			}
		}
		public FontWeight Wheight {
			get{ 
				switch (Style) {
				case FontStyle.Bold:
					return FontWeight.Bold;
				case FontStyle.Italic:
				case FontStyle.Normal:
				default:
					return FontWeight.Normal;
				}			
			}
		}

		#region Operators
		public static implicit operator string(Font c)
		{
			return c.ToString();
		}
		public static implicit operator Font(string s)
		{
			Font f = new Font ();

			if (!string.IsNullOrEmpty (s)) {
				string[] c = s.TrimStart().TrimEnd().Split (new char[] { ',' });

				if (c.Length == 2)
					f.Size = int.Parse (c [1].TrimStart());

				string[] n = c [0].TrimEnd().Split (new char[] { ' ' });

				f.Name = n [0];

				if (n.Length > 1)
					f.Style = (FontStyle)Enum.Parse (typeof(FontStyle), n[n.Length-1], true);
			}

			return f;
		}
		#endregion

		public override string ToString()
		{
			if (_style == FontStyle.Normal)
				return string.Format("{0},{1}", _name, _size);
			else
				return string.Format("{0} {1},{2}", _name, _style, _size);

		}

		public static object Parse(string s)
		{
			return (Font)s;
		}
	}
}