KHTML
SVGPaintServerRadialGradientQt.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 "SVGPaintServerRadialGradient.h"
00027
00028
00029 #include "RenderPath.h"
00030
00031 #include <math.h>
00032 #include <QPainter>
00033 #include <QPainterPath>
00034 #include <QRadialGradient>
00035
00036 namespace WebCore {
00037
00038 QGradient SVGPaintServerRadialGradient::setupGradient(QPainter* painter, QPainterPath* painterPath, const RenderObject* object) const
00039 {
00040
00041
00042
00043
00044
00045 QPainterPath* path(painterPath);
00046
00047 RenderStyle* renderStyle = object->style();
00048
00049 QMatrix mat = painter->matrix();
00050
00051 double cx, fx, cy, fy, r;
00052 if (boundingBoxMode()) {
00053 QRectF bbox = path->boundingRect();
00054 cx = double(bbox.left()) + (double(gradientCenter().x() / 100.0) * double(bbox.width()));
00055 cy = double(bbox.top()) + (double(gradientCenter().y() / 100.0) * double(bbox.height()));
00056 fx = double(bbox.left()) + (double(gradientFocal().x() / 100.0) * double(bbox.width())) - cx;
00057 fy = double(bbox.top()) + (double(gradientFocal().y() / 100.0) * double(bbox.height())) - cy;
00058 r = double(gradientRadius() / 100.0) * (sqrt(pow(bbox.width(), 2) + pow(bbox.height(), 2)));
00059
00060 float width = bbox.width();
00061 float height = bbox.height();
00062
00063 int diff = int(width - height);
00064 if (!(diff > -2 && diff < 2)) {
00065
00066 float ratioX = (width / height);
00067 float ratioY = (height / width);
00068 mat.scale((width > height) ? 1 : ratioX, (width > height) ? ratioY : 1);
00069 }
00070 } else {
00071 cx = gradientCenter().x();
00072 cy = gradientCenter().y();
00073
00074 fx = gradientFocal().x();
00075 fy = gradientFocal().y();
00076
00077 fx -= cx;
00078 fy -= cy;
00079
00080 r = gradientRadius();
00081 }
00082
00083 if (sqrt(fx * fx + fy * fy) > r) {
00084
00085
00086 double angle = atan2(fy, fx);
00087 fx = int(cos(angle) * r) - 1;
00088 fy = int(sin(angle) * r) - 1;
00089 }
00090
00091 kDebug() << "cx:" << cx << "cy:" << cy << "radius:" << gradientRadius() << "fx:" << fx + cx << "fy:" << fy + cy << endl;
00092 QRadialGradient gradient(QPointF(cx, cy), gradientRadius(), QPointF(fx + cx, fy + cy));
00093
00094 return gradient;
00095 }
00096
00097 }
00098
00099 #endif
00100
00101