fix logic
[personal-kdelibs.git] / khtml / rendering / SVGRenderSupport.cpp
blobb14684a2914539cd30056c913a8676f1a61611ec
1 /*
2 * Copyright (C) 2007 Rob Buis <buis@kde.org>
3 * (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * (C) 2007 Eric Seidel <eric@webkit.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #include "config.h"
24 #include "wtf/Platform.h"
26 #if ENABLE(SVG)
27 #include "SVGRenderSupport.h"
29 #include "AffineTransform.h"
30 /*#include "ImageBuffer.h"*/
31 #include "RenderObject.h"
32 #include "RenderSVGContainer.h"
33 /*#include "RenderView.h"*/
34 #include "SVGResourceClipper.h"
35 /*#include "SVGResourceFilter.h"
36 #include "SVGResourceMasker.h"*/
37 #include "SVGStyledElement.h"
38 #include "SVGURIReference.h"
40 namespace WebCore {
42 void prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, SVGResourceFilter* rootFilter)
44 SVGElement* svgElement = static_cast<SVGElement*>(object->element());
45 ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
46 ASSERT(object);
48 SVGStyledElement* styledElement = static_cast<SVGStyledElement*>(svgElement);
49 const RenderStyle* style = object->style();
50 ASSERT(style);
52 const SVGRenderStyle* svgStyle = style->svgStyle();
53 ASSERT(svgStyle);
55 /*// Setup transparency layers before setting up filters!
56 float opacity = style->opacity();
57 if (opacity < 1.0f) {
58 paintInfo.context->clip(enclosingIntRect(boundingBox));
59 paintInfo.context->beginTransparencyLayer(opacity);
60 }*/
62 #if ENABLE(SVG_FILTERS)
63 AtomicString filterId(SVGURIReference::getTarget(svgStyle->filter()));
64 #endif
66 AtomicString clipperId(SVGURIReference::getTarget(svgStyle->clipPath()));
67 //AtomicString maskerId(SVGURIReference::getTarget(svgStyle->maskElement()));
69 Document* document = object->document();
71 #if ENABLE(SVG_FILTERS)
72 SVGResourceFilter* newFilter = getFilterById(document, filterId);
73 if (newFilter == rootFilter) {
74 // Catch <text filter="url(#foo)">Test<tspan filter="url(#foo)">123</tspan></text>.
75 // The filter is NOT meant to be applied twice in that case!
76 filter = 0;
77 filterId = String();
78 } else
79 filter = newFilter;
80 #endif
82 SVGResourceClipper* clipper = getClipperById(document, clipperId);
83 //SVGResourceMasker* masker = getMaskerById(document, maskerId);
85 #if ENABLE(SVG_FILTERS)
86 if (filter) {
87 filter->addClient(styledElement);
88 filter->prepareFilter(paintInfo.context, boundingBox);
89 } else if (!filterId.isEmpty())
90 svgElement->document()->accessSVGExtensions()->addPendingResource(filterId, styledElement);
91 #endif
93 if (clipper) {
94 clipper->addClient(styledElement);
95 clipper->applyClip(paintInfo.p, boundingBox);
96 } else if (!clipperId.isEmpty())
97 svgElement->document()->accessSVGExtensions()->addPendingResource(clipperId, styledElement);
99 /*if (masker) {
100 masker->addClient(styledElement);
101 masker->applyMask(paintInfo.context, boundingBox);
102 } else if (!maskerId.isEmpty())
103 svgElement->document()->accessSVGExtensions()->addPendingResource(maskerId, styledElement);*/
106 void finishRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter, GraphicsContext* savedContext)
108 /* ASSERT(object);
110 const RenderStyle* style = object->style();
111 ASSERT(style);
113 #if ENABLE(SVG_FILTERS)
114 if (filter) {
115 filter->applyFilter(paintInfo.context, boundingBox);
116 paintInfo.context = savedContext;
118 #endif
120 float opacity = style->opacity();
121 if (opacity < 1.0f)
122 paintInfo.context->endTransparencyLayer();*/
125 /*void renderSubtreeToImage(ImageBuffer* image, RenderObject* item)
127 ASSERT(item);
128 ASSERT(image);
129 ASSERT(image->context());
130 RenderObject::PaintInfo info(image->context(), IntRect(), PaintPhaseForeground, 0, 0, 0);
132 RenderSVGContainer* svgContainer = 0;
133 if (item && item->isSVGContainer())
134 svgContainer = static_cast<RenderSVGContainer*>(item);
136 bool drawsContents = svgContainer ? svgContainer->drawsContents() : false;
137 if (svgContainer && !drawsContents)
138 svgContainer->setDrawsContents(true);
140 item->layoutIfNeeded();
141 item->paint(info, 0, 0);
143 if (svgContainer && !drawsContents)
144 svgContainer->setDrawsContents(false);
147 void clampImageBufferSizeToViewport(RenderObject* object, IntSize& size)
149 if (!object || !object->isRenderView())
150 return;
152 RenderView* view = static_cast<RenderView*>(object);
153 if (!view->frameView())
154 return;
156 int viewWidth = view->frameView()->visibleWidth();
157 int viewHeight = view->frameView()->visibleHeight();
159 if (size.width() > viewWidth)
160 size.setWidth(viewWidth);
162 if (size.height() > viewHeight)
163 size.setHeight(viewHeight);
166 } // namespace WebCore
168 #endif // ENABLE(SVG)