Chromium Code Reviews| 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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "ui/gfx/font.h" | 29 #include "ui/gfx/font.h" |
| 30 #include "ui/gfx/font_fallback.h" | 30 #include "ui/gfx/font_fallback.h" |
| 31 #include "ui/gfx/font_render_params.h" | 31 #include "ui/gfx/font_render_params.h" |
| 32 #include "ui/gfx/geometry/safe_integer_conversions.h" | 32 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 33 #include "ui/gfx/harfbuzz_font_skia.h" | 33 #include "ui/gfx/harfbuzz_font_skia.h" |
| 34 #include "ui/gfx/range/range_f.h" | 34 #include "ui/gfx/range/range_f.h" |
| 35 #include "ui/gfx/skia_util.h" | 35 #include "ui/gfx/skia_util.h" |
| 36 #include "ui/gfx/text_utils.h" | 36 #include "ui/gfx/text_utils.h" |
| 37 #include "ui/gfx/utf16_indexing.h" | 37 #include "ui/gfx/utf16_indexing.h" |
| 38 | 38 |
| 39 #if defined(OS_WIN) | |
| 40 #include "ui/gfx/font_fallback_win.h" | |
| 41 #endif | |
| 42 | |
| 43 namespace gfx { | 39 namespace gfx { |
| 44 | 40 |
| 45 namespace { | 41 namespace { |
| 46 | 42 |
| 47 // Text length limit. Longer strings are slow and not fully tested. | 43 // Text length limit. Longer strings are slow and not fully tested. |
| 48 const size_t kMaxTextLength = 10000; | 44 const size_t kMaxTextLength = 10000; |
| 49 | 45 |
| 50 // The maximum number of scripts a Unicode character can belong to. This value | 46 // The maximum number of scripts a Unicode character can belong to. This value |
| 51 // is arbitrarily chosen to be a good limit because it is unlikely for a single | 47 // is arbitrarily chosen to be a good limit because it is unlikely for a single |
| 52 // character to belong to more scripts. | 48 // character to belong to more scripts. |
| (...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1501 Font best_font(primary_font); | 1497 Font best_font(primary_font); |
| 1502 FontRenderParams best_render_params; | 1498 FontRenderParams best_render_params; |
| 1503 size_t best_missing_glyphs = std::numeric_limits<size_t>::max(); | 1499 size_t best_missing_glyphs = std::numeric_limits<size_t>::max(); |
| 1504 | 1500 |
| 1505 for (const Font& font : font_list().GetFonts()) { | 1501 for (const Font& font : font_list().GetFonts()) { |
| 1506 if (CompareFamily(text, font, font.GetFontRenderParams(), run, &best_font, | 1502 if (CompareFamily(text, font, font.GetFontRenderParams(), run, &best_font, |
| 1507 &best_render_params, &best_missing_glyphs)) | 1503 &best_render_params, &best_missing_glyphs)) |
| 1508 return; | 1504 return; |
| 1509 } | 1505 } |
| 1510 | 1506 |
| 1511 #if defined(OS_WIN) | 1507 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 1512 Font fallback_font(primary_font); | 1508 Font fallback_font(primary_font); |
| 1513 std::string fallback_family; | 1509 std::string preferred_fallback_family; |
| 1514 const base::char16* run_text = &(text[run->range.start()]); | 1510 const base::char16* run_text = &(text[run->range.start()]); |
| 1515 if (GetFallbackFont(primary_font, run_text, run->range.length(), | 1511 if (GetFallbackFont(primary_font, run_text, run->range.length(), |
| 1516 &fallback_font)) { | 1512 &fallback_font)) { |
| 1517 fallback_family = fallback_font.GetFontName(); | 1513 preferred_fallback_family = fallback_font.GetFontName(); |
| 1518 if (CompareFamily(text, fallback_font, fallback_font.GetFontRenderParams(), | 1514 if (CompareFamily(text, fallback_font, fallback_font.GetFontRenderParams(), |
| 1519 run, &best_font, &best_render_params, | 1515 run, &best_font, &best_render_params, |
| 1520 &best_missing_glyphs)) | 1516 &best_missing_glyphs)) |
| 1521 return; | 1517 return; |
| 1522 } | 1518 } |
| 1519 | |
|
Alexei Svitkine (slow)
2017/06/20 14:59:34
Nit: Remove empty line.
tapted
2017/06/20 23:52:57
Done.
| |
| 1523 #endif | 1520 #endif |
| 1524 | 1521 |
| 1525 std::vector<Font> fallback_font_list = GetFallbackFonts(primary_font); | 1522 std::vector<Font> fallback_font_list = GetFallbackFonts(primary_font); |
| 1526 | 1523 |
| 1527 #if defined(OS_WIN) | 1524 #if defined(OS_WIN) |
| 1528 // Append fonts in the fallback list of the fallback font. | 1525 // Append fonts in the fallback list of the preferred fallback font. |
| 1529 if (!fallback_family.empty()) { | 1526 // TODO(tapted): Investigate whether there's a case that benefits from this on |
| 1527 // Mac. | |
| 1528 if (!preferred_fallback_family.empty()) { | |
| 1530 std::vector<Font> fallback_fonts = GetFallbackFonts(fallback_font); | 1529 std::vector<Font> fallback_fonts = GetFallbackFonts(fallback_font); |
| 1531 fallback_font_list.insert(fallback_font_list.end(), fallback_fonts.begin(), | 1530 fallback_font_list.insert(fallback_font_list.end(), fallback_fonts.begin(), |
| 1532 fallback_fonts.end()); | 1531 fallback_fonts.end()); |
| 1533 } | 1532 } |
| 1534 | 1533 |
| 1535 // Add Segoe UI and its associated linked fonts to the fallback font list to | 1534 // Add Segoe UI and its associated linked fonts to the fallback font list to |
| 1536 // ensure that the fallback list covers the basic cases. | 1535 // ensure that the fallback list covers the basic cases. |
| 1537 // http://crbug.com/467459. On some Windows configurations the default font | 1536 // http://crbug.com/467459. On some Windows configurations the default font |
| 1538 // could be a raster font like System, which would not give us a reasonable | 1537 // could be a raster font like System, which would not give us a reasonable |
| 1539 // fallback font list. | 1538 // fallback font list. |
| 1540 if (!base::LowerCaseEqualsASCII(primary_font.GetFontName(), "segoe ui") && | 1539 if (!base::LowerCaseEqualsASCII(primary_font.GetFontName(), "segoe ui") && |
| 1541 !base::LowerCaseEqualsASCII(fallback_family, "segoe ui")) { | 1540 !base::LowerCaseEqualsASCII(preferred_fallback_family, "segoe ui")) { |
| 1542 std::vector<Font> default_fallback_families = | 1541 std::vector<Font> default_fallback_families = |
| 1543 GetFallbackFonts(Font("Segoe UI", 13)); | 1542 GetFallbackFonts(Font("Segoe UI", 13)); |
| 1544 fallback_font_list.insert(fallback_font_list.end(), | 1543 fallback_font_list.insert(fallback_font_list.end(), |
| 1545 default_fallback_families.begin(), default_fallback_families.end()); | 1544 default_fallback_families.begin(), default_fallback_families.end()); |
| 1546 } | 1545 } |
| 1547 #endif | 1546 #endif |
| 1548 | 1547 |
| 1549 // Use a set to track the fallback fonts and avoid duplicate entries. | 1548 // Use a set to track the fallback fonts and avoid duplicate entries. |
| 1550 std::set<Font, CaseInsensitiveCompare> fallback_fonts; | 1549 std::set<Font, CaseInsensitiveCompare> fallback_fonts; |
| 1551 | 1550 |
| 1552 // Try shaping with the fallback fonts. | 1551 // Try shaping with the fallback fonts. |
| 1553 for (const auto& font : fallback_font_list) { | 1552 for (const auto& font : fallback_font_list) { |
| 1554 std::string font_name = font.GetFontName(); | 1553 std::string font_name = font.GetFontName(); |
| 1555 | 1554 |
| 1556 if (font_name == primary_font.GetFontName()) | 1555 if (font_name == primary_font.GetFontName()) |
| 1557 continue; | 1556 continue; |
| 1558 #if defined(OS_WIN) | 1557 #if defined(OS_WIN) || defined(OS_MACOSX) |
|
Alexei Svitkine (slow)
2017/06/20 14:59:34
Nit: Suggest moving preferred_fallback_family outs
tapted
2017/06/20 23:52:57
Nice - Done. Collapsed the 3 `if`.
| |
| 1559 if (font_name == fallback_family) | 1558 if (font_name == preferred_fallback_family) |
| 1560 continue; | 1559 continue; |
| 1561 #endif | 1560 #endif |
| 1562 if (fallback_fonts.find(font) != fallback_fonts.end()) | 1561 if (fallback_fonts.find(font) != fallback_fonts.end()) |
| 1563 continue; | 1562 continue; |
| 1564 | 1563 |
| 1565 fallback_fonts.insert(font); | 1564 fallback_fonts.insert(font); |
| 1566 | 1565 |
| 1567 FontRenderParamsQuery query; | 1566 FontRenderParamsQuery query; |
| 1568 query.families.push_back(font_name); | 1567 query.families.push_back(font_name); |
| 1569 query.pixel_size = run->font_size; | 1568 query.pixel_size = run->font_size; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1727 | 1726 |
| 1728 attribute.strike = run.strike; | 1727 attribute.strike = run.strike; |
| 1729 attribute.diagonal_strike = run.diagonal_strike; | 1728 attribute.diagonal_strike = run.diagonal_strike; |
| 1730 decorated_text->attributes.push_back(attribute); | 1729 decorated_text->attributes.push_back(attribute); |
| 1731 } | 1730 } |
| 1732 } | 1731 } |
| 1733 return true; | 1732 return true; |
| 1734 } | 1733 } |
| 1735 | 1734 |
| 1736 } // namespace gfx | 1735 } // namespace gfx |
| OLD | NEW |