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

Unified Diff: third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.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
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp
diff --git a/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp b/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp
index d8b3a66a73aa676ec94efc5d53faed9f17d75b5d..34bcaa7c6b32f2c1a3906b1881bc1d605d89efeb 100644
--- a/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp
@@ -45,8 +45,7 @@ SVGTextLayoutEngine::SVGTextLayoutEngine(Vector<SVGTextLayoutAttributes*>& layou
, m_isVerticalText(false)
, m_inPathLayout(false)
, m_textLengthSpacingInEffect(false)
- , m_textPathCalculator(nullptr)
- , m_textPathLength(0)
+ , m_textPath(nullptr)
, m_textPathCurrentOffset(0)
, m_textPathSpacing(0)
, m_textPathScaling(1)
@@ -54,6 +53,8 @@ SVGTextLayoutEngine::SVGTextLayoutEngine(Vector<SVGTextLayoutAttributes*>& layou
ASSERT(!m_layoutAttributes.isEmpty());
}
+SVGTextLayoutEngine::~SVGTextLayoutEngine() = default;
+
void SVGTextLayoutEngine::updateCharacterPositionIfNeeded(float& x, float& y)
{
if (m_inPathLayout)
@@ -174,12 +175,10 @@ void SVGTextLayoutEngine::beginTextPathLayout(SVGInlineFlowBox* flowBox)
m_inPathLayout = true;
LineLayoutSVGTextPath textPath = LineLayoutSVGTextPath(flowBox->lineLayoutItem());
- Path path = textPath.layoutPath();
- if (path.isEmpty())
+ m_textPath = textPath.layoutPath();
+ if (!m_textPath)
return;
- m_textPathCalculator = new Path::PositionCalculator(path);
- m_textPathLength = path.length();
- m_textPathStartOffset = textPath.calculateStartOffset(m_textPathLength);
+ m_textPathStartOffset = textPath.calculateStartOffset(m_textPath->length());
SVGTextPathChunkBuilder textPathChunkLayoutBuilder;
textPathChunkLayoutBuilder.processTextChunks(lineLayout.m_lineLayoutBoxes);
@@ -213,9 +212,7 @@ void SVGTextLayoutEngine::beginTextPathLayout(SVGInlineFlowBox* flowBox)
void SVGTextLayoutEngine::endTextPathLayout()
{
m_inPathLayout = false;
- delete m_textPathCalculator;
- m_textPathCalculator = 0;
- m_textPathLength = 0;
+ m_textPath = nullptr;
m_textPathStartOffset = 0;
m_textPathCurrentOffset = 0;
m_textPathSpacing = 0;
@@ -350,7 +347,7 @@ void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo
void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, LineLayoutSVGInlineText textLineLayout, const ComputedStyle& style)
{
- if (m_inPathLayout && !m_textPathCalculator)
+ if (m_inPathLayout && !m_textPath)
return;
// Find the start of the current text box in the metrics list.
@@ -422,7 +419,6 @@ void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line
// Calculate CSS 'letter-spacing' and 'word-spacing' for next character, if needed.
float spacing = spacingLayout.calculateCSSSpacing(currentCharacter);
- float textPathOffset = 0;
float textPathShiftX = 0;
float textPathShiftY = 0;
if (m_inPathLayout) {
@@ -452,24 +448,25 @@ void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line
}
// Calculate current offset along path.
- textPathOffset = m_textPathCurrentOffset + scaledGlyphAdvance / 2;
+ float textPathOffset = m_textPathCurrentOffset + scaledGlyphAdvance / 2;
// Move to next character.
m_textPathCurrentOffset += scaledGlyphAdvance + m_textPathSpacing + spacing * m_textPathScaling;
+ FloatPoint point;
+ PathPositionMapper::PositionType positionType = m_textPath->pointAndNormalAtLength(textPathOffset, point, angle);
+
// Skip character, if we're before the path.
- if (textPathOffset < 0) {
+ if (positionType == PathPositionMapper::BeforePath) {
advanceToNextLogicalCharacter(logicalMetrics);
m_visualMetricsIterator.next();
continue;
}
- // Stop processing, if the next character lies behind the path.
- if (textPathOffset > m_textPathLength)
+ // Stop processing if the next character lies behind the path.
+ if (positionType == PathPositionMapper::AfterPath)
break;
- FloatPoint point;
- m_textPathCalculator->pointAndNormalAtLength(textPathOffset, point, angle);
x = point.x();
y = point.y();
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698