File indexing completed on 2024-04-28 15:22:41
0001 /* 0002 Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org> 0003 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 0004 (C) 2009 Maksim Orlovich <maksim@kde.org> 0005 0006 This file is part of the KDE project 0007 0008 This library is free software; you can redistribute it and/or 0009 modify it under the terms of the GNU Library General Public 0010 License as published by the Free Software Foundation; either 0011 version 2 of the License, or (at your option) any later version. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Library General Public License for more details. 0017 0018 You should have received a copy of the GNU Library General Public License 0019 along with this library; see the file COPYING.LIB. If not, write to 0020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0021 Boston, MA 02110-1301, USA. 0022 */ 0023 0024 #include "css/css_svgvalueimpl.h" 0025 #include "svg/SVGException.h" 0026 0027 namespace DOM 0028 { 0029 0030 SVGColorImpl::SVGColorImpl() 0031 : m_colorType(SVG_COLORTYPE_UNKNOWN) 0032 { 0033 } 0034 0035 SVGColorImpl::SVGColorImpl(const DOMString &rgbColor) 0036 : m_colorType(SVG_COLORTYPE_RGBCOLOR) 0037 { 0038 setRGBColor(rgbColor); 0039 } 0040 0041 SVGColorImpl::SVGColorImpl(unsigned short colorType) 0042 : m_colorType(colorType) 0043 {} 0044 0045 SVGColorImpl::SVGColorImpl(const QColor &c) 0046 : m_color(c) 0047 , m_colorType(SVG_COLORTYPE_RGBCOLOR) 0048 {} 0049 0050 SVGColorImpl::~SVGColorImpl() 0051 {} 0052 0053 unsigned short SVGColorImpl::colorType() const 0054 { 0055 return m_colorType; 0056 } 0057 0058 unsigned SVGColorImpl::rgbColor() const 0059 { 0060 return m_color.rgb(); 0061 } 0062 0063 void SVGColorImpl::setRGBColor(const DOMString &rgbColor, int &ec) 0064 { 0065 QColor color = SVGColorImpl::colorFromRGBColorString(rgbColor); 0066 if (color.isValid()) { 0067 m_color = color; 0068 } else { 0069 ec = SVGException::SVG_INVALID_VALUE_ERR; 0070 } 0071 } 0072 0073 QColor SVGColorImpl::colorFromRGBColorString(const DOMString &colorDOMString) 0074 { 0075 0076 // ### this used to disallow hsl, etc, but I think CSS3 color ought to win.. 0077 // ### FIXME, same as canvas... where should the helper go. 0078 0079 /*DOMString s = colorDOMString.stripWhiteSpace(); 0080 // hsl, hsla and rgba are not in the SVG spec. 0081 // FIXME: rework css parser so it is more svg aware 0082 if (s.startsWith("hsl") || s.startsWith("rgba")) 0083 return Color(); 0084 RGBA32 color; 0085 if (CSSParser::parseColor(color, s)) 0086 return color; 0087 return Color();*/ 0088 return QColor(colorDOMString.string()); 0089 } 0090 0091 void SVGColorImpl::setRGBColorICCColor(const DOMString & /* rgbColor */, const DOMString & /* iccColor */, int & /* ec */) 0092 { 0093 // ### TODO: implement me! 0094 } 0095 0096 void SVGColorImpl::setColor(unsigned short colorType, const DOMString & /* rgbColor */, const DOMString & /* iccColor */, int & /*ec*/) 0097 { 0098 // ### TODO: implement me! 0099 m_colorType = colorType; 0100 } 0101 0102 DOMString SVGColorImpl::cssText() const 0103 { 0104 if (m_colorType == SVG_COLORTYPE_RGBCOLOR) { 0105 return m_color.name(); 0106 } 0107 0108 // ### FIXME: other types? 0109 0110 return DOMString(); 0111 } 0112 0113 const QColor &SVGColorImpl::color() const 0114 { 0115 return m_color; 0116 } 0117 0118 SVGPaintImpl::SVGPaintImpl() 0119 : SVGColorImpl() 0120 , m_paintType(SVG_PAINTTYPE_UNKNOWN) 0121 { 0122 } 0123 0124 SVGPaintImpl::SVGPaintImpl(const DOMString &uri) 0125 : SVGColorImpl() 0126 , m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR) 0127 { 0128 setUri(uri); 0129 } 0130 0131 SVGPaintImpl::SVGPaintImpl(SVGPaintType paintType) 0132 : SVGColorImpl() 0133 , m_paintType(paintType) 0134 { 0135 } 0136 0137 SVGPaintImpl::SVGPaintImpl(SVGPaintType paintType, const DOMString &uri, const DOMString &rgbPaint, const DOMString &) 0138 : SVGColorImpl(rgbPaint) 0139 , m_paintType(paintType) 0140 { 0141 setUri(uri); 0142 } 0143 0144 SVGPaintImpl::SVGPaintImpl(const QColor &c) 0145 : SVGColorImpl(c) 0146 , m_paintType(SVG_PAINTTYPE_RGBCOLOR) 0147 { 0148 } 0149 0150 SVGPaintImpl::SVGPaintImpl(const DOMString &uri, const QColor &c) 0151 : SVGColorImpl(c) 0152 , m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR) 0153 { 0154 setUri(uri); 0155 } 0156 0157 SVGPaintImpl::~SVGPaintImpl() 0158 { 0159 } 0160 0161 SVGPaintImpl *SVGPaintImpl::defaultFill() 0162 { 0163 static SVGPaintImpl *_defaultFill = new SVGPaintImpl(Qt::black); 0164 return _defaultFill; 0165 } 0166 0167 SVGPaintImpl *SVGPaintImpl::defaultStroke() 0168 { 0169 static SVGPaintImpl *_defaultStroke = new SVGPaintImpl(SVG_PAINTTYPE_NONE); 0170 return _defaultStroke; 0171 } 0172 0173 DOMString SVGPaintImpl::uri() const 0174 { 0175 return m_uri; 0176 } 0177 0178 void SVGPaintImpl::setUri(const DOMString &uri) 0179 { 0180 m_uri = uri; 0181 } 0182 0183 void SVGPaintImpl::setPaint(SVGPaintType paintType, const DOMString &uri, const DOMString &rgbPaint, const DOMString &, int &) 0184 { 0185 m_paintType = paintType; 0186 0187 if (m_paintType == SVG_PAINTTYPE_URI) { 0188 setUri(uri); 0189 } else if (m_paintType == SVG_PAINTTYPE_RGBCOLOR) { 0190 setRGBColor(rgbPaint); 0191 } 0192 } 0193 0194 DOMString SVGPaintImpl::cssText() const 0195 { 0196 if (m_paintType == SVG_PAINTTYPE_NONE) { 0197 return "none"; 0198 } else if (m_paintType == SVG_PAINTTYPE_CURRENTCOLOR) { 0199 return "currentColor"; 0200 } else if (m_paintType == SVG_PAINTTYPE_URI) { 0201 return m_uri; //return "url(" + m_uri + ")"; 0202 } 0203 0204 return SVGColorImpl::cssText(); 0205 } 0206 0207 } 0208