| 1 | /* |
| 2 | * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public License |
| 15 | * along with this library; see the file COPYING.LIB. If not, write to |
| 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "config.h" |
| 21 | #include "RenderSVGTextPath.h" |
| 22 | |
| 23 | #include "FloatQuad.h" |
| 24 | #include "RenderBlock.h" |
| 25 | #include "SVGInlineTextBox.h" |
| 26 | #include "SVGNames.h" |
| 27 | #include "SVGPathData.h" |
| 28 | #include "SVGPathElement.h" |
| 29 | #include "SVGRootInlineBox.h" |
| 30 | #include "SVGTextPathElement.h" |
| 31 | #include <wtf/IsoMallocInlines.h> |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSVGTextPath); |
| 36 | |
| 37 | RenderSVGTextPath::RenderSVGTextPath(SVGTextPathElement& element, RenderStyle&& style) |
| 38 | : RenderSVGInline(element, WTFMove(style)) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | SVGTextPathElement& RenderSVGTextPath::textPathElement() const |
| 43 | { |
| 44 | return downcast<SVGTextPathElement>(RenderSVGInline::graphicsElement()); |
| 45 | } |
| 46 | |
| 47 | Path RenderSVGTextPath::layoutPath() const |
| 48 | { |
| 49 | auto target = SVGURIReference::targetElementFromIRIString(textPathElement().href(), textPathElement().treeScope()); |
| 50 | if (!is<SVGPathElement>(target.element)) |
| 51 | return Path(); |
| 52 | |
| 53 | SVGPathElement& pathElement = downcast<SVGPathElement>(*target.element); |
| 54 | |
| 55 | Path path = pathFromGraphicsElement(&pathElement); |
| 56 | |
| 57 | // Spec: The transform attribute on the referenced 'path' element represents a |
| 58 | // supplemental transformation relative to the current user coordinate system for |
| 59 | // the current 'text' element, including any adjustments to the current user coordinate |
| 60 | // system due to a possible transform attribute on the current 'text' element. |
| 61 | // http://www.w3.org/TR/SVG/text.html#TextPathElement |
| 62 | path.transform(pathElement.animatedLocalTransform()); |
| 63 | return path; |
| 64 | } |
| 65 | |
| 66 | float RenderSVGTextPath::startOffset() const |
| 67 | { |
| 68 | return textPathElement().startOffset().valueAsPercentage(); |
| 69 | } |
| 70 | |
| 71 | bool RenderSVGTextPath::exactAlignment() const |
| 72 | { |
| 73 | return textPathElement().spacing() == SVGTextPathSpacingExact; |
| 74 | } |
| 75 | |
| 76 | bool RenderSVGTextPath::stretchMethod() const |
| 77 | { |
| 78 | return textPathElement().method() == SVGTextPathMethodStretch; |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |