KHtml

SVGRenderSupport.cpp
1 /*
2  * Copyright (C) 2007 Rob Buis <[email protected]>
3  * (C) 2007 Nikolas Zimmermann <[email protected]>
4  * (C) 2007 Eric Seidel <[email protected]>
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22 
23 #include "wtf/Platform.h"
24 
25 #if ENABLE(SVG)
26 #include "SVGRenderSupport.h"
27 
28 #include "AffineTransform.h"
29 /*#include "ImageBuffer.h"*/
30 #include "RenderSVGContainer.h"
31 /*#include "RenderView.h"*/
32 #include "SVGResourceClipper.h"
33 /*#include "SVGResourceFilter.h"
34 #include "SVGResourceMasker.h"*/
35 #include "SVGStyledElement.h"
36 #include "SVGURIReference.h"
37 
38 namespace WebCore
39 {
40 
41 void prepareToRenderSVGContent(RenderObject *object, RenderObject::PaintInfo &paintInfo, const FloatRect &boundingBox, SVGResourceFilter *&filter, SVGResourceFilter *rootFilter)
42 {
43  Q_UNUSED(filter);
44  Q_UNUSED(rootFilter);
45  SVGElement *svgElement = static_cast<SVGElement *>(object->element());
46  ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
47  ASSERT(object);
48 
49  SVGStyledElement *styledElement = static_cast<SVGStyledElement *>(svgElement);
50  const RenderStyle *style = object->style();
51  ASSERT(style);
52 
53  const SVGRenderStyle *svgStyle = style->svgStyle();
54  ASSERT(svgStyle);
55 
56  /*// Setup transparency layers before setting up filters!
57  float opacity = style->opacity();
58  if (opacity < 1.0f) {
59  paintInfo.context->clip(enclosingIntRect(boundingBox));
60  paintInfo.context->beginTransparencyLayer(opacity);
61  }*/
62 
63 #if ENABLE(SVG_FILTERS)
64  AtomicString filterId(SVGURIReference::getTarget(svgStyle->filter()));
65 #endif
66 
67  AtomicString clipperId(SVGURIReference::getTarget(svgStyle->clipPath()));
68  //AtomicString maskerId(SVGURIReference::getTarget(svgStyle->maskElement()));
69 
70  Document *document = object->document();
71 
72 #if ENABLE(SVG_FILTERS)
73  SVGResourceFilter *newFilter = getFilterById(document, filterId);
74  if (newFilter == rootFilter) {
75  // Catch <text filter="url(#foo)">Test<tspan filter="url(#foo)">123</tspan></text>.
76  // The filter is NOT meant to be applied twice in that case!
77  filter = 0;
78  filterId = String();
79  } else {
80  filter = newFilter;
81  }
82 #endif
83 
84  SVGResourceClipper *clipper = getClipperById(document, clipperId);
85  //SVGResourceMasker* masker = getMaskerById(document, maskerId);
86 
87 #if ENABLE(SVG_FILTERS)
88  if (filter) {
89  filter->addClient(styledElement);
90  filter->prepareFilter(paintInfo.context, boundingBox);
91  } else if (!filterId.isEmpty()) {
92  svgElement->document()->accessSVGExtensions()->addPendingResource(filterId, styledElement);
93  }
94 #endif
95 
96  if (clipper) {
97  clipper->addClient(styledElement);
98  clipper->applyClip(paintInfo.p, boundingBox);
99  } else if (!clipperId.isEmpty()) {
100  svgElement->document()->accessSVGExtensions()->addPendingResource(clipperId, styledElement);
101  }
102 
103  /*if (masker) {
104  masker->addClient(styledElement);
105  masker->applyMask(paintInfo.context, boundingBox);
106  } else if (!maskerId.isEmpty())
107  svgElement->document()->accessSVGExtensions()->addPendingResource(maskerId, styledElement);*/
108 }
109 
110 void finishRenderSVGContent(RenderObject *object, RenderObject::PaintInfo &paintInfo, const FloatRect &boundingBox, SVGResourceFilter *&filter, QPainter *savedContext)
111 {
112  Q_UNUSED(object);
113  Q_UNUSED(paintInfo);
114  Q_UNUSED(boundingBox);
115  Q_UNUSED(filter);
116  Q_UNUSED(savedContext);
117  /* ASSERT(object);
118 
119  const RenderStyle* style = object->style();
120  ASSERT(style);
121 
122  #if ENABLE(SVG_FILTERS)
123  if (filter) {
124  filter->applyFilter(paintInfo.context, boundingBox);
125  paintInfo.context = savedContext;
126  }
127  #endif
128 
129  float opacity = style->opacity();
130  if (opacity < 1.0f)
131  paintInfo.context->endTransparencyLayer();*/
132 }
133 
134 /*void renderSubtreeToImage(ImageBuffer* image, RenderObject* item)
135 {
136  ASSERT(item);
137  ASSERT(image);
138  ASSERT(image->context());
139  RenderObject::PaintInfo info(image->context(), IntRect(), PaintPhaseForeground, 0, 0, 0);
140 
141  RenderSVGContainer* svgContainer = 0;
142  if (item && item->isSVGContainer())
143  svgContainer = static_cast<RenderSVGContainer*>(item);
144 
145  bool drawsContents = svgContainer ? svgContainer->drawsContents() : false;
146  if (svgContainer && !drawsContents)
147  svgContainer->setDrawsContents(true);
148 
149  item->layoutIfNeeded();
150  item->paint(info, 0, 0);
151 
152  if (svgContainer && !drawsContents)
153  svgContainer->setDrawsContents(false);
154 }
155 
156 void clampImageBufferSizeToViewport(RenderObject* object, IntSize& size)
157 {
158  if (!object || !object->isRenderView())
159  return;
160 
161  RenderView* view = static_cast<RenderView*>(object);
162  if (!view->frameView())
163  return;
164 
165  int viewWidth = view->frameView()->visibleWidth();
166  int viewHeight = view->frameView()->visibleHeight();
167 
168  if (size.width() > viewWidth)
169  size.setWidth(viewWidth);
170 
171  if (size.height() > viewHeight)
172  size.setHeight(viewHeight);
173 }*/
174 
175 } // namespace WebCore
176 
177 #endif // ENABLE(SVG)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.