KHTML
SVGPaintServerGradientQt.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include "wtf/Platform.h"
00024
00025 #if ENABLE(SVG)
00026 #include "SVGPaintServerGradient.h"
00027
00028
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
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 Color 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 kDebug() << "!!!!!!!" << endl;
00061 m_ownerElement->buildGradient();
00062
00063
00064
00065
00066
00067
00068
00069 RenderStyle* renderStyle = object->style();
00070
00071 QGradient gradient = setupGradient(painter, painterPath, object);
00072
00073 painter->setPen(Qt::NoPen);
00074 painter->setBrush(Qt::NoBrush);
00075
00076 if (spreadMethod() == SPREADMETHOD_REPEAT)
00077 gradient.setSpread(QGradient::RepeatSpread);
00078 else if (spreadMethod() == SPREADMETHOD_REFLECT)
00079 gradient.setSpread(QGradient::ReflectSpread);
00080 else
00081 gradient.setSpread(QGradient::PadSpread);
00082 double opacity = 1.0;
00083
00084 kDebug() << "type: " << type << (type & ApplyToFillTargetType) << endl;
00085 if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) {
00086 fillColorArray(gradient, gradientStops(), opacity);
00087
00088 QBrush brush(gradient);
00089 brush.setMatrix(gradientTransform());
00090
00091 painter->setBrush(brush);
00092
00093 }
00094
00095 if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) {
00096 fillColorArray(gradient, gradientStops(), opacity);
00097
00098 QPen pen;
00099 QBrush brush(gradient);
00100 brush.setMatrix(gradientTransform());
00101
00102 setPenProperties(object, renderStyle, pen);
00103 pen.setBrush(brush);
00104
00105 painter->setPen(pen);
00106 }
00107
00108 return true;
00109 }
00110
00111 }
00112
00113 #endif
00114
00115