1 | // <developer>niklas@protocol7.com</developer>
|
---|
2 | // <completed>100</completed>
|
---|
3 |
|
---|
4 | using System;
|
---|
5 |
|
---|
6 | using SharpVectors.Dom.Css;
|
---|
7 |
|
---|
8 | namespace SharpVectors.Dom.Svg
|
---|
9 | {
|
---|
10 | /// <summary>
|
---|
11 | /// Summary description for SvgColor.
|
---|
12 | /// </summary>
|
---|
13 | public class SvgColor : CssValue, ISvgColor
|
---|
14 | {
|
---|
15 | #region Private Level Fields
|
---|
16 |
|
---|
17 | protected CssColor _rgbColor;
|
---|
18 | private SvgColorType _colorType;
|
---|
19 |
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | #region Constructors and Destructor
|
---|
23 |
|
---|
24 | protected SvgColor()
|
---|
25 | : base(CssValueType.PrimitiveValue, String.Empty, false)
|
---|
26 | {
|
---|
27 | }
|
---|
28 |
|
---|
29 | public SvgColor(string str)
|
---|
30 | : base(CssValueType.PrimitiveValue, str, false)
|
---|
31 | {
|
---|
32 | ParseColor(str);
|
---|
33 | }
|
---|
34 |
|
---|
35 | #endregion
|
---|
36 |
|
---|
37 | #region Public Properties
|
---|
38 |
|
---|
39 | public override string CssText
|
---|
40 | {
|
---|
41 | get
|
---|
42 | {
|
---|
43 | string ret;
|
---|
44 | switch (ColorType)
|
---|
45 | {
|
---|
46 | case SvgColorType.RgbColor:
|
---|
47 | ret = _rgbColor.CssText;
|
---|
48 | break;
|
---|
49 | case SvgColorType.RgbColorIccColor:
|
---|
50 | ret = _rgbColor.CssText;
|
---|
51 | break;
|
---|
52 | case SvgColorType.CurrentColor:
|
---|
53 | ret = "currentColor";
|
---|
54 | break;
|
---|
55 | default:
|
---|
56 | ret = String.Empty;
|
---|
57 | break;
|
---|
58 | }
|
---|
59 | return ret;
|
---|
60 | }
|
---|
61 | set
|
---|
62 | {
|
---|
63 | base.CssText = value;
|
---|
64 | ParseColor(value);
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | public SvgColorType ColorType
|
---|
69 | {
|
---|
70 | get
|
---|
71 | {
|
---|
72 | return _colorType;
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public ICssColor RgbColor
|
---|
77 | {
|
---|
78 | get
|
---|
79 | {
|
---|
80 | return _rgbColor;
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | public ISvgIccColor IccColor
|
---|
85 | {
|
---|
86 | get
|
---|
87 | {
|
---|
88 | throw new NotImplementedException();
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | #endregion
|
---|
93 |
|
---|
94 | #region Public Methods
|
---|
95 |
|
---|
96 | public void SetRgbColor(string rgbColor)
|
---|
97 | {
|
---|
98 | SetColor(SvgColorType.RgbColor, rgbColor, String.Empty);
|
---|
99 | }
|
---|
100 |
|
---|
101 | public void SetRgbColorIccColor (string rgbColor, string iccColor )
|
---|
102 | {
|
---|
103 | SetColor(SvgColorType.RgbColorIccColor, rgbColor, iccColor);
|
---|
104 | }
|
---|
105 |
|
---|
106 | public void SetColor (SvgColorType colorType, string rgbColor, string iccColor )
|
---|
107 | {
|
---|
108 | _colorType = colorType;
|
---|
109 | if (rgbColor != null && rgbColor.Length > 0)
|
---|
110 | {
|
---|
111 | try
|
---|
112 | {
|
---|
113 | _rgbColor = new CssColor(rgbColor);
|
---|
114 | }
|
---|
115 | catch (DomException domExc)
|
---|
116 | {
|
---|
117 | throw new SvgException(SvgExceptionType.SvgInvalidValueErr,
|
---|
118 | "Invalid color value: " + rgbColor, domExc);
|
---|
119 | }
|
---|
120 | }
|
---|
121 | else
|
---|
122 | {
|
---|
123 | _rgbColor = new CssColor("black");
|
---|
124 | }
|
---|
125 |
|
---|
126 | //TODO--PAUL: deal with ICC colors
|
---|
127 | }
|
---|
128 |
|
---|
129 | #endregion
|
---|
130 |
|
---|
131 | #region Protected Methods
|
---|
132 |
|
---|
133 | protected void ParseColor(string str)
|
---|
134 | {
|
---|
135 | str = str.Trim();
|
---|
136 | if (str.Equals("currentColor"))
|
---|
137 | {
|
---|
138 | SetColor(SvgColorType.CurrentColor, null, null);
|
---|
139 | }
|
---|
140 | else if (str.IndexOf("icc-color(") > -1)
|
---|
141 | {
|
---|
142 | int iccStart = str.IndexOf("icc-color(");
|
---|
143 | string strRgb = str.Substring(0, iccStart).Trim();
|
---|
144 | string strIcc = str.Substring(iccStart);
|
---|
145 |
|
---|
146 | SetColor(SvgColorType.RgbColorIccColor, strRgb, strIcc);
|
---|
147 | }
|
---|
148 | else
|
---|
149 | {
|
---|
150 | SetColor(SvgColorType.RgbColor, str, String.Empty);
|
---|
151 | }
|
---|
152 | }
|
---|
153 |
|
---|
154 | #endregion
|
---|
155 | }
|
---|
156 | }
|
---|