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

Unified Diff: Source/core/layout/svg/LayoutSVGInlineText.h

Issue 1160623002: Avoid resetting the metrics-list/character offset for each text box (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase. Created 5 years, 7 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 | « no previous file | Source/core/layout/svg/SVGTextLayoutEngine.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/layout/svg/LayoutSVGInlineText.h
diff --git a/Source/core/layout/svg/LayoutSVGInlineText.h b/Source/core/layout/svg/LayoutSVGInlineText.h
index f35e7bcaaa47a21d9ff11fa7ed2c6494b0dfbb96..98594511cc37aa203334a8a99ccd3ad40a92fe2a 100644
--- a/Source/core/layout/svg/LayoutSVGInlineText.h
+++ b/Source/core/layout/svg/LayoutSVGInlineText.h
@@ -69,6 +69,57 @@ private:
DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutSVGInlineText, isSVGInlineText());
+class SVGInlineTextMetricsIterator {
+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; }
+
+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
« no previous file with comments | « no previous file | Source/core/layout/svg/SVGTextLayoutEngine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698