KHTML
RenderPathQt.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org> 00003 2004, 2005, 2006 Rob Buis <buis@kde.org> 00004 2005 Eric Seidel <eric.seidel@kdemail.net> 00005 00006 This file is part of the KDE project 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License as published by the Free Software Foundation; either 00011 version 2 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 aint with this library; see the file COPYING.LIB. If not, write to 00020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #include "config.h" 00025 #include "RenderPath.h" 00026 #include "SVGRenderStyle.h" 00027 #include "SVGPaintServer.h" 00028 00029 #include <QDebug> 00030 #include <QPainterPathStroker> 00031 00032 namespace WebCore { 00033 00034 bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const 00035 { 00036 if (path().isEmpty()) 00037 return false; 00038 00039 if (requiresStroke && !SVGPaintServer::strokePaintServer(style(), this)) 00040 return false; 00041 00042 return false; 00043 } 00044 00045 static QPainterPath getPathStroke(const QPainterPath &path, const RenderObject* object, const RenderStyle* style) 00046 { 00047 QPainterPathStroker s; 00048 s.setWidth(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0)); 00049 00050 if (style->svgStyle()->capStyle() == ButtCap) 00051 s.setCapStyle(Qt::FlatCap); 00052 else if (style->svgStyle()->capStyle() == RoundCap) 00053 s.setCapStyle(Qt::RoundCap); 00054 00055 if (style->svgStyle()->joinStyle() == MiterJoin) { 00056 s.setJoinStyle(Qt::MiterJoin); 00057 s.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit()); 00058 } else if(style->svgStyle()->joinStyle() == RoundJoin) 00059 s.setJoinStyle(Qt::RoundJoin); 00060 00061 const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style); 00062 double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0); 00063 00064 unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0; 00065 if(dashLength) { 00066 QVector<qreal> pattern; 00067 unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2; 00068 00069 for(unsigned int i = 0; i < count; i++) 00070 pattern.append(dashes[i % dashLength] / (float)s.width()); 00071 00072 s.setDashPattern(pattern); 00073 00074 Q_UNUSED(dashOffset); 00075 // TODO: dash-offset, does/will qt4 API allow it? (Rob) 00076 } 00077 00078 return s.createStroke(path); 00079 } 00080 00081 FloatRect RenderPath::strokeBBox() const 00082 { 00083 QPainterPath outline = getPathStroke(*(path().platformPath()), this, style()); 00084 return outline.boundingRect(); 00085 } 00086 00087 } 00088 00089 // vim:ts=4:noet
KDE 4.6 API Reference