KHtml

css_svgvalueimpl.cpp
1 /*
2  Copyright (C) 2004, 2005 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006, 2007 Rob Buis <[email protected]>
4  (C) 2009 Maksim Orlovich <[email protected]>
5 
6  This file is part of the KDE project
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include "css/css_svgvalueimpl.h"
25 #include "svg/SVGException.h"
26 
27 namespace DOM
28 {
29 
30 SVGColorImpl::SVGColorImpl()
31  : m_colorType(SVG_COLORTYPE_UNKNOWN)
32 {
33 }
34 
35 SVGColorImpl::SVGColorImpl(const DOMString &rgbColor)
36  : m_colorType(SVG_COLORTYPE_RGBCOLOR)
37 {
38  setRGBColor(rgbColor);
39 }
40 
41 SVGColorImpl::SVGColorImpl(unsigned short colorType)
42  : m_colorType(colorType)
43 {}
44 
45 SVGColorImpl::SVGColorImpl(const QColor &c)
46  : m_color(c)
47  , m_colorType(SVG_COLORTYPE_RGBCOLOR)
48 {}
49 
50 SVGColorImpl::~SVGColorImpl()
51 {}
52 
53 unsigned short SVGColorImpl::colorType() const
54 {
55  return m_colorType;
56 }
57 
58 unsigned SVGColorImpl::rgbColor() const
59 {
60  return m_color.rgb();
61 }
62 
63 void SVGColorImpl::setRGBColor(const DOMString &rgbColor, int &ec)
64 {
65  QColor color = SVGColorImpl::colorFromRGBColorString(rgbColor);
66  if (color.isValid()) {
67  m_color = color;
68  } else {
69  ec = SVGException::SVG_INVALID_VALUE_ERR;
70  }
71 }
72 
73 QColor SVGColorImpl::colorFromRGBColorString(const DOMString &colorDOMString)
74 {
75 
76  // ### this used to disallow hsl, etc, but I think CSS3 color ought to win..
77  // ### FIXME, same as canvas... where should the helper go.
78 
79  /*DOMString s = colorDOMString.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  return QColor(colorDOMString.string());
89 }
90 
91 void SVGColorImpl::setRGBColorICCColor(const DOMString & /* rgbColor */, const DOMString & /* iccColor */, int & /* ec */)
92 {
93  // ### TODO: implement me!
94 }
95 
96 void SVGColorImpl::setColor(unsigned short colorType, const DOMString & /* rgbColor */, const DOMString & /* iccColor */, int & /*ec*/)
97 {
98  // ### TODO: implement me!
99  m_colorType = colorType;
100 }
101 
102 DOMString SVGColorImpl::cssText() const
103 {
104  if (m_colorType == SVG_COLORTYPE_RGBCOLOR) {
105  return m_color.name();
106  }
107 
108  // ### FIXME: other types?
109 
110  return DOMString();
111 }
112 
113 const QColor &SVGColorImpl::color() const
114 {
115  return m_color;
116 }
117 
118 SVGPaintImpl::SVGPaintImpl()
119  : SVGColorImpl()
120  , m_paintType(SVG_PAINTTYPE_UNKNOWN)
121 {
122 }
123 
124 SVGPaintImpl::SVGPaintImpl(const DOMString &uri)
125  : SVGColorImpl()
126  , m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR)
127 {
128  setUri(uri);
129 }
130 
131 SVGPaintImpl::SVGPaintImpl(SVGPaintType paintType)
132  : SVGColorImpl()
133  , m_paintType(paintType)
134 {
135 }
136 
137 SVGPaintImpl::SVGPaintImpl(SVGPaintType paintType, const DOMString &uri, const DOMString &rgbPaint, const DOMString &)
138  : SVGColorImpl(rgbPaint)
139  , m_paintType(paintType)
140 {
141  setUri(uri);
142 }
143 
144 SVGPaintImpl::SVGPaintImpl(const QColor &c)
145  : SVGColorImpl(c)
146  , m_paintType(SVG_PAINTTYPE_RGBCOLOR)
147 {
148 }
149 
150 SVGPaintImpl::SVGPaintImpl(const DOMString &uri, const QColor &c)
151  : SVGColorImpl(c)
152  , m_paintType(SVG_PAINTTYPE_URI_RGBCOLOR)
153 {
154  setUri(uri);
155 }
156 
157 SVGPaintImpl::~SVGPaintImpl()
158 {
159 }
160 
161 SVGPaintImpl *SVGPaintImpl::defaultFill()
162 {
163  static SVGPaintImpl *_defaultFill = new SVGPaintImpl(Qt::black);
164  return _defaultFill;
165 }
166 
167 SVGPaintImpl *SVGPaintImpl::defaultStroke()
168 {
169  static SVGPaintImpl *_defaultStroke = new SVGPaintImpl(SVG_PAINTTYPE_NONE);
170  return _defaultStroke;
171 }
172 
173 DOMString SVGPaintImpl::uri() const
174 {
175  return m_uri;
176 }
177 
178 void SVGPaintImpl::setUri(const DOMString &uri)
179 {
180  m_uri = uri;
181 }
182 
183 void SVGPaintImpl::setPaint(SVGPaintType paintType, const DOMString &uri, const DOMString &rgbPaint, const DOMString &, int &)
184 {
185  m_paintType = paintType;
186 
187  if (m_paintType == SVG_PAINTTYPE_URI) {
188  setUri(uri);
189  } else if (m_paintType == SVG_PAINTTYPE_RGBCOLOR) {
190  setRGBColor(rgbPaint);
191  }
192 }
193 
194 DOMString SVGPaintImpl::cssText() const
195 {
196  if (m_paintType == SVG_PAINTTYPE_NONE) {
197  return "none";
198  } else if (m_paintType == SVG_PAINTTYPE_CURRENTCOLOR) {
199  return "currentColor";
200  } else if (m_paintType == SVG_PAINTTYPE_URI) {
201  return m_uri; //return "url(" + m_uri + ")";
202  }
203 
204  return SVGColorImpl::cssText();
205 }
206 
207 }
208 
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
This library provides a full-featured HTML parser and widget.
bool isValid() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:51 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.