KHTML
SVGPaintServerQt.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 "SVGPaintServer.h" 00027 00028 /*#include "GraphicsContext.h"*/ 00029 #include "SVGRenderStyle.h" 00030 #include "RenderObject.h" 00031 #include "RenderPath.h" 00032 00033 #include <QPainter> 00034 #include <QVector> 00035 00036 namespace WebCore { 00037 00038 void SVGPaintServer::setPenProperties(const RenderObject* object, const RenderStyle* style, QPen& pen) const 00039 { 00040 pen.setWidthF(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0)); 00041 00042 /*if (style->svgStyle()->capStyle() == ButtCap) 00043 pen.setCapStyle(Qt::FlatCap); 00044 else if (style->svgStyle()->capStyle() == RoundCap) 00045 pen.setCapStyle(Qt::RoundCap); 00046 00047 if (style->svgStyle()->joinStyle() == MiterJoin) { 00048 pen.setJoinStyle(Qt::MiterJoin); 00049 pen.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit()); 00050 } else if(style->svgStyle()->joinStyle() == RoundJoin) 00051 pen.setJoinStyle(Qt::RoundJoin);*/ 00052 00053 /*const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style); 00054 double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0); 00055 00056 unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0; 00057 if(dashLength) { 00058 QVector<qreal> pattern; 00059 unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2; 00060 00061 for(unsigned int i = 0; i < count; i++) 00062 pattern.append(dashes[i % dashLength] / (float)pen.widthF()); 00063 00064 pen.setDashPattern(pattern); 00065 00066 Q_UNUSED(dashOffset); 00067 // TODO: dash-offset, does/will qt4 API allow it? (Rob) 00068 }*/ 00069 } 00070 00071 void SVGPaintServer::draw(QPainter* painter, QPainterPath* painterPath, const RenderObject* path, SVGPaintTargetType type) const 00072 { 00073 if (!setup(painter, painterPath, path, type)) 00074 return; 00075 00076 renderPath(painter, painterPath, path, type); 00077 teardown(painter, painterPath, path, type); 00078 } 00079 00080 void SVGPaintServer::teardown(QPainter* painter, QPainterPath* painterPath, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const 00081 { 00082 // no-op 00083 } 00084 00085 void SVGPaintServer::renderPath(QPainter* painter, QPainterPath* painterPath, const RenderObject* path, SVGPaintTargetType type) const 00086 { 00087 RenderStyle* renderStyle = path->style(); 00088 00089 //QPainter* painter(context ? context->platformContext() : 0); 00090 //Q_ASSERT(painter); 00091 00092 //QPainterPath* painterPath(context ? context->currentPath() : 0); 00093 //Q_ASSERT(painterPath); 00094 00095 if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) 00096 painter->fillPath(*painterPath, painter->brush()); 00097 00098 if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) 00099 painter->strokePath(*painterPath, painter->pen()); 00100 } 00101 00102 } // namespace WebCore 00103 00104 #endif 00105 00106 // vim:ts=4