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.
24 #include "wtf/Platform.h"
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"
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());
48 SVGStyledElement
* styledElement
= static_cast<SVGStyledElement
*>(svgElement
);
49 const RenderStyle
* style
= object
->style();
52 const SVGRenderStyle
* svgStyle
= style
->svgStyle();
55 /*// Setup transparency layers before setting up filters!
56 float opacity = style->opacity();
58 paintInfo.context->clip(enclosingIntRect(boundingBox));
59 paintInfo.context->beginTransparencyLayer(opacity);
62 #if ENABLE(SVG_FILTERS)
63 AtomicString
filterId(SVGURIReference::getTarget(svgStyle
->filter()));
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!
82 SVGResourceClipper
* clipper
= getClipperById(document
, clipperId
);
83 //SVGResourceMasker* masker = getMaskerById(document, maskerId);
85 #if ENABLE(SVG_FILTERS)
87 filter
->addClient(styledElement
);
88 filter
->prepareFilter(paintInfo
.context
, boundingBox
);
89 } else if (!filterId
.isEmpty())
90 svgElement
->document()->accessSVGExtensions()->addPendingResource(filterId
, styledElement
);
94 clipper
->addClient(styledElement
);
95 clipper
->applyClip(paintInfo
.p
, boundingBox
);
96 } else if (!clipperId
.isEmpty())
97 svgElement
->document()->accessSVGExtensions()->addPendingResource(clipperId
, styledElement
);
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
)
110 const RenderStyle* style = object->style();
113 #if ENABLE(SVG_FILTERS)
115 filter->applyFilter(paintInfo.context, boundingBox);
116 paintInfo.context = savedContext;
120 float opacity = style->opacity();
122 paintInfo.context->endTransparencyLayer();*/
125 /*void renderSubtreeToImage(ImageBuffer* image, RenderObject* item)
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())
152 RenderView* view = static_cast<RenderView*>(object);
153 if (!view->frameView())
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)