KHtml

RenderSVGTextPath.cpp
1 /*
2  * This file is part of the WebKit project.
3  *
4  * Copyright (C) 2007 Nikolas Zimmermann <[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 "RenderSVGTextPath.h"
27 
28 #include "FloatRect.h"
29 #include "SVGInlineTextBox.h"
30 #include "SVGPathElement.h"
31 #include "SVGRootInlineBox.h"
32 #include "SVGTextPathElement.h"
33 #include "SVGTransformList.h"
34 
35 namespace WebCore
36 {
37 
38 RenderSVGTextPath::RenderSVGTextPath(DOM::NodeImpl *n)
39  : RenderSVGInline(n)
40  , m_startOffset(0.0f)
41  , m_exactAlignment(true)
42  , m_stretchMethod(false)
43 {
44 }
45 
46 Path RenderSVGTextPath::layoutPath() const
47 {
48  SVGTextPathElement *textPathElement = static_cast<SVGTextPathElement *>(element());
49  String pathId = SVGURIReference::getTarget(textPathElement->href());
50  Element *targetElement = textPathElement->document()->getElementById(pathId);
51  if (!targetElement || !targetElement->hasTagName(SVGNames::pathTag)) {
52  return Path();
53  }
54 
55  SVGPathElement *pathElement = static_cast<SVGPathElement *>(targetElement);
56 
57  Path pathData = pathElement->toPathData();
58  // Spec: The transform attribute on the referenced 'path' element represents a
59  // supplemental transformation relative to the current user coordinate system for
60  // the current 'text' element, including any adjustments to the current user coordinate
61  // system due to a possible transform attribute on the current 'text' element.
62  // https://www.w3.org/TR/SVG/text.html#TextPathElement
63  pathData.transform(pathElement->animatedLocalTransform());
64  return pathData;
65 }
66 
67 float RenderSVGTextPath::startOffset() const
68 {
69  return static_cast<SVGTextPathElement *>(element())->startOffset().valueAsPercentage();
70 }
71 
72 bool RenderSVGTextPath::exactAlignment() const
73 {
74  return static_cast<SVGTextPathElement *>(element())->spacing() == SVG_TEXTPATH_SPACINGTYPE_EXACT;
75 }
76 
77 bool RenderSVGTextPath::stretchMethod() const
78 {
79  return static_cast<SVGTextPathElement *>(element())->method() == SVG_TEXTPATH_METHODTYPE_STRETCH;
80 }
81 
82 void RenderSVGTextPath::absoluteRects(Vector<IntRect> &rects, int, int)
83 {
84  InlineRunBox *firstBox = firstLineBox();
85 
86  SVGRootInlineBox *rootBox = firstBox ? static_cast<SVGInlineTextBox *>(firstBox)->svgRootInlineBox() : nullptr;
87  RenderObject *object = rootBox ? rootBox->object() : nullptr;
88 
89  if (!object) {
90  return;
91  }
92 
93  int xRef = object->xPos() + xPos();
94  int yRef = object->yPos() + yPos();
95 
96  for (InlineRunBox *curr = firstBox; curr; curr = curr->nextLineBox()) {
97  FloatRect rect(xRef + curr->xPos(), yRef + curr->yPos(), curr->width(), curr->height());
98  rects.append(enclosingIntRect(absoluteTransform().mapRect(rect)));
99  }
100 }
101 
102 }
103 
104 #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:09 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.