Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: ui/gfx/render_text_harfbuzz.cc

Issue 2927953003: Use CTFontCreateForString for RenderTextHarfbuzz on Mac (Closed)
Patch Set: Fix views::Label tests Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/font_fallback_win.cc ('k') | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 std::string preferred_fallback_family;
1508
1509 #if defined(OS_WIN) || defined(OS_MACOSX)
1512 Font fallback_font(primary_font); 1510 Font fallback_font(primary_font);
1513 std::string fallback_family;
1514 const base::char16* run_text = &(text[run->range.start()]); 1511 const base::char16* run_text = &(text[run->range.start()]);
1515 if (GetFallbackFont(primary_font, run_text, run->range.length(), 1512 if (GetFallbackFont(primary_font, run_text, run->range.length(),
1516 &fallback_font)) { 1513 &fallback_font)) {
1517 fallback_family = fallback_font.GetFontName(); 1514 preferred_fallback_family = fallback_font.GetFontName();
1518 if (CompareFamily(text, fallback_font, fallback_font.GetFontRenderParams(), 1515 if (CompareFamily(text, fallback_font, fallback_font.GetFontRenderParams(),
1519 run, &best_font, &best_render_params, 1516 run, &best_font, &best_render_params,
1520 &best_missing_glyphs)) 1517 &best_missing_glyphs))
1521 return; 1518 return;
1522 } 1519 }
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() ||
1556 font_name == preferred_fallback_family || fallback_fonts.count(font)) {
1557 continue; 1557 continue;
1558 #if defined(OS_WIN) 1558 }
1559 if (font_name == fallback_family)
1560 continue;
1561 #endif
1562 if (fallback_fonts.find(font) != fallback_fonts.end())
1563 continue;
1564 1559
1565 fallback_fonts.insert(font); 1560 fallback_fonts.insert(font);
1566 1561
1567 FontRenderParamsQuery query; 1562 FontRenderParamsQuery query;
1568 query.families.push_back(font_name); 1563 query.families.push_back(font_name);
1569 query.pixel_size = run->font_size; 1564 query.pixel_size = run->font_size;
1570 query.style = run->italic ? Font::ITALIC : 0; 1565 query.style = run->italic ? Font::ITALIC : 0;
1571 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); 1566 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL);
1572 if (CompareFamily(text, font, fallback_render_params, run, &best_font, 1567 if (CompareFamily(text, font, fallback_render_params, run, &best_font,
1573 &best_render_params, &best_missing_glyphs)) 1568 &best_render_params, &best_missing_glyphs))
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 1722
1728 attribute.strike = run.strike; 1723 attribute.strike = run.strike;
1729 attribute.diagonal_strike = run.diagonal_strike; 1724 attribute.diagonal_strike = run.diagonal_strike;
1730 decorated_text->attributes.push_back(attribute); 1725 decorated_text->attributes.push_back(attribute);
1731 } 1726 }
1732 } 1727 }
1733 return true; 1728 return true;
1734 } 1729 }
1735 1730
1736 } // namespace gfx 1731 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/font_fallback_win.cc ('k') | ui/views/controls/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698