| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/render_text_harfbuzz.h" | 5 #include "ui/gfx/render_text_harfbuzz.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/i18n/bidi_line_iterator.h" | 10 #include "base/i18n/bidi_line_iterator.h" |
| (...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 // Temporarily apply composition underlines and selection colors. | 1160 // Temporarily apply composition underlines and selection colors. |
| 1161 ApplyCompositionAndSelectionStyles(); | 1161 ApplyCompositionAndSelectionStyles(); |
| 1162 | 1162 |
| 1163 // Build the run list from the script items and ranged styles and baselines. | 1163 // Build the run list from the script items and ranged styles and baselines. |
| 1164 // Use an empty color BreakList to avoid breaking runs at color boundaries. | 1164 // Use an empty color BreakList to avoid breaking runs at color boundaries. |
| 1165 BreakList<SkColor> empty_colors; | 1165 BreakList<SkColor> empty_colors; |
| 1166 empty_colors.SetMax(text.length()); | 1166 empty_colors.SetMax(text.length()); |
| 1167 DCHECK_LE(text.size(), baselines().max()); | 1167 DCHECK_LE(text.size(), baselines().max()); |
| 1168 for (const BreakList<bool>& style : styles()) | 1168 for (const BreakList<bool>& style : styles()) |
| 1169 DCHECK_LE(text.size(), style.max()); | 1169 DCHECK_LE(text.size(), style.max()); |
| 1170 internal::StyleIterator style(empty_colors, baselines(), styles()); | 1170 internal::StyleIterator style(font_sizes(), empty_colors, baselines(), |
| 1171 styles()); |
| 1171 | 1172 |
| 1172 for (size_t run_break = 0; run_break < text.length();) { | 1173 for (size_t run_break = 0; run_break < text.length();) { |
| 1173 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; | 1174 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; |
| 1174 run->range.set_start(run_break); | 1175 run->range.set_start(run_break); |
| 1175 run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | | 1176 run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | |
| 1176 (style.style(ITALIC) ? Font::ITALIC : 0); | 1177 (style.style(ITALIC) ? Font::ITALIC : 0); |
| 1178 run->font_size = style.font_size(); |
| 1177 run->baseline_type = style.baseline(); | 1179 run->baseline_type = style.baseline(); |
| 1178 run->strike = style.style(STRIKE); | 1180 run->strike = style.style(STRIKE); |
| 1179 run->diagonal_strike = style.style(DIAGONAL_STRIKE); | 1181 run->diagonal_strike = style.style(DIAGONAL_STRIKE); |
| 1180 run->underline = style.style(UNDERLINE); | 1182 run->underline = style.style(UNDERLINE); |
| 1181 int32 script_item_break = 0; | 1183 int32 script_item_break = 0; |
| 1182 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); | 1184 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); |
| 1183 // Odd BiDi embedding levels correspond to RTL runs. | 1185 // Odd BiDi embedding levels correspond to RTL runs. |
| 1184 run->is_rtl = (run->level % 2) == 1; | 1186 run->is_rtl = (run->level % 2) == 1; |
| 1185 // Find the length and script of this script run. | 1187 // Find the length and script of this script run. |
| 1186 script_item_break = ScriptInterval(text, run_break, | 1188 script_item_break = ScriptInterval(text, run_break, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 internal::TextRunList* run_list) { | 1237 internal::TextRunList* run_list) { |
| 1236 for (auto* run : run_list->runs()) | 1238 for (auto* run : run_list->runs()) |
| 1237 ShapeRun(text, run); | 1239 ShapeRun(text, run); |
| 1238 run_list->ComputePrecedingRunWidths(); | 1240 run_list->ComputePrecedingRunWidths(); |
| 1239 } | 1241 } |
| 1240 | 1242 |
| 1241 void RenderTextHarfBuzz::ShapeRun(const base::string16& text, | 1243 void RenderTextHarfBuzz::ShapeRun(const base::string16& text, |
| 1242 internal::TextRunHarfBuzz* run) { | 1244 internal::TextRunHarfBuzz* run) { |
| 1243 const Font& primary_font = font_list().GetPrimaryFont(); | 1245 const Font& primary_font = font_list().GetPrimaryFont(); |
| 1244 const std::string primary_family = primary_font.GetFontName(); | 1246 const std::string primary_family = primary_font.GetFontName(); |
| 1245 run->font_size = primary_font.GetFontSize(); | 1247 if (run->font_size == 0) |
| 1248 run->font_size = primary_font.GetFontSize(); |
| 1246 run->baseline_offset = 0; | 1249 run->baseline_offset = 0; |
| 1247 if (run->baseline_type != NORMAL_BASELINE) { | 1250 if (run->baseline_type != NORMAL_BASELINE) { |
| 1248 // Calculate a slightly smaller font. The ratio here is somewhat arbitrary. | 1251 // Calculate a slightly smaller font. The ratio here is somewhat arbitrary. |
| 1249 // Proportions from 5/9 to 5/7 all look pretty good. | 1252 // Proportions from 5/9 to 5/7 all look pretty good. |
| 1250 const float ratio = 5.0f / 9.0f; | 1253 const float ratio = 5.0f / 9.0f; |
| 1251 run->font_size = gfx::ToRoundedInt(primary_font.GetFontSize() * ratio); | 1254 run->font_size = gfx::ToRoundedInt(primary_font.GetFontSize() * ratio); |
| 1252 switch (run->baseline_type) { | 1255 switch (run->baseline_type) { |
| 1253 case SUPERSCRIPT: | 1256 case SUPERSCRIPT: |
| 1254 run->baseline_offset = | 1257 run->baseline_offset = |
| 1255 primary_font.GetCapHeight() - primary_font.GetHeight(); | 1258 primary_font.GetCapHeight() - primary_font.GetHeight(); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 DCHECK(!update_layout_run_list_); | 1531 DCHECK(!update_layout_run_list_); |
| 1529 DCHECK(!update_display_run_list_); | 1532 DCHECK(!update_display_run_list_); |
| 1530 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1533 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
| 1531 } | 1534 } |
| 1532 | 1535 |
| 1533 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1536 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
| 1534 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1537 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
| 1535 } | 1538 } |
| 1536 | 1539 |
| 1537 } // namespace gfx | 1540 } // namespace gfx |
| OLD | NEW |