| 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 1375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 FontRenderParams best_render_params; | 1386 FontRenderParams best_render_params; |
| 1387 size_t best_missing_glyphs = std::numeric_limits<size_t>::max(); | 1387 size_t best_missing_glyphs = std::numeric_limits<size_t>::max(); |
| 1388 | 1388 |
| 1389 for (const Font& font : font_list().GetFonts()) { | 1389 for (const Font& font : font_list().GetFonts()) { |
| 1390 if (CompareFamily(text, font, font.GetFontRenderParams(), run, &best_font, | 1390 if (CompareFamily(text, font, font.GetFontRenderParams(), run, &best_font, |
| 1391 &best_render_params, &best_missing_glyphs)) | 1391 &best_render_params, &best_missing_glyphs)) |
| 1392 return; | 1392 return; |
| 1393 } | 1393 } |
| 1394 | 1394 |
| 1395 #if defined(OS_WIN) | 1395 #if defined(OS_WIN) |
| 1396 Font uniscribe_font(primary_font); | 1396 Font fallback_font(primary_font); |
| 1397 std::string uniscribe_family; | 1397 std::string fallback_family; |
| 1398 const base::char16* run_text = &(text[run->range.start()]); | 1398 const base::char16* run_text = &(text[run->range.start()]); |
| 1399 if (GetUniscribeFallbackFont(primary_font, run_text, run->range.length(), | 1399 if (GetFallbackFont(primary_font, run_text, run->range.length(), |
| 1400 &uniscribe_font)) { | 1400 &fallback_font)) { |
| 1401 uniscribe_family = uniscribe_font.GetFontName(); | 1401 fallback_family = fallback_font.GetFontName(); |
| 1402 if (CompareFamily(text, uniscribe_font, | 1402 if (CompareFamily(text, fallback_font, fallback_font.GetFontRenderParams(), |
| 1403 uniscribe_font.GetFontRenderParams(), run, | 1403 run, &best_font, &best_render_params, |
| 1404 &best_font, &best_render_params, &best_missing_glyphs)) | 1404 &best_missing_glyphs)) |
| 1405 return; | 1405 return; |
| 1406 } | 1406 } |
| 1407 #endif | 1407 #endif |
| 1408 | 1408 |
| 1409 std::vector<Font> fallback_font_list = GetFallbackFonts(primary_font); | 1409 std::vector<Font> fallback_font_list = GetFallbackFonts(primary_font); |
| 1410 | 1410 |
| 1411 #if defined(OS_WIN) | 1411 #if defined(OS_WIN) |
| 1412 // Append fonts in the fallback list of the Uniscribe font. | 1412 // Append fonts in the fallback list of the fallback font. |
| 1413 if (!uniscribe_family.empty()) { | 1413 if (!fallback_family.empty()) { |
| 1414 std::vector<Font> uniscribe_fallbacks = GetFallbackFonts(uniscribe_font); | 1414 std::vector<Font> fallback_fonts = GetFallbackFonts(fallback_font); |
| 1415 fallback_font_list.insert(fallback_font_list.end(), | 1415 fallback_font_list.insert(fallback_font_list.end(), fallback_fonts.begin(), |
| 1416 uniscribe_fallbacks.begin(), uniscribe_fallbacks.end()); | 1416 fallback_fonts.end()); |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 // Add Segoe UI and its associated linked fonts to the fallback font list to | 1419 // Add Segoe UI and its associated linked fonts to the fallback font list to |
| 1420 // ensure that the fallback list covers the basic cases. | 1420 // ensure that the fallback list covers the basic cases. |
| 1421 // http://crbug.com/467459. On some Windows configurations the default font | 1421 // http://crbug.com/467459. On some Windows configurations the default font |
| 1422 // could be a raster font like System, which would not give us a reasonable | 1422 // could be a raster font like System, which would not give us a reasonable |
| 1423 // fallback font list. | 1423 // fallback font list. |
| 1424 if (!base::LowerCaseEqualsASCII(primary_font.GetFontName(), "segoe ui") && | 1424 if (!base::LowerCaseEqualsASCII(primary_font.GetFontName(), "segoe ui") && |
| 1425 !base::LowerCaseEqualsASCII(uniscribe_family, "segoe ui")) { | 1425 !base::LowerCaseEqualsASCII(fallback_family, "segoe ui")) { |
| 1426 std::vector<Font> default_fallback_families = | 1426 std::vector<Font> default_fallback_families = |
| 1427 GetFallbackFonts(Font("Segoe UI", 13)); | 1427 GetFallbackFonts(Font("Segoe UI", 13)); |
| 1428 fallback_font_list.insert(fallback_font_list.end(), | 1428 fallback_font_list.insert(fallback_font_list.end(), |
| 1429 default_fallback_families.begin(), default_fallback_families.end()); | 1429 default_fallback_families.begin(), default_fallback_families.end()); |
| 1430 } | 1430 } |
| 1431 #endif | 1431 #endif |
| 1432 | 1432 |
| 1433 // Use a set to track the fallback fonts and avoid duplicate entries. | 1433 // Use a set to track the fallback fonts and avoid duplicate entries. |
| 1434 std::set<Font, CaseInsensitiveCompare> fallback_fonts; | 1434 std::set<Font, CaseInsensitiveCompare> fallback_fonts; |
| 1435 | 1435 |
| 1436 // Try shaping with the fallback fonts. | 1436 // Try shaping with the fallback fonts. |
| 1437 for (const auto& font : fallback_font_list) { | 1437 for (const auto& font : fallback_font_list) { |
| 1438 std::string font_name = font.GetFontName(); | 1438 std::string font_name = font.GetFontName(); |
| 1439 | 1439 |
| 1440 if (font_name == primary_font.GetFontName()) | 1440 if (font_name == primary_font.GetFontName()) |
| 1441 continue; | 1441 continue; |
| 1442 #if defined(OS_WIN) | 1442 #if defined(OS_WIN) |
| 1443 if (font_name == uniscribe_family) | 1443 if (font_name == fallback_family) |
| 1444 continue; | 1444 continue; |
| 1445 #endif | 1445 #endif |
| 1446 if (fallback_fonts.find(font) != fallback_fonts.end()) | 1446 if (fallback_fonts.find(font) != fallback_fonts.end()) |
| 1447 continue; | 1447 continue; |
| 1448 | 1448 |
| 1449 fallback_fonts.insert(font); | 1449 fallback_fonts.insert(font); |
| 1450 | 1450 |
| 1451 FontRenderParamsQuery query; | 1451 FontRenderParamsQuery query; |
| 1452 query.families.push_back(font_name); | 1452 query.families.push_back(font_name); |
| 1453 query.pixel_size = run->font_size; | 1453 query.pixel_size = run->font_size; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 DCHECK(!update_layout_run_list_); | 1584 DCHECK(!update_layout_run_list_); |
| 1585 DCHECK(!update_display_run_list_); | 1585 DCHECK(!update_display_run_list_); |
| 1586 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1586 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
| 1587 } | 1587 } |
| 1588 | 1588 |
| 1589 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1589 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
| 1590 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1590 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
| 1591 } | 1591 } |
| 1592 | 1592 |
| 1593 } // namespace gfx | 1593 } // namespace gfx |
| OLD | NEW |