KHtml

SVGLocatable.cpp
1 /*
2  Copyright (C) 2004, 2005 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006 Rob Buis <[email protected]>
4 
5  This file is part of the KDE project
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include "wtf/Platform.h"
24 
25 #if ENABLE(SVG)
26 
27 #include "SVGLocatable.h"
28 
29 #include "AffineTransform.h"
30 #include "RenderPath.h"
31 #include "SVGException.h"
32 #include "SVGSVGElement.h"
33 
34 namespace WebCore
35 {
36 
37 SVGLocatable::SVGLocatable()
38 {
39 }
40 
41 SVGLocatable::~SVGLocatable()
42 {
43 }
44 
45 SVGElement *SVGLocatable::nearestViewportElement(const SVGStyledElement *e)
46 {
47  Q_UNUSED(e);
48  /*
49  Node* n = e->parentNode();
50  while (n && !n->isDocumentNode()) {
51  if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::symbolTag) ||
52  n->hasTagName(SVGNames::imageTag))
53  return static_cast<SVGElement*>(n);
54  #if ENABLE(SVG_FOREIGN_OBJECT)
55  if (n->hasTagName(SVGNames::foreignObjectTag))
56  return static_cast<SVGElement*>(n);
57  #endif
58 
59  n = n->parentNode();
60  }*/
61 
62  return nullptr;
63 }
64 
65 SVGElement *SVGLocatable::farthestViewportElement(const SVGStyledElement *e)
66 {
67  Q_UNUSED(e);
68  // FIXME : likely this will be always the <svg> farthest away.
69  // If we have a different implementation of documentElement(), one
70  // that give the documentElement() of the svg fragment, it could be
71  // used instead. This depends on cdf demands though(Rob.)
72  SVGElement *farthest = nullptr;
73  /*Node* n = e->parentNode();
74  while (n && !n->isDocumentNode()) {
75  if (n->hasTagName(SVGNames::svgTag) || n->hasTagName(SVGNames::symbolTag) ||
76  n->hasTagName(SVGNames::imageTag))
77  farthest = static_cast<SVGElement*>(n);
78  #if ENABLE(SVG_FOREIGN_OBJECT)
79  if (n->hasTagName(SVGNames::foreignObjectTag))
80  farthest = static_cast<SVGElement*>(n);
81  #endif
82 
83  n = n->parentNode();
84  }*/
85 
86  return farthest;
87 }
88 
89 // Spec:
90 // https://www.w3.org/TR/2005/WD-SVGMobile12-20050413/svgudom.html#svg::SVGLocatable
91 FloatRect SVGLocatable::getBBox(const SVGStyledElement *e)
92 {
93  Q_UNUSED(e);
94  FloatRect bboxRect;
95 
96  /*if (e && e->renderer()) {
97  // Need this to make sure we have render object dimensions.
98  // See bug 11686.
99  e->document()->updateLayoutIgnorePendingStylesheets();
100  bboxRect = e->renderer()->relativeBBox(false);
101  }*/
102 
103  return bboxRect;
104 }
105 
106 AffineTransform SVGLocatable::getCTM(const SVGElement *element)
107 {
108  if (!element) {
109  return AffineTransform();
110  }
111 
112  AffineTransform ctm;
113 
114  Node *parent = element->parentNode();
115  if (parent && parent->isSVGElement()) {
116  SVGElement *parentElement = static_cast<SVGElement *>(parent);
117  if (parentElement && parentElement->isStyledLocatable()) {
118  AffineTransform parentCTM = static_cast<SVGStyledLocatableElement *>(parentElement)->getCTM();
119  ctm = parentCTM * ctm;
120  }
121  }
122 
123  return ctm;
124 }
125 
126 AffineTransform SVGLocatable::getScreenCTM(const SVGElement *element)
127 {
128  if (!element) {
129  return AffineTransform();
130  }
131 
132  AffineTransform ctm;
133 
134  Node *parent = element->parentNode();
135  if (parent && parent->isSVGElement()) {
136  SVGElement *parentElement = static_cast<SVGElement *>(parent);
137  if (parentElement && parentElement->isStyledLocatable()) {
138  AffineTransform parentCTM = static_cast<SVGStyledLocatableElement *>(parentElement)->getScreenCTM();
139  ctm = parentCTM * ctm;
140  }
141  }
142 
143  return ctm;
144 }
145 
146 AffineTransform SVGLocatable::getTransformToElement(SVGElement *target, ExceptionCode &ec) const
147 {
148  Q_UNUSED(ec);
149  AffineTransform ctm = getCTM();
150 
151  if (target && target->isStyledLocatable()) {
152  AffineTransform targetCTM = static_cast<SVGStyledLocatableElement *>(target)->getCTM();
153  if (!targetCTM.isInvertible()) {
154  //ec = SVGException::SVG_MATRIX_NOT_INVERTABLE;
155  return ctm;
156  }
157  ctm *= targetCTM.inverse();
158  }
159 
160  return ctm;
161 }
162 
163 }
164 
165 #endif // ENABLE(SVG)
166 
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:48:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.