Home | History | Annotate | Download | only in svg
      1 /*
      2     Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox (at) kde.org>
      3                   2004, 2005, 2006, 2007 Rob Buis <buis (at) 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 "SVGColor.h"
     24 
     25 #include "CSSParser.h"
     26 #include "RGBColor.h"
     27 #include "SVGException.h"
     28 
     29 namespace WebCore {
     30 
     31 SVGColor::SVGColor()
     32     : m_colorType(SVG_COLORTYPE_UNKNOWN)
     33 {
     34 }
     35 
     36 SVGColor::SVGColor(const String& rgbColor)
     37     : m_colorType(SVG_COLORTYPE_RGBCOLOR)
     38 {
     39     setRGBColor(rgbColor);
     40 }
     41 
     42 SVGColor::SVGColor(SVGColorType colorType)
     43     : m_colorType(colorType)
     44 {
     45 }
     46 
     47 SVGColor::SVGColor(const Color& c)
     48     : m_color(c)
     49     , m_colorType(SVG_COLORTYPE_RGBCOLOR)
     50 {
     51 }
     52 
     53 
     54 SVGColor::~SVGColor()
     55 {
     56 }
     57 
     58 unsigned short SVGColor::colorType() const
     59 {
     60     return m_colorType;
     61 }
     62 
     63 PassRefPtr<RGBColor> SVGColor::rgbColor() const
     64 {
     65     return RGBColor::create(m_color.rgb());
     66 }
     67 
     68 void SVGColor::setRGBColor(const String& rgbColor, ExceptionCode& ec)
     69 {
     70     Color color = SVGColor::colorFromRGBColorString(rgbColor);
     71     if (color.isValid())
     72         m_color = color;
     73     else
     74         ec = SVGException::SVG_INVALID_VALUE_ERR;
     75 }
     76 
     77 Color SVGColor::colorFromRGBColorString(const String& colorString)
     78 {
     79     String s = colorString.stripWhiteSpace();
     80     // hsl, hsla and rgba are not in the SVG spec.
     81     // FIXME: rework css parser so it is more svg aware
     82     if (s.startsWith("hsl") || s.startsWith("rgba"))
     83         return Color();
     84     RGBA32 color;
     85     if (CSSParser::parseColor(color, s))
     86         return color;
     87     return Color();
     88 }
     89 
     90 void SVGColor::setRGBColorICCColor(const String& /* rgbColor */, const String& /* iccColor */, ExceptionCode&)
     91 {
     92     // TODO: implement me!
     93 }
     94 
     95 void SVGColor::setColor(unsigned short colorType, const String& /* rgbColor */ , const String& /* iccColor */, ExceptionCode&)
     96 {
     97     // TODO: implement me!
     98     m_colorType = colorType;
     99 }
    100 
    101 String SVGColor::cssText() const
    102 {
    103     if (m_colorType == SVG_COLORTYPE_RGBCOLOR)
    104         return m_color.name();
    105 
    106     return String();
    107 }
    108 
    109 const Color& SVGColor::color() const
    110 {
    111     return m_color;
    112 }
    113 
    114 }
    115 
    116 // vim:ts=4:noet
    117 #endif // ENABLE(SVG)
    118 
    119