• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
3                   2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 
5     This file is part of the KDE project
6 
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Library General Public
9     License as published by the Free Software Foundation; either
10     version 2 of the License, or (at your option) any later version.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Library General Public License for more details.
16 
17     You should have received a copy of the GNU Library General Public License
18     along with this library; see the file COPYING.LIB.  If not, write to
19     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20     Boston, MA 02110-1301, USA.
21 */
22 
23 #include "config.h"
24 #if ENABLE(SVG)
25 #include "SVGColor.h"
26 
27 #include "CSSParser.h"
28 #include "RGBColor.h"
29 #include "SVGException.h"
30 
31 namespace WebCore {
32 
SVGColor()33 SVGColor::SVGColor()
34     : m_colorType(SVG_COLORTYPE_UNKNOWN)
35 {
36 }
37 
SVGColor(const String & rgbColor)38 SVGColor::SVGColor(const String& rgbColor)
39     : m_colorType(SVG_COLORTYPE_RGBCOLOR)
40 {
41     setRGBColor(rgbColor);
42 }
43 
SVGColor(SVGColorType colorType)44 SVGColor::SVGColor(SVGColorType colorType)
45     : m_colorType(colorType)
46 {
47 }
48 
SVGColor(const Color & c)49 SVGColor::SVGColor(const Color& c)
50     : m_color(c)
51     , m_colorType(SVG_COLORTYPE_RGBCOLOR)
52 {
53 }
54 
55 
~SVGColor()56 SVGColor::~SVGColor()
57 {
58 }
59 
colorType() const60 unsigned short SVGColor::colorType() const
61 {
62     return m_colorType;
63 }
64 
rgbColor() const65 RGBColor* SVGColor::rgbColor() const
66 {
67     return RGBColor::create(m_color.rgb()).releaseRef();
68 }
69 
setRGBColor(const String & rgbColor,ExceptionCode & ec)70 void SVGColor::setRGBColor(const String& rgbColor, ExceptionCode& ec)
71 {
72     Color color = SVGColor::colorFromRGBColorString(rgbColor);
73     if (color.isValid())
74         m_color = color;
75     else
76         ec = SVGException::SVG_INVALID_VALUE_ERR;
77 }
78 
colorFromRGBColorString(const String & colorString)79 Color SVGColor::colorFromRGBColorString(const String& colorString)
80 {
81     String s = colorString.stripWhiteSpace();
82     // hsl, hsla and rgba are not in the SVG spec.
83     // FIXME: rework css parser so it is more svg aware
84     if (s.startsWith("hsl") || s.startsWith("rgba"))
85         return Color();
86     RGBA32 color;
87     if (CSSParser::parseColor(color, s))
88         return color;
89     return Color();
90 }
91 
setRGBColorICCColor(const String &,const String &,ExceptionCode &)92 void SVGColor::setRGBColorICCColor(const String& /* rgbColor */, const String& /* iccColor */, ExceptionCode&)
93 {
94     // TODO: implement me!
95 }
96 
setColor(unsigned short colorType,const String &,const String &,ExceptionCode &)97 void SVGColor::setColor(unsigned short colorType, const String& /* rgbColor */ , const String& /* iccColor */, ExceptionCode&)
98 {
99     // TODO: implement me!
100     m_colorType = colorType;
101 }
102 
cssText() const103 String SVGColor::cssText() const
104 {
105     if (m_colorType == SVG_COLORTYPE_RGBCOLOR)
106         return m_color.name();
107 
108     return String();
109 }
110 
color() const111 const Color& SVGColor::color() const
112 {
113     return m_color;
114 }
115 
116 }
117 
118 // vim:ts=4:noet
119 #endif // ENABLE(SVG)
120 
121