SvgColourServer.cs 1.18 KB
Newer Older
davescriven's avatar
davescriven committed
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Svg
{
    public sealed class SvgColourServer : SvgPaintServer
    {
        public SvgColourServer() : this(Color.Transparent)
        {
        }

        public SvgColourServer(Color colour)
        {
            this._colour = colour;
        }

        private Color _colour;

        public Color Colour
        {
            get { return this._colour; }
            set { this._colour = value; }
        }

        public override Brush GetBrush(SvgGraphicsElement styleOwner, float opacity)
        {
            int alpha = (int)((opacity * (this.Colour.A/255) ) * 255);
            Color colour = Color.FromArgb(alpha, this.Colour);

32
            return new SolidBrush(colour);
davescriven's avatar
davescriven committed
33
34
35
36
37
38
39
40
        }

        public override string ToString()
        {
            Color c = this.Colour;

            // Return the name if it exists
            if (c.IsKnownColor)
41
            {
davescriven's avatar
davescriven committed
42
                return c.Name;
43
            }
davescriven's avatar
davescriven committed
44
45
46
47
48
49

            // Return the hex value
            return String.Format("#{0}", c.ToArgb().ToString("x").Substring(2));
        }
    }
}