Commit 4a49a218 authored by pilgrim's avatar pilgrim Committed by Commit bot

[Line Layout API] Convert SVGTextLayoutEngine and SVGTextLayoutEngineBaseline to line Layout API

This CL converts references to LayoutSVGInlineText* objects and some general
LayoutObject* to the equivalent objects in the new line layout API
(LineLayoutSVGInlineText and LineLayoutItem). No functional changes.

BUG=499321

Review URL: https://codereview.chromium.org/1411123014

Cr-Commit-Position: refs/heads/master@{#357170}
parent 2d56a247
...@@ -58,6 +58,59 @@ private: ...@@ -58,6 +58,59 @@ private:
} }
}; };
class SVGInlineTextMetricsIterator {
DISALLOW_NEW();
public:
SVGInlineTextMetricsIterator() { reset(nullptr); }
void advanceToTextStart(LineLayoutSVGInlineText* textLineLayout, unsigned startCharacterOffset)
{
ASSERT(textLineLayout);
if (m_textLineLayout != textLineLayout) {
reset(textLineLayout);
ASSERT(!metricsList().isEmpty());
}
if (m_characterOffset == startCharacterOffset)
return;
// TODO(fs): We could walk backwards through the metrics list in these cases.
if (m_characterOffset > startCharacterOffset)
reset(textLineLayout);
while (m_characterOffset < startCharacterOffset)
next();
}
void next()
{
m_characterOffset += metrics().length();
++m_metricsListOffset;
}
const SVGTextMetrics& metrics() const
{
ASSERT(m_textLineLayout && m_metricsListOffset < metricsList().size());
return metricsList()[m_metricsListOffset];
}
const Vector<SVGTextMetrics>& metricsList() const { return m_textLineLayout->layoutAttributes()->textMetricsValues(); }
unsigned metricsListOffset() const { return m_metricsListOffset; }
unsigned characterOffset() const { return m_characterOffset; }
bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); }
private:
void reset(LineLayoutSVGInlineText* textLineLayout)
{
m_textLineLayout = textLineLayout;
m_characterOffset = 0;
m_metricsListOffset = 0;
}
LineLayoutSVGInlineText* m_textLineLayout;
unsigned m_metricsListOffset;
unsigned m_characterOffset;
};
} // namespace blink } // namespace blink
#endif // LineLayoutSVGInlineText_h #endif // LineLayoutSVGInlineText_h
...@@ -67,6 +67,11 @@ public: ...@@ -67,6 +67,11 @@ public:
return toText()->uncheckedCharacterAt(offset); return toText()->uncheckedCharacterAt(offset);
} }
UChar32 codepointAt(unsigned offset) const
{
return toText()->codepointAt(offset);
}
bool is8Bit() const bool is8Bit() const
{ {
return toText()->is8Bit(); return toText()->is8Bit();
......
...@@ -69,59 +69,6 @@ private: ...@@ -69,59 +69,6 @@ private:
DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutSVGInlineText, isSVGInlineText()); DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutSVGInlineText, isSVGInlineText());
class SVGInlineTextMetricsIterator {
DISALLOW_NEW();
public:
SVGInlineTextMetricsIterator() { reset(nullptr); }
void advanceToTextStart(const LayoutSVGInlineText* textLayoutObject, unsigned startCharacterOffset)
{
ASSERT(textLayoutObject);
if (m_textLayoutObject != textLayoutObject) {
reset(textLayoutObject);
ASSERT(!metricsList().isEmpty());
}
if (m_characterOffset == startCharacterOffset)
return;
// TODO(fs): We could walk backwards through the metrics list in these cases.
if (m_characterOffset > startCharacterOffset)
reset(textLayoutObject);
while (m_characterOffset < startCharacterOffset)
next();
}
void next()
{
m_characterOffset += metrics().length();
++m_metricsListOffset;
}
const SVGTextMetrics& metrics() const
{
ASSERT(m_textLayoutObject && m_metricsListOffset < metricsList().size());
return metricsList()[m_metricsListOffset];
}
const Vector<SVGTextMetrics>& metricsList() const { return m_textLayoutObject->layoutAttributes()->textMetricsValues(); }
unsigned metricsListOffset() const { return m_metricsListOffset; }
unsigned characterOffset() const { return m_characterOffset; }
bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); }
private:
void reset(const LayoutSVGInlineText* textLayoutObject)
{
m_textLayoutObject = textLayoutObject;
m_characterOffset = 0;
m_metricsListOffset = 0;
}
const LayoutSVGInlineText* m_textLayoutObject;
unsigned m_metricsListOffset;
unsigned m_characterOffset;
};
} }
#endif // LayoutSVGInlineText_h #endif // LayoutSVGInlineText_h
...@@ -207,16 +207,16 @@ void SVGTextLayoutEngine::layoutInlineTextBox(SVGInlineTextBox* textBox) ...@@ -207,16 +207,16 @@ void SVGTextLayoutEngine::layoutInlineTextBox(SVGInlineTextBox* textBox)
{ {
ASSERT(textBox); ASSERT(textBox);
LayoutSVGInlineText& text = toLayoutSVGInlineText(textBox->layoutObject()); LineLayoutSVGInlineText textLineLayout = LineLayoutSVGInlineText(textBox->lineLayoutItem());
ASSERT(text.parent()); ASSERT(textLineLayout.parent());
ASSERT(text.parent()->node()); ASSERT(textLineLayout.parent().node());
ASSERT(text.parent()->node()->isSVGElement()); ASSERT(textLineLayout.parent().node()->isSVGElement());
const ComputedStyle& style = text.styleRef(); const ComputedStyle& style = textLineLayout.styleRef();
textBox->clearTextFragments(); textBox->clearTextFragments();
m_isVerticalText = !style.isHorizontalWritingMode(); m_isVerticalText = !style.isHorizontalWritingMode();
layoutTextOnLineOrPath(textBox, text, style); layoutTextOnLineOrPath(textBox, textLineLayout, style);
if (m_inPathLayout) if (m_inPathLayout)
return; return;
...@@ -329,13 +329,13 @@ void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo ...@@ -329,13 +329,13 @@ void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo
m_logicalCharacterOffset += logicalMetrics.length(); m_logicalCharacterOffset += logicalMetrics.length();
} }
void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, const LayoutSVGInlineText& text, const ComputedStyle& style) void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, LineLayoutSVGInlineText textLineLayout, const ComputedStyle& style)
{ {
if (m_inPathLayout && !m_textPathCalculator) if (m_inPathLayout && !m_textPathCalculator)
return; return;
// Find the start of the current text box in the metrics list. // Find the start of the current text box in the metrics list.
m_visualMetricsIterator.advanceToTextStart(&text, textBox->start()); m_visualMetricsIterator.advanceToTextStart(&textLineLayout, textBox->start());
const Font& font = style.font(); const Font& font = style.font();
...@@ -347,7 +347,7 @@ void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, cons ...@@ -347,7 +347,7 @@ void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, cons
float lastAngle = 0; float lastAngle = 0;
float baselineShift = baselineLayout.calculateBaselineShift(style); float baselineShift = baselineLayout.calculateBaselineShift(style);
baselineShift -= baselineLayout.calculateAlignmentBaselineShift(m_isVerticalText, &text); baselineShift -= baselineLayout.calculateAlignmentBaselineShift(m_isVerticalText, textLineLayout);
// Main layout algorithm. // Main layout algorithm.
const unsigned boxEndOffset = textBox->start() + textBox->len(); const unsigned boxEndOffset = textBox->start() + textBox->len();
...@@ -386,7 +386,7 @@ void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, cons ...@@ -386,7 +386,7 @@ void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, cons
// Calculate glyph orientation angle. // Calculate glyph orientation angle.
// Font::width() calculates the resolved FontOrientation for each character, // Font::width() calculates the resolved FontOrientation for each character,
// but is not exposed today to avoid the API complexity. // but is not exposed today to avoid the API complexity.
UChar32 currentCharacter = text.codepointAt(m_visualMetricsIterator.characterOffset()); UChar32 currentCharacter = textLineLayout.codepointAt(m_visualMetricsIterator.characterOffset());
FontOrientation fontOrientation = font.fontDescription().orientation(); FontOrientation fontOrientation = font.fontDescription().orientation();
fontOrientation = adjustOrientationForCharacterInMixedVertical(fontOrientation, currentCharacter); fontOrientation = adjustOrientationForCharacterInMixedVertical(fontOrientation, currentCharacter);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#ifndef SVGTextLayoutEngine_h #ifndef SVGTextLayoutEngine_h
#define SVGTextLayoutEngine_h #define SVGTextLayoutEngine_h
#include "core/layout/api/LineLayoutSVGInlineText.h"
#include "core/layout/svg/LayoutSVGInlineText.h" #include "core/layout/svg/LayoutSVGInlineText.h"
#include "core/layout/svg/SVGTextFragment.h" #include "core/layout/svg/SVGTextFragment.h"
#include "core/layout/svg/SVGTextLayoutAttributes.h" #include "core/layout/svg/SVGTextLayoutAttributes.h"
...@@ -66,7 +67,7 @@ private: ...@@ -66,7 +67,7 @@ private:
void endTextPathLayout(); void endTextPathLayout();
void layoutInlineTextBox(SVGInlineTextBox*); void layoutInlineTextBox(SVGInlineTextBox*);
void layoutTextOnLineOrPath(SVGInlineTextBox*, const LayoutSVGInlineText&, const ComputedStyle&); void layoutTextOnLineOrPath(SVGInlineTextBox*, LineLayoutSVGInlineText, const ComputedStyle&);
bool currentLogicalCharacterAttributes(SVGTextLayoutAttributes*&); bool currentLogicalCharacterAttributes(SVGTextLayoutAttributes*&);
bool currentLogicalCharacterMetrics(SVGTextLayoutAttributes*&, SVGTextMetrics&); bool currentLogicalCharacterMetrics(SVGTextLayoutAttributes*&, SVGTextMetrics&);
......
...@@ -53,12 +53,12 @@ float SVGTextLayoutEngineBaseline::calculateBaselineShift(const ComputedStyle& s ...@@ -53,12 +53,12 @@ float SVGTextLayoutEngineBaseline::calculateBaselineShift(const ComputedStyle& s
} }
} }
EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBaseline(bool isVerticalText, const LayoutObject* textLayoutObject) const EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBaseline(bool isVerticalText, LineLayoutItem textLineLayout) const
{ {
ASSERT(textLayoutObject); ASSERT(textLineLayout);
ASSERT(textLayoutObject->style()); ASSERT(textLineLayout.style());
const SVGComputedStyle& style = textLayoutObject->style()->svgStyle(); const SVGComputedStyle& style = textLineLayout.style()->svgStyle();
EDominantBaseline baseline = style.dominantBaseline(); EDominantBaseline baseline = style.dominantBaseline();
if (baseline == DB_AUTO) { if (baseline == DB_AUTO) {
...@@ -75,11 +75,11 @@ EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel ...@@ -75,11 +75,11 @@ EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel
// content. // content.
return AB_ALPHABETIC; return AB_ALPHABETIC;
case DB_NO_CHANGE: case DB_NO_CHANGE:
ASSERT(textLayoutObject->parent()); ASSERT(textLineLayout.parent());
return dominantBaselineToAlignmentBaseline(isVerticalText, textLayoutObject->parent()); return dominantBaselineToAlignmentBaseline(isVerticalText, textLineLayout.parent());
case DB_RESET_SIZE: case DB_RESET_SIZE:
ASSERT(textLayoutObject->parent()); ASSERT(textLineLayout.parent());
return dominantBaselineToAlignmentBaseline(isVerticalText, textLayoutObject->parent()); return dominantBaselineToAlignmentBaseline(isVerticalText, textLineLayout.parent());
case DB_IDEOGRAPHIC: case DB_IDEOGRAPHIC:
return AB_IDEOGRAPHIC; return AB_IDEOGRAPHIC;
case DB_ALPHABETIC: case DB_ALPHABETIC:
...@@ -102,18 +102,18 @@ EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel ...@@ -102,18 +102,18 @@ EAlignmentBaseline SVGTextLayoutEngineBaseline::dominantBaselineToAlignmentBasel
} }
} }
float SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift(bool isVerticalText, const LayoutObject* textLayoutObject) const float SVGTextLayoutEngineBaseline::calculateAlignmentBaselineShift(bool isVerticalText, LineLayoutItem textLineLayout) const
{ {
ASSERT(textLayoutObject); ASSERT(textLineLayout);
ASSERT(textLayoutObject->style()); ASSERT(textLineLayout.style());
ASSERT(textLayoutObject->parent()); ASSERT(textLineLayout.parent());
const LayoutObject* textLayoutObjectParent = textLayoutObject->parent(); LineLayoutItem textLineLayoutParent = textLineLayout.parent();
ASSERT(textLayoutObjectParent); ASSERT(textLineLayoutParent);
EAlignmentBaseline baseline = textLayoutObject->style()->svgStyle().alignmentBaseline(); EAlignmentBaseline baseline = textLineLayout.style()->svgStyle().alignmentBaseline();
if (baseline == AB_AUTO || baseline == AB_BASELINE) { if (baseline == AB_AUTO || baseline == AB_BASELINE) {
baseline = dominantBaselineToAlignmentBaseline(isVerticalText, textLayoutObjectParent); baseline = dominantBaselineToAlignmentBaseline(isVerticalText, textLineLayoutParent);
ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE); ASSERT(baseline != AB_AUTO && baseline != AB_BASELINE);
} }
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#ifndef SVGTextLayoutEngineBaseline_h #ifndef SVGTextLayoutEngineBaseline_h
#define SVGTextLayoutEngineBaseline_h #define SVGTextLayoutEngineBaseline_h
#include "core/layout/api/LineLayoutItem.h"
#include "core/style/SVGComputedStyleDefs.h" #include "core/style/SVGComputedStyleDefs.h"
#include "wtf/Allocator.h" #include "wtf/Allocator.h"
#include "wtf/Noncopyable.h" #include "wtf/Noncopyable.h"
...@@ -41,10 +42,10 @@ public: ...@@ -41,10 +42,10 @@ public:
SVGTextLayoutEngineBaseline(const Font&, float effectiveZoom); SVGTextLayoutEngineBaseline(const Font&, float effectiveZoom);
float calculateBaselineShift(const ComputedStyle&) const; float calculateBaselineShift(const ComputedStyle&) const;
float calculateAlignmentBaselineShift(bool isVerticalText, const LayoutObject* textLayoutObject) const; float calculateAlignmentBaselineShift(bool isVerticalText, LineLayoutItem) const;
private: private:
EAlignmentBaseline dominantBaselineToAlignmentBaseline(bool isVerticalText, const LayoutObject* textLayoutObject) const; EAlignmentBaseline dominantBaselineToAlignmentBaseline(bool isVerticalText, LineLayoutItem) const;
const Font& m_font; const Font& m_font;
......
...@@ -105,9 +105,9 @@ typedef bool ProcessTextFragmentCallback(QueryData*, const SVGTextFragment&); ...@@ -105,9 +105,9 @@ typedef bool ProcessTextFragmentCallback(QueryData*, const SVGTextFragment&);
static bool queryTextBox(QueryData* queryData, const SVGInlineTextBox* textBox, ProcessTextFragmentCallback fragmentCallback) static bool queryTextBox(QueryData* queryData, const SVGInlineTextBox* textBox, ProcessTextFragmentCallback fragmentCallback)
{ {
queryData->textBox = textBox; queryData->textBox = textBox;
queryData->textLineLayout = LineLayoutSVGInlineText(&toLayoutSVGInlineText(textBox->layoutObject())); queryData->textLineLayout = LineLayoutSVGInlineText(textBox->lineLayoutItem());
queryData->isVerticalText = !textBox->layoutObject().style()->isHorizontalWritingMode(); queryData->isVerticalText = !queryData->textLineLayout.style()->isHorizontalWritingMode();
// Loop over all text fragments in this text box, firing a callback for each. // Loop over all text fragments in this text box, firing a callback for each.
for (const SVGTextFragment& fragment : textBox->textFragments()) { for (const SVGTextFragment& fragment : textBox->textFragments()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment