File indexing completed on 2024-05-05 12:16:15

0001 /*
0002  * Copyright (C) 2007 Rob Buis <buis@kde.org>
0003  *           (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
0004  *           (C) 2007 Eric Seidel <eric@webkit.org>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  *
0021  */
0022 
0023 #include "wtf/Platform.h"
0024 
0025 #if ENABLE(SVG)
0026 #include "SVGRenderSupport.h"
0027 
0028 #include "AffineTransform.h"
0029 /*#include "ImageBuffer.h"*/
0030 #include "RenderSVGContainer.h"
0031 /*#include "RenderView.h"*/
0032 #include "SVGResourceClipper.h"
0033 /*#include "SVGResourceFilter.h"
0034 #include "SVGResourceMasker.h"*/
0035 #include "SVGStyledElement.h"
0036 #include "SVGURIReference.h"
0037 
0038 namespace WebCore
0039 {
0040 
0041 void prepareToRenderSVGContent(RenderObject *object, RenderObject::PaintInfo &paintInfo, const FloatRect &boundingBox, SVGResourceFilter *&filter, SVGResourceFilter *rootFilter)
0042 {
0043     Q_UNUSED(filter);
0044     Q_UNUSED(rootFilter);
0045     SVGElement *svgElement = static_cast<SVGElement *>(object->element());
0046     ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
0047     ASSERT(object);
0048 
0049     SVGStyledElement *styledElement = static_cast<SVGStyledElement *>(svgElement);
0050     const RenderStyle *style = object->style();
0051     ASSERT(style);
0052 
0053     const SVGRenderStyle *svgStyle = style->svgStyle();
0054     ASSERT(svgStyle);
0055 
0056     /*// Setup transparency layers before setting up filters!
0057     float opacity = style->opacity();
0058     if (opacity < 1.0f) {
0059         paintInfo.context->clip(enclosingIntRect(boundingBox));
0060         paintInfo.context->beginTransparencyLayer(opacity);
0061     }*/
0062 
0063 #if ENABLE(SVG_FILTERS)
0064     AtomicString filterId(SVGURIReference::getTarget(svgStyle->filter()));
0065 #endif
0066 
0067     AtomicString clipperId(SVGURIReference::getTarget(svgStyle->clipPath()));
0068     //AtomicString maskerId(SVGURIReference::getTarget(svgStyle->maskElement()));
0069 
0070     Document *document = object->document();
0071 
0072 #if ENABLE(SVG_FILTERS)
0073     SVGResourceFilter *newFilter = getFilterById(document, filterId);
0074     if (newFilter == rootFilter) {
0075         // Catch <text filter="url(#foo)">Test<tspan filter="url(#foo)">123</tspan></text>.
0076         // The filter is NOT meant to be applied twice in that case!
0077         filter = 0;
0078         filterId = String();
0079     } else {
0080         filter = newFilter;
0081     }
0082 #endif
0083 
0084     SVGResourceClipper *clipper = getClipperById(document, clipperId);
0085     //SVGResourceMasker* masker = getMaskerById(document, maskerId);
0086 
0087 #if ENABLE(SVG_FILTERS)
0088     if (filter) {
0089         filter->addClient(styledElement);
0090         filter->prepareFilter(paintInfo.context, boundingBox);
0091     } else if (!filterId.isEmpty()) {
0092         svgElement->document()->accessSVGExtensions()->addPendingResource(filterId, styledElement);
0093     }
0094 #endif
0095 
0096     if (clipper) {
0097         clipper->addClient(styledElement);
0098         clipper->applyClip(paintInfo.p, boundingBox);
0099     } else if (!clipperId.isEmpty()) {
0100         svgElement->document()->accessSVGExtensions()->addPendingResource(clipperId, styledElement);
0101     }
0102 
0103     /*if (masker) {
0104         masker->addClient(styledElement);
0105         masker->applyMask(paintInfo.context, boundingBox);
0106     } else if (!maskerId.isEmpty())
0107         svgElement->document()->accessSVGExtensions()->addPendingResource(maskerId, styledElement);*/
0108 }
0109 
0110 void finishRenderSVGContent(RenderObject *object, RenderObject::PaintInfo &paintInfo, const FloatRect &boundingBox, SVGResourceFilter *&filter, QPainter *savedContext)
0111 {
0112     Q_UNUSED(object);
0113     Q_UNUSED(paintInfo);
0114     Q_UNUSED(boundingBox);
0115     Q_UNUSED(filter);
0116     Q_UNUSED(savedContext);
0117     /*    ASSERT(object);
0118 
0119         const RenderStyle* style = object->style();
0120         ASSERT(style);
0121 
0122     #if ENABLE(SVG_FILTERS)
0123         if (filter) {
0124             filter->applyFilter(paintInfo.context, boundingBox);
0125             paintInfo.context = savedContext;
0126         }
0127     #endif
0128 
0129         float opacity = style->opacity();
0130         if (opacity < 1.0f)
0131             paintInfo.context->endTransparencyLayer();*/
0132 }
0133 
0134 /*void renderSubtreeToImage(ImageBuffer* image, RenderObject* item)
0135 {
0136     ASSERT(item);
0137     ASSERT(image);
0138     ASSERT(image->context());
0139     RenderObject::PaintInfo info(image->context(), IntRect(), PaintPhaseForeground, 0, 0, 0);
0140 
0141     RenderSVGContainer* svgContainer = 0;
0142     if (item && item->isSVGContainer())
0143         svgContainer = static_cast<RenderSVGContainer*>(item);
0144 
0145     bool drawsContents = svgContainer ? svgContainer->drawsContents() : false;
0146     if (svgContainer && !drawsContents)
0147         svgContainer->setDrawsContents(true);
0148 
0149     item->layoutIfNeeded();
0150     item->paint(info, 0, 0);
0151 
0152     if (svgContainer && !drawsContents)
0153         svgContainer->setDrawsContents(false);
0154 }
0155 
0156 void clampImageBufferSizeToViewport(RenderObject* object, IntSize& size)
0157 {
0158     if (!object || !object->isRenderView())
0159         return;
0160 
0161     RenderView* view = static_cast<RenderView*>(object);
0162     if (!view->frameView())
0163         return;
0164 
0165     int viewWidth = view->frameView()->visibleWidth();
0166     int viewHeight = view->frameView()->visibleHeight();
0167 
0168     if (size.width() > viewWidth)
0169         size.setWidth(viewWidth);
0170 
0171     if (size.height() > viewHeight)
0172         size.setHeight(viewHeight);
0173 }*/
0174 
0175 } // namespace WebCore
0176 
0177 #endif // ENABLE(SVG)