Add ParagraphBuilder::PeekStyle() to allow Flutter style inheritance.

Change-Id: Ia198778d9a7cfd7053390e6195bf8e03245add77
This commit is contained in:
Gary Qian 2017-08-09 17:56:33 -07:00
parent ffd0311172
commit 130cc7e044
5 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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());
}

View File

@ -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);

View File

@ -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});
}

View File

@ -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);