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

Unified Diff: ui/gfx/render_text.cc

Issue 1020853018: DNCI [RenderText] Added font size options in RenderText. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed some debug code Created 5 years, 9 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
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index c668c1b3f6aadfd5266f36572d51772305b4ee20..a796e092356013d97ed2e2a52a86030d0c39e4f9 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -367,10 +367,15 @@ void SkiaTextRenderer::DiagonalStrike::Draw() {
}
}
-StyleIterator::StyleIterator(const BreakList<SkColor>& colors,
+StyleIterator::StyleIterator(const BreakList<uint32_t>& font_sizes,
+ const BreakList<SkColor>& colors,
const BreakList<BaselineStyle>& baselines,
const std::vector<BreakList<bool>>& styles)
- : colors_(colors), baselines_(baselines), styles_(styles) {
+ : font_sizes_(font_sizes),
+ colors_(colors),
+ baselines_(baselines),
+ styles_(styles) {
+ font_size_ = font_sizes_.breaks().begin();
color_ = colors_.breaks().begin();
baseline_ = baselines_.breaks().begin();
for (size_t i = 0; i < styles_.size(); ++i)
@@ -381,6 +386,7 @@ StyleIterator::~StyleIterator() {}
Range StyleIterator::GetRange() const {
Range range(colors_.GetRange(color_));
+ range = range.Intersect(font_sizes_.GetRange(font_size_));
range = range.Intersect(baselines_.GetRange(baseline_));
for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
range = range.Intersect(styles_[i].GetRange(style_[i]));
@@ -388,6 +394,7 @@ Range StyleIterator::GetRange() const {
}
void StyleIterator::UpdatePosition(size_t position) {
+ font_size_ = font_sizes_.GetBreak(position);
color_ = colors_.GetBreak(position);
baseline_ = baselines_.GetBreak(position);
for (size_t i = 0; i < NUM_TEXT_STYLES; ++i)
@@ -450,6 +457,7 @@ void RenderText::SetText(const base::string16& text) {
// Clear style ranges as they might break new text graphemes and apply
// the first style to the whole text instead.
+ font_sizes_.SetValue(font_sizes_.breaks().begin()->second);
colors_.SetValue(colors_.breaks().begin()->second);
baselines_.SetValue(baselines_.breaks().begin()->second);
for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
@@ -707,6 +715,18 @@ void RenderText::SetCompositionRange(const Range& composition_range) {
OnLayoutTextAttributeChanged(false);
}
+void RenderText::SetFontSize(uint32_t value) {
+ font_sizes_.SetValue(value);
+ cached_bounds_and_offset_valid_ = false;
+ OnLayoutTextAttributeChanged(false);
+}
+
+void RenderText::ApplyFontSize(uint32_t value, const Range& range) {
+ font_sizes_.ApplyValue(value, range);
+ cached_bounds_and_offset_valid_ = false;
+ OnLayoutTextAttributeChanged(false);
+}
+
void RenderText::SetColor(SkColor value) {
colors_.SetValue(value);
}
@@ -974,6 +994,7 @@ RenderText::RenderText()
selection_background_focused_color_(kDefaultSelectionBackgroundColor),
focused_(false),
composition_range_(Range::InvalidRange()),
+ font_sizes_(0),
colors_(kDefaultColor),
baselines_(NORMAL_BASELINE),
styles_(NUM_TEXT_STYLES),
@@ -1268,6 +1289,7 @@ size_t RenderText::TextIndexToGivenTextIndex(const base::string16& given_text,
void RenderText::UpdateStyleLengths() {
const size_t text_length = text_.length();
+ font_sizes_.SetMax(text_length);
colors_.SetMax(text_length);
baselines_.SetMax(text_length);
for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
@@ -1373,6 +1395,7 @@ base::string16 RenderText::Elide(const base::string16& text,
render_text->styles_ = styles_;
render_text->baselines_ = baselines_;
render_text->colors_ = colors_;
+ render_text->font_sizes_ = font_sizes_;
if (text_width == 0) {
render_text->SetText(text);
text_width = render_text->GetContentWidthF();
@@ -1430,6 +1453,7 @@ base::string16 RenderText::Elide(const base::string16& text,
for (size_t style = 0; style < NUM_TEXT_STYLES; ++style)
RestoreBreakList(render_text.get(), render_text->styles_[style]);
RestoreBreakList(render_text.get(), render_text->baselines_);
+ RestoreBreakList(render_text.get(), render_text->font_sizes_);
// We check the width of the whole desired string at once to ensure we
// handle kerning/ligatures/etc. correctly.

Powered by Google App Engine
This is Rietveld 408576698