From 130cc7e044a3ace1a70bbd71ce8ca4c72712ce9e Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 9 Aug 2017 17:56:33 -0700 Subject: [PATCH] Add ParagraphBuilder::PeekStyle() to allow Flutter style inheritance. Change-Id: Ia198778d9a7cfd7053390e6195bf8e03245add77 --- src/paragraph.h | 2 +- src/paragraph_builder.cc | 4 ++++ src/paragraph_builder.h | 3 +++ src/styled_runs.cc | 4 ++++ src/styled_runs.h | 3 +++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/paragraph.h b/src/paragraph.h index e62c4a1d294..8b4936bac77 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -52,7 +52,7 @@ class Paragraph { ~Paragraph(); - // NOTE: Minikin Layout doLayout() and LineBreaker addStyleRun() has an + // Minikin Layout doLayout() and LineBreaker addStyleRun() has an // O(N^2) (according to benchmarks) time complexity where N is the total // number of characters. However, this is not significant for reasonably sized // paragraphs. It is currently recommended to break up very long paragraphs diff --git a/src/paragraph_builder.cc b/src/paragraph_builder.cc index a883e142a69..964a202211b 100644 --- a/src/paragraph_builder.cc +++ b/src/paragraph_builder.cc @@ -72,6 +72,10 @@ void ParagraphBuilder::Pop() { runs_.StartRun(style_index, text_index); } +const TextStyle& ParagraphBuilder::PeekStyle() const { + return runs_.PeekStyle(); +} + void ParagraphBuilder::AddText(const std::u16string& text) { text_.insert(text_.end(), text.begin(), text.end()); } diff --git a/src/paragraph_builder.h b/src/paragraph_builder.h index df756672a75..82908506836 100644 --- a/src/paragraph_builder.h +++ b/src/paragraph_builder.h @@ -56,6 +56,9 @@ class ParagraphBuilder { // builder.AddText(" Back to normal again."); void Pop(); + // Returns the last TextStyle on the stack. + const TextStyle& PeekStyle() const; + // Adds text to the builder. Forms the proper runs to use the upper-most style // on the style_stack_; void AddText(const std::u16string& text); diff --git a/src/styled_runs.cc b/src/styled_runs.cc index 7e64460c188..67e7ec1eb2e 100644 --- a/src/styled_runs.cc +++ b/src/styled_runs.cc @@ -46,6 +46,10 @@ size_t StyledRuns::AddStyle(const TextStyle& style) { return style_index; } +const TextStyle& StyledRuns::PeekStyle() const { + return styles_.back(); +} + void StyledRuns::StartRun(size_t style_index, size_t start) { runs_.push_back(IndexedRun{style_index, start, start}); } diff --git a/src/styled_runs.h b/src/styled_runs.h index ff3d58aabae..94931989fd6 100644 --- a/src/styled_runs.h +++ b/src/styled_runs.h @@ -49,6 +49,9 @@ class StyledRuns { size_t AddStyle(const TextStyle& style); + // Returns the last TextStyle on the stack. + const TextStyle& PeekStyle() const; + void StartRun(size_t style_index, size_t start); void EndRunIfNeeded(size_t end);