• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

SVGPaintServerRadialGradientQt.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 "SVGPaintServerRadialGradient.h"
00027 
00028 /*#include "GraphicsContext.h"*/
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     //QPainter* painter(context ? context->platformContext() : 0);
00041     //Q_ASSERT(painter);
00042 
00043     //QPainterPath* path(context ? context->currentPath() : 0);
00044     //Q_ASSERT(path);
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); // allow slight tolerance
00064         if (!(diff > -2 && diff < 2)) {
00065             // make elliptical or circular depending on bbox aspect ratio
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         // Spec: If (fx, fy) lies outside the circle defined by (cx, cy) and r, set (fx, fy)
00085         // to the point of intersection of the line through (fx, fy) and the circle.
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 } // namespace WebCore
00098 
00099 #endif
00100 
00101 // vim:ts=4:noet

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal