| 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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 TextRunHarfBuzz::TextRunHarfBuzz() | 569 TextRunHarfBuzz::TextRunHarfBuzz() |
| 570 : width(0.0f), | 570 : width(0.0f), |
| 571 preceding_run_widths(0.0f), | 571 preceding_run_widths(0.0f), |
| 572 is_rtl(false), | 572 is_rtl(false), |
| 573 level(0), | 573 level(0), |
| 574 script(USCRIPT_INVALID_CODE), | 574 script(USCRIPT_INVALID_CODE), |
| 575 glyph_count(static_cast<size_t>(-1)), | 575 glyph_count(static_cast<size_t>(-1)), |
| 576 font_size(0), | 576 font_size(0), |
| 577 baseline_offset(0), | 577 baseline_offset(0), |
| 578 baseline_type(0), | 578 baseline_type(0), |
| 579 font_style(0), | 579 italic(false), |
| 580 weight(gfx::Font::Weight::NORMAL), |
| 580 strike(false), | 581 strike(false), |
| 581 diagonal_strike(false), | 582 diagonal_strike(false), |
| 582 underline(false) { | 583 underline(false) {} |
| 583 } | |
| 584 | 584 |
| 585 TextRunHarfBuzz::~TextRunHarfBuzz() {} | 585 TextRunHarfBuzz::~TextRunHarfBuzz() {} |
| 586 | 586 |
| 587 Range TextRunHarfBuzz::CharRangeToGlyphRange(const Range& char_range) const { | 587 Range TextRunHarfBuzz::CharRangeToGlyphRange(const Range& char_range) const { |
| 588 DCHECK(range.Contains(char_range)); | 588 DCHECK(range.Contains(char_range)); |
| 589 DCHECK(!char_range.is_reversed()); | 589 DCHECK(!char_range.is_reversed()); |
| 590 DCHECK(!char_range.is_empty()); | 590 DCHECK(!char_range.is_empty()); |
| 591 | 591 |
| 592 Range start_glyphs; | 592 Range start_glyphs; |
| 593 Range end_glyphs; | 593 Range end_glyphs; |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1253 // Temporarily apply composition underlines and selection colors. | 1253 // Temporarily apply composition underlines and selection colors. |
| 1254 ApplyCompositionAndSelectionStyles(); | 1254 ApplyCompositionAndSelectionStyles(); |
| 1255 | 1255 |
| 1256 // Build the run list from the script items and ranged styles and baselines. | 1256 // Build the run list from the script items and ranged styles and baselines. |
| 1257 // Use an empty color BreakList to avoid breaking runs at color boundaries. | 1257 // Use an empty color BreakList to avoid breaking runs at color boundaries. |
| 1258 BreakList<SkColor> empty_colors; | 1258 BreakList<SkColor> empty_colors; |
| 1259 empty_colors.SetMax(text.length()); | 1259 empty_colors.SetMax(text.length()); |
| 1260 DCHECK_LE(text.size(), baselines().max()); | 1260 DCHECK_LE(text.size(), baselines().max()); |
| 1261 for (const BreakList<bool>& style : styles()) | 1261 for (const BreakList<bool>& style : styles()) |
| 1262 DCHECK_LE(text.size(), style.max()); | 1262 DCHECK_LE(text.size(), style.max()); |
| 1263 internal::StyleIterator style(empty_colors, baselines(), styles()); | 1263 internal::StyleIterator style(empty_colors, baselines(), weights(), styles()); |
| 1264 | 1264 |
| 1265 for (size_t run_break = 0; run_break < text.length();) { | 1265 for (size_t run_break = 0; run_break < text.length();) { |
| 1266 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; | 1266 internal::TextRunHarfBuzz* run = new internal::TextRunHarfBuzz; |
| 1267 run->range.set_start(run_break); | 1267 run->range.set_start(run_break); |
| 1268 run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | | 1268 run->italic = style.style(ITALIC); |
| 1269 (style.style(ITALIC) ? Font::ITALIC : 0); | |
| 1270 run->baseline_type = style.baseline(); | 1269 run->baseline_type = style.baseline(); |
| 1271 run->strike = style.style(STRIKE); | 1270 run->strike = style.style(STRIKE); |
| 1272 run->diagonal_strike = style.style(DIAGONAL_STRIKE); | 1271 run->diagonal_strike = style.style(DIAGONAL_STRIKE); |
| 1273 run->underline = style.style(UNDERLINE); | 1272 run->underline = style.style(UNDERLINE); |
| 1273 run->weight = style.weight(); |
| 1274 int32_t script_item_break = 0; | 1274 int32_t script_item_break = 0; |
| 1275 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); | 1275 bidi_iterator.GetLogicalRun(run_break, &script_item_break, &run->level); |
| 1276 CHECK_GT(static_cast<size_t>(script_item_break), run_break); | 1276 CHECK_GT(static_cast<size_t>(script_item_break), run_break); |
| 1277 // Odd BiDi embedding levels correspond to RTL runs. | 1277 // Odd BiDi embedding levels correspond to RTL runs. |
| 1278 run->is_rtl = (run->level % 2) == 1; | 1278 run->is_rtl = (run->level % 2) == 1; |
| 1279 // Find the length and script of this script run. | 1279 // Find the length and script of this script run. |
| 1280 script_item_break = ScriptInterval(text, run_break, | 1280 script_item_break = ScriptInterval(text, run_break, |
| 1281 script_item_break - run_break, &run->script) + run_break; | 1281 script_item_break - run_break, &run->script) + run_break; |
| 1282 | 1282 |
| 1283 // Find the next break and advance the iterators as needed. | 1283 // Find the next break and advance the iterators as needed. |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 continue; | 1428 continue; |
| 1429 #endif | 1429 #endif |
| 1430 if (fallback_fonts.find(font) != fallback_fonts.end()) | 1430 if (fallback_fonts.find(font) != fallback_fonts.end()) |
| 1431 continue; | 1431 continue; |
| 1432 | 1432 |
| 1433 fallback_fonts.insert(font); | 1433 fallback_fonts.insert(font); |
| 1434 | 1434 |
| 1435 FontRenderParamsQuery query; | 1435 FontRenderParamsQuery query; |
| 1436 query.families.push_back(font_name); | 1436 query.families.push_back(font_name); |
| 1437 query.pixel_size = run->font_size; | 1437 query.pixel_size = run->font_size; |
| 1438 query.style = run->font_style; | 1438 query.style = run->italic ? gfx::Font::ITALIC : 0; |
| 1439 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); | 1439 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); |
| 1440 if (CompareFamily(text, font, fallback_render_params, run, &best_font, | 1440 if (CompareFamily(text, font, fallback_render_params, run, &best_font, |
| 1441 &best_render_params, &best_missing_glyphs)) | 1441 &best_render_params, &best_missing_glyphs)) |
| 1442 return; | 1442 return; |
| 1443 } | 1443 } |
| 1444 | 1444 |
| 1445 if (best_missing_glyphs != std::numeric_limits<size_t>::max() && | 1445 if (best_missing_glyphs != std::numeric_limits<size_t>::max() && |
| 1446 (best_font.GetFontName() == run->font.GetFontName() || | 1446 (best_font.GetFontName() == run->font.GetFontName() || |
| 1447 ShapeRunWithFont(text, best_font, best_render_params, run))) | 1447 ShapeRunWithFont(text, best_font, best_render_params, run))) |
| 1448 return; | 1448 return; |
| 1449 | 1449 |
| 1450 run->glyph_count = 0; | 1450 run->glyph_count = 0; |
| 1451 run->width = 0.0f; | 1451 run->width = 0.0f; |
| 1452 } | 1452 } |
| 1453 | 1453 |
| 1454 bool RenderTextHarfBuzz::ShapeRunWithFont(const base::string16& text, | 1454 bool RenderTextHarfBuzz::ShapeRunWithFont(const base::string16& text, |
| 1455 const gfx::Font& font, | 1455 const gfx::Font& font, |
| 1456 const FontRenderParams& params, | 1456 const FontRenderParams& params, |
| 1457 internal::TextRunHarfBuzz* run) { | 1457 internal::TextRunHarfBuzz* run) { |
| 1458 skia::RefPtr<SkTypeface> skia_face = | 1458 skia::RefPtr<SkTypeface> skia_face = |
| 1459 internal::CreateSkiaTypeface(font, run->font_style); | 1459 internal::CreateSkiaTypeface(font, run->italic, run->weight); |
| 1460 if (skia_face == NULL) | 1460 if (skia_face == NULL) |
| 1461 return false; | 1461 return false; |
| 1462 run->skia_face = skia_face; | 1462 run->skia_face = skia_face; |
| 1463 run->font = font; | 1463 run->font = font; |
| 1464 run->render_params = params; | 1464 run->render_params = params; |
| 1465 | 1465 |
| 1466 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( | 1466 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( |
| 1467 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params, | 1467 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params, |
| 1468 subpixel_rendering_suppressed()); | 1468 subpixel_rendering_suppressed()); |
| 1469 | 1469 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 DCHECK(!update_layout_run_list_); | 1567 DCHECK(!update_layout_run_list_); |
| 1568 DCHECK(!update_display_run_list_); | 1568 DCHECK(!update_display_run_list_); |
| 1569 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1569 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
| 1570 } | 1570 } |
| 1571 | 1571 |
| 1572 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1572 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
| 1573 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1573 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
| 1574 } | 1574 } |
| 1575 | 1575 |
| 1576 } // namespace gfx | 1576 } // namespace gfx |
| OLD | NEW |