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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/svg/LayoutSVGTextPath.cpp
diff --git a/third_party/WebKit/Source/core/layout/svg/LayoutSVGTextPath.cpp b/third_party/WebKit/Source/core/layout/svg/LayoutSVGTextPath.cpp
index 29964a11682917aff4c91b3109f0de0169291ac0..5562e3959948812d8387b6f8ccf2951aa0f331ac 100644
--- a/third_party/WebKit/Source/core/layout/svg/LayoutSVGTextPath.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/LayoutSVGTextPath.cpp
@@ -22,9 +22,28 @@
#include "core/layout/svg/SVGLayoutSupport.h"
#include "core/svg/SVGPathElement.h"
#include "core/svg/SVGTextPathElement.h"
+#include "platform/graphics/Path.h"
namespace blink {
+PathPositionMapper::PathPositionMapper(const Path& path)
+ : m_positionCalculator(path)
+ , m_pathLength(path.length())
+{
+}
+
+PathPositionMapper::PositionType PathPositionMapper::pointAndNormalAtLength(
+ float length, FloatPoint& point, float& angle)
+{
+ if (length < 0)
+ return BeforePath;
+ if (length > m_pathLength)
+ return AfterPath;
+ ASSERT(length >= 0 && length <= m_pathLength);
+ m_positionCalculator.pointAndNormalAtLength(length, point, angle);
+ return OnPath;
+}
+
LayoutSVGTextPath::LayoutSVGTextPath(Element* element)
: LayoutSVGInline(element)
{
@@ -38,15 +57,18 @@ bool LayoutSVGTextPath::isChildAllowed(LayoutObject* child, const ComputedStyle&
return child->isSVGInline() && !child->isSVGTextPath();
}
-Path LayoutSVGTextPath::layoutPath() const
+PassOwnPtr<PathPositionMapper> LayoutSVGTextPath::layoutPath() const
{
- SVGTextPathElement* textPathElement = toSVGTextPathElement(node());
- Element* targetElement = SVGURIReference::targetElementFromIRIString(textPathElement->href()->currentValue()->value(), textPathElement->treeScope());
+ const SVGTextPathElement& textPathElement = toSVGTextPathElement(*node());
+ Element* targetElement = SVGURIReference::targetElementFromIRIString(
+ textPathElement.hrefString(), textPathElement.treeScope());
if (!isSVGPathElement(targetElement))
- return Path();
+ return nullptr;
SVGPathElement& pathElement = toSVGPathElement(*targetElement);
Path pathData = pathElement.asPath();
+ if (pathData.isEmpty())
+ return nullptr;
// Spec: The transform attribute on the referenced 'path' element represents a
// supplemental transformation relative to the current user coordinate system for
@@ -54,7 +76,8 @@ Path LayoutSVGTextPath::layoutPath() const
// system due to a possible transform attribute on the current 'text' element.
// http://www.w3.org/TR/SVG/text.html#TextPathElement
pathData.transform(pathElement.calculateAnimatedLocalTransform());
- return pathData;
+
+ return PathPositionMapper::create(pathData);
}
float LayoutSVGTextPath::calculateStartOffset(float pathLength) const

Powered by Google App Engine
This is Rietveld 408576698