SVGPaintServerRadialGradientQt.cpp [plain text]
#include "config.h"
#if ENABLE(SVG)
#include "SVGPaintServerRadialGradient.h"
#include "GraphicsContext.h"
#include "RenderPath.h"
#include <math.h>
#include <QPainter>
#include <QPainterPath>
#include <QRadialGradient>
namespace WebCore {
QGradient SVGPaintServerRadialGradient::setupGradient(GraphicsContext*& context, const RenderObject* object) const
{
QPainter* painter(context ? context->platformContext() : 0);
Q_ASSERT(painter);
QPainterPath* path(context ? context->currentPath() : 0);
Q_ASSERT(path);
RenderStyle* renderStyle = object->style();
QMatrix mat = painter->matrix();
double cx, fx, cy, fy, r;
if (boundingBoxMode()) {
QRectF bbox = path->boundingRect();
cx = double(bbox.left()) + (double(gradientCenter().x() / 100.0) * double(bbox.width()));
cy = double(bbox.top()) + (double(gradientCenter().y() / 100.0) * double(bbox.height()));
fx = double(bbox.left()) + (double(gradientFocal().x() / 100.0) * double(bbox.width())) - cx;
fy = double(bbox.top()) + (double(gradientFocal().y() / 100.0) * double(bbox.height())) - cy;
r = double(gradientRadius() / 100.0) * (sqrt(pow(bbox.width(), 2) + pow(bbox.height(), 2)));
float width = bbox.width();
float height = bbox.height();
int diff = int(width - height); if (!(diff > -2 && diff < 2)) {
float ratioX = (width / height);
float ratioY = (height / width);
mat.scale((width > height) ? 1 : ratioX, (width > height) ? ratioY : 1);
}
} else {
cx = gradientCenter().x();
cy = gradientCenter().y();
fx = gradientFocal().x();
fy = gradientFocal().y();
fx -= cx;
fy -= cy;
r = gradientRadius();
}
if (sqrt(fx * fx + fy * fy) > r) {
double angle = atan2(fy, fx);
fx = int(cos(angle) * r) - 1;
fy = int(sin(angle) * r) - 1;
}
QRadialGradient gradient(QPointF(cx, cy), gradientRadius(), QPointF(fx + cx, fy + cy));
return gradient;
}
}
#endif