1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 |
|
---|
4 | using SharpVectors.Dom.Svg;
|
---|
5 | using SharpVectors.Dom.Css;
|
---|
6 |
|
---|
7 | namespace SharpVectors.Renderers.Gdi
|
---|
8 | {
|
---|
9 | public sealed class GdiSvgColor : SvgColor
|
---|
10 | {
|
---|
11 | private string _propertyName;
|
---|
12 | private SvgStyleableElement _element;
|
---|
13 |
|
---|
14 | public GdiSvgColor(SvgStyleableElement elm, string propertyName)
|
---|
15 | : base(elm.GetComputedStyle("").GetPropertyValue(propertyName))
|
---|
16 | {
|
---|
17 | _element = elm;
|
---|
18 | _propertyName = propertyName;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public Color Color
|
---|
22 | {
|
---|
23 | get
|
---|
24 | {
|
---|
25 | SvgColor colorToUse;
|
---|
26 | if (ColorType == SvgColorType.CurrentColor)
|
---|
27 | {
|
---|
28 | string sCurColor = _element.GetComputedStyle("").GetPropertyValue("color");
|
---|
29 | colorToUse = new SvgColor(sCurColor);
|
---|
30 | }
|
---|
31 | else if (ColorType == SvgColorType.Unknown)
|
---|
32 | {
|
---|
33 | colorToUse = new SvgColor("black");
|
---|
34 | }
|
---|
35 | else
|
---|
36 | {
|
---|
37 | colorToUse = this;
|
---|
38 | }
|
---|
39 |
|
---|
40 | ICssColor rgbColor = colorToUse.RgbColor;
|
---|
41 | int red = Convert.ToInt32(rgbColor.Red.GetFloatValue(CssPrimitiveType.Number));
|
---|
42 | int green = Convert.ToInt32(rgbColor.Green.GetFloatValue(CssPrimitiveType.Number));
|
---|
43 | int blue = Convert.ToInt32(rgbColor.Blue.GetFloatValue(CssPrimitiveType.Number));
|
---|
44 |
|
---|
45 | return Color.FromArgb(this.Opacity, red, green, blue);
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | public int Opacity
|
---|
50 | {
|
---|
51 | get
|
---|
52 | {
|
---|
53 | string propName;
|
---|
54 | if (_propertyName.Equals("stop-color"))
|
---|
55 | {
|
---|
56 | propName = "stop-opacity";
|
---|
57 | }
|
---|
58 | else if (_propertyName.Equals("flood-color"))
|
---|
59 | {
|
---|
60 | propName = "flood-opacity";
|
---|
61 | }
|
---|
62 | else
|
---|
63 | {
|
---|
64 | return 255;
|
---|
65 | }
|
---|
66 |
|
---|
67 | double alpha = 255;
|
---|
68 | string opacity;
|
---|
69 |
|
---|
70 | opacity = _element.GetPropertyValue(propName);
|
---|
71 | if (opacity.Length > 0)
|
---|
72 | alpha *= SvgNumber.ParseNumber(opacity);
|
---|
73 |
|
---|
74 | alpha = Math.Min(alpha, 255);
|
---|
75 | alpha = Math.Max(alpha, 0);
|
---|
76 |
|
---|
77 | return Convert.ToInt32(alpha);
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|