KHTML
SVGPaintServerGradientQt.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> 00003 00004 This file is part of the KDE project 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 aint with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "config.h" 00023 #include "wtf/Platform.h" 00024 00025 #if ENABLE(SVG) 00026 #include "SVGPaintServerGradient.h" 00027 00028 /*#include "GraphicsContext.h"*/ 00029 #include "RenderObject.h" 00030 #include "RenderStyle.h" 00031 #include "SVGGradientElement.h" 00032 00033 #include <QPainter> 00034 #include <QPainterPath> 00035 #include <QColor> 00036 #include <QGradient> 00037 00038 namespace WebCore { 00039 00040 // Helper function used by linear & radial gradient 00041 void SVGPaintServerGradient::fillColorArray(QGradient& gradient, const Vector<SVGGradientStop>& stops, 00042 float opacity) const 00043 { 00044 kDebug() << stops.size() << endl; 00045 for (unsigned i = 0; i < stops.size(); ++i) { 00046 float offset = stops[i].first; 00047 QColor color = stops[i].second; 00048 kDebug() << "offset" << offset << "color" << color << endl; 00049 00050 QColor c(color.red(), color.green(), color.blue()); 00051 c.setAlpha(int(color.alpha() * opacity)); 00052 00053 gradient.setColorAt(offset, c); 00054 } 00055 } 00056 00057 bool SVGPaintServerGradient::setup(QPainter* painter, QPainterPath* painterPath, const RenderObject* object, 00058 SVGPaintTargetType type, bool isPaintingText) const 00059 { 00060 Q_UNUSED(isPaintingText); 00061 kDebug() << "!!!!!!!" << endl; 00062 m_ownerElement->buildGradient(); 00063 00064 /*QPainter* painter(context ? context->platformContext() : 0); 00065 Q_ASSERT(painter);*/ 00066 00067 /*QPainterPath* path(context ? context->currentPath() : 0); 00068 Q_ASSERT(path);*/ 00069 00070 RenderStyle* renderStyle = object->style(); 00071 00072 QGradient gradient = setupGradient(painter, painterPath, object); 00073 00074 painter->setPen(Qt::NoPen); 00075 painter->setBrush(Qt::NoBrush); 00076 00077 if (spreadMethod() == SPREADMETHOD_REPEAT) 00078 gradient.setSpread(QGradient::RepeatSpread); 00079 else if (spreadMethod() == SPREADMETHOD_REFLECT) 00080 gradient.setSpread(QGradient::ReflectSpread); 00081 else 00082 gradient.setSpread(QGradient::PadSpread); 00083 double opacity = 1.0; 00084 00085 kDebug() << "type: " << type << (type & ApplyToFillTargetType) << endl; 00086 if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) { 00087 fillColorArray(gradient, gradientStops(), opacity); 00088 00089 QBrush brush(gradient); 00090 brush.setMatrix(gradientTransform()); 00091 00092 painter->setBrush(brush); 00093 /* FIXME khtml context->setFillRule(renderStyle->svgStyle()->fillRule());*/ 00094 } 00095 00096 if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) { 00097 fillColorArray(gradient, gradientStops(), opacity); 00098 00099 QPen pen; 00100 QBrush brush(gradient); 00101 brush.setMatrix(gradientTransform()); 00102 00103 setPenProperties(object, renderStyle, pen); 00104 pen.setBrush(brush); 00105 00106 painter->setPen(pen); 00107 } 00108 00109 return true; 00110 } 00111 00112 } // namespace WebCore 00113 00114 #endif 00115 00116 // vim:ts=4
KDE 4.6 API Reference