1 /*
2 Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22 #if ENABLE(SVG)
23 #include "SVGPaint.h"
24
25 namespace WebCore {
26
SVGPaint()27 SVGPaint::SVGPaint()
28 : m_paintType(SVG_PAINTTYPE_UNKNOWN)
29 {
30 }
31
SVGPaint(const String & uri)32 SVGPaint::SVGPaint(const String& uri)
33 : m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR)
34 {
35 setUri(uri);
36 }
37
SVGPaint(SVGPaintType paintType)38 SVGPaint::SVGPaint(SVGPaintType paintType)
39 : m_paintType(paintType)
40 {
41 }
42
SVGPaint(SVGPaintType paintType,const String & uri,const String & rgbPaint,const String &)43 SVGPaint::SVGPaint(SVGPaintType paintType, const String& uri, const String& rgbPaint, const String&)
44 : SVGColor(rgbPaint)
45 , m_paintType(paintType)
46 {
47 setUri(uri);
48 }
49
SVGPaint(const Color & c)50 SVGPaint::SVGPaint(const Color& c)
51 : SVGColor(c)
52 , m_paintType(SVG_PAINTTYPE_RGBCOLOR)
53 {
54 }
55
SVGPaint(const String & uri,const Color & c)56 SVGPaint::SVGPaint(const String& uri, const Color& c)
57 : SVGColor(c)
58 , m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR)
59 {
60 setUri(uri);
61 }
62
~SVGPaint()63 SVGPaint::~SVGPaint()
64 {
65 }
66
defaultFill()67 SVGPaint* SVGPaint::defaultFill()
68 {
69 static SVGPaint* _defaultFill = new SVGPaint(Color::black);
70 return _defaultFill;
71 }
72
defaultStroke()73 SVGPaint* SVGPaint::defaultStroke()
74 {
75 static SVGPaint* _defaultStroke = new SVGPaint(SVG_PAINTTYPE_NONE);
76 return _defaultStroke;
77 }
78
uri() const79 String SVGPaint::uri() const
80 {
81 return m_uri;
82 }
83
setUri(const String & uri)84 void SVGPaint::setUri(const String& uri)
85 {
86 m_uri = uri;
87 }
88
setPaint(SVGPaintType paintType,const String & uri,const String & rgbPaint,const String &,ExceptionCode &)89 void SVGPaint::setPaint(SVGPaintType paintType, const String& uri, const String& rgbPaint, const String&, ExceptionCode&)
90 {
91 m_paintType = paintType;
92
93 if (m_paintType == SVG_PAINTTYPE_URI)
94 setUri(uri);
95 else if (m_paintType == SVG_PAINTTYPE_RGBCOLOR)
96 setRGBColor(rgbPaint);
97 }
98
cssText() const99 String SVGPaint::cssText() const
100 {
101 if (m_paintType == SVG_PAINTTYPE_NONE)
102 return "none";
103 else if (m_paintType == SVG_PAINTTYPE_CURRENTCOLOR)
104 return "currentColor";
105 else if (m_paintType == SVG_PAINTTYPE_URI)
106 return "url(" + m_uri + ")";
107
108 return SVGColor::cssText();
109 }
110
111 }
112
113 // vim:ts=4:noet
114 #endif // ENABLE(SVG)
115
116