Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/LayoutSVGTextPath.cpp

Issue 1683903004: Factor out the <textPath> positioning mapping code into a helper class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 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 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, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "core/layout/svg/LayoutSVGTextPath.h" 20 #include "core/layout/svg/LayoutSVGTextPath.h"
21 21
22 #include "core/layout/svg/SVGLayoutSupport.h" 22 #include "core/layout/svg/SVGLayoutSupport.h"
23 #include "core/svg/SVGPathElement.h" 23 #include "core/svg/SVGPathElement.h"
24 #include "core/svg/SVGTextPathElement.h" 24 #include "core/svg/SVGTextPathElement.h"
25 #include "platform/graphics/Path.h"
25 26
26 namespace blink { 27 namespace blink {
27 28
29 PathPositionMapper::PathPositionMapper(const Path& path)
30 : m_positionCalculator(path)
31 , m_pathLength(path.length())
32 {
33 }
34
35 PathPositionMapper::PositionType PathPositionMapper::pointAndNormalAtLength(
36 float length, FloatPoint& point, float& angle)
37 {
38 if (length < 0)
39 return BeforePath;
40 if (length > m_pathLength)
41 return AfterPath;
42 ASSERT(length >= 0 && length <= m_pathLength);
43 m_positionCalculator.pointAndNormalAtLength(length, point, angle);
44 return OnPath;
45 }
46
28 LayoutSVGTextPath::LayoutSVGTextPath(Element* element) 47 LayoutSVGTextPath::LayoutSVGTextPath(Element* element)
29 : LayoutSVGInline(element) 48 : LayoutSVGInline(element)
30 { 49 {
31 } 50 }
32 51
33 bool LayoutSVGTextPath::isChildAllowed(LayoutObject* child, const ComputedStyle& ) const 52 bool LayoutSVGTextPath::isChildAllowed(LayoutObject* child, const ComputedStyle& ) const
34 { 53 {
35 if (child->isText()) 54 if (child->isText())
36 return SVGLayoutSupport::isLayoutableTextNode(child); 55 return SVGLayoutSupport::isLayoutableTextNode(child);
37 56
38 return child->isSVGInline() && !child->isSVGTextPath(); 57 return child->isSVGInline() && !child->isSVGTextPath();
39 } 58 }
40 59
41 Path LayoutSVGTextPath::layoutPath() const 60 PassOwnPtr<PathPositionMapper> LayoutSVGTextPath::layoutPath() const
42 { 61 {
43 SVGTextPathElement* textPathElement = toSVGTextPathElement(node()); 62 const SVGTextPathElement& textPathElement = toSVGTextPathElement(*node());
44 Element* targetElement = SVGURIReference::targetElementFromIRIString(textPat hElement->href()->currentValue()->value(), textPathElement->treeScope()); 63 Element* targetElement = SVGURIReference::targetElementFromIRIString(
64 textPathElement.hrefString(), textPathElement.treeScope());
45 if (!isSVGPathElement(targetElement)) 65 if (!isSVGPathElement(targetElement))
46 return Path(); 66 return nullptr;
47 67
48 SVGPathElement& pathElement = toSVGPathElement(*targetElement); 68 SVGPathElement& pathElement = toSVGPathElement(*targetElement);
49 Path pathData = pathElement.asPath(); 69 Path pathData = pathElement.asPath();
70 if (pathData.isEmpty())
71 return nullptr;
50 72
51 // Spec: The transform attribute on the referenced 'path' element represent s a 73 // Spec: The transform attribute on the referenced 'path' element represent s a
52 // supplemental transformation relative to the current user coordinate syste m for 74 // supplemental transformation relative to the current user coordinate syste m for
53 // the current 'text' element, including any adjustments to the current user coordinate 75 // the current 'text' element, including any adjustments to the current user coordinate
54 // system due to a possible transform attribute on the current 'text' elemen t. 76 // system due to a possible transform attribute on the current 'text' elemen t.
55 // http://www.w3.org/TR/SVG/text.html#TextPathElement 77 // http://www.w3.org/TR/SVG/text.html#TextPathElement
56 pathData.transform(pathElement.calculateAnimatedLocalTransform()); 78 pathData.transform(pathElement.calculateAnimatedLocalTransform());
57 return pathData; 79
80 return PathPositionMapper::create(pathData);
58 } 81 }
59 82
60 float LayoutSVGTextPath::calculateStartOffset(float pathLength) const 83 float LayoutSVGTextPath::calculateStartOffset(float pathLength) const
61 { 84 {
62 const SVGLength& startOffset = *toSVGTextPathElement(node())->startOffset()- >currentValue(); 85 const SVGLength& startOffset = *toSVGTextPathElement(node())->startOffset()- >currentValue();
63 float textPathStartOffset = startOffset.valueAsPercentage(); 86 float textPathStartOffset = startOffset.valueAsPercentage();
64 if (startOffset.typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Perce ntage) 87 if (startOffset.typeWithCalcResolved() == CSSPrimitiveValue::UnitType::Perce ntage)
65 textPathStartOffset *= pathLength; 88 textPathStartOffset *= pathLength;
66 89
67 return textPathStartOffset; 90 return textPathStartOffset;
68 } 91 }
69 92
70 } // namespace blink 93 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698