| 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 | 8 |
| 9 #include "base/i18n/bidi_line_iterator.h" | 9 #include "base/i18n/bidi_line_iterator.h" |
| 10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
| (...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 return; | 1146 return; |
| 1147 } | 1147 } |
| 1148 | 1148 |
| 1149 // Temporarily apply composition underlines and selection colors. | 1149 // Temporarily apply composition underlines and selection colors. |
| 1150 ApplyCompositionAndSelectionStyles(); | 1150 ApplyCompositionAndSelectionStyles(); |
| 1151 | 1151 |
| 1152 // Build the run list from the script items and ranged styles and baselines. | 1152 // Build the run list from the script items and ranged styles and baselines. |
| 1153 // Use an empty color BreakList to avoid breaking runs at color boundaries. | 1153 // Use an empty color BreakList to avoid breaking runs at color boundaries. |
| 1154 BreakList<SkColor> empty_colors; | 1154 BreakList<SkColor> empty_colors; |
| 1155 empty_colors.SetMax(text.length()); | 1155 empty_colors.SetMax(text.length()); |
| 1156 internal::StyleIterator style(empty_colors, baselines(), styles()); | 1156 internal::StyleIterator style(font_sizes(), empty_colors, baselines(), |
| 1157 styles()); |
| 1157 | 1158 |
| 1158 for (size_t run_break = 0; run_break < text.length();) { | 1159 for (size_t run_break = 0; run_break < text.length();) { |
| 1159 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; | 1160 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; |
| 1160 run->range.set_start(run_break); | 1161 run->range.set_start(run_break); |
| 1161 run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | | 1162 run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | |
| 1162 (style.style(ITALIC) ? Font::ITALIC : 0); | 1163 (style.style(ITALIC) ? Font::ITALIC : 0); |
| 1164 run->font_size = style.font_size(); |
| 1163 run->baseline_type = style.baseline(); | 1165 run->baseline_type = style.baseline(); |
| 1164 run->strike = style.style(STRIKE); | 1166 run->strike = style.style(STRIKE); |
| 1165 run->diagonal_strike = style.style(DIAGONAL_STRIKE); | 1167 run->diagonal_strike = style.style(DIAGONAL_STRIKE); |
| 1166 run->underline = style.style(UNDERLINE); | 1168 run->underline = style.style(UNDERLINE); |
| 1167 int32 script_item_break = 0; | 1169 int32 script_item_break = 0; |
| 1168 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); | 1170 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); |
| 1169 // Odd BiDi embedding levels correspond to RTL runs. | 1171 // Odd BiDi embedding levels correspond to RTL runs. |
| 1170 run->is_rtl = (run->level % 2) == 1; | 1172 run->is_rtl = (run->level % 2) == 1; |
| 1171 // Find the length and script of this script run. | 1173 // Find the length and script of this script run. |
| 1172 script_item_break = ScriptInterval(text, run_break, | 1174 script_item_break = ScriptInterval(text, run_break, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 internal::TextRunList* run_list) { | 1223 internal::TextRunList* run_list) { |
| 1222 for (auto* run : run_list->runs()) | 1224 for (auto* run : run_list->runs()) |
| 1223 ShapeRun(text, run); | 1225 ShapeRun(text, run); |
| 1224 run_list->ComputePrecedingRunWidths(); | 1226 run_list->ComputePrecedingRunWidths(); |
| 1225 } | 1227 } |
| 1226 | 1228 |
| 1227 void RenderTextHarfBuzz::ShapeRun(const base::string16& text, | 1229 void RenderTextHarfBuzz::ShapeRun(const base::string16& text, |
| 1228 internal::TextRunHarfBuzz* run) { | 1230 internal::TextRunHarfBuzz* run) { |
| 1229 const Font& primary_font = font_list().GetPrimaryFont(); | 1231 const Font& primary_font = font_list().GetPrimaryFont(); |
| 1230 const std::string primary_family = primary_font.GetFontName(); | 1232 const std::string primary_family = primary_font.GetFontName(); |
| 1231 run->font_size = primary_font.GetFontSize(); | 1233 if (run->font_size == 0) |
| 1234 run->font_size = primary_font.GetFontSize(); |
| 1232 run->baseline_offset = 0; | 1235 run->baseline_offset = 0; |
| 1233 if (run->baseline_type != NORMAL_BASELINE) { | 1236 if (run->baseline_type != NORMAL_BASELINE) { |
| 1234 // Calculate a slightly smaller font. The ratio here is somewhat arbitrary. | 1237 // Calculate a slightly smaller font. The ratio here is somewhat arbitrary. |
| 1235 // Proportions from 5/9 to 5/7 all look pretty good. | 1238 // Proportions from 5/9 to 5/7 all look pretty good. |
| 1236 const float ratio = 5.0f / 9.0f; | 1239 const float ratio = 5.0f / 9.0f; |
| 1237 run->font_size = gfx::ToRoundedInt(primary_font.GetFontSize() * ratio); | 1240 run->font_size = gfx::ToRoundedInt(primary_font.GetFontSize() * ratio); |
| 1238 switch (run->baseline_type) { | 1241 switch (run->baseline_type) { |
| 1239 case SUPERSCRIPT: | 1242 case SUPERSCRIPT: |
| 1240 run->baseline_offset = | 1243 run->baseline_offset = |
| 1241 primary_font.GetCapHeight() - primary_font.GetHeight(); | 1244 primary_font.GetCapHeight() - primary_font.GetHeight(); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 DCHECK(!update_layout_run_list_); | 1522 DCHECK(!update_layout_run_list_); |
| 1520 DCHECK(!update_display_run_list_); | 1523 DCHECK(!update_display_run_list_); |
| 1521 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1524 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
| 1522 } | 1525 } |
| 1523 | 1526 |
| 1524 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1527 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
| 1525 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1528 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
| 1526 } | 1529 } |
| 1527 | 1530 |
| 1528 } // namespace gfx | 1531 } // namespace gfx |
| OLD | NEW |