Chromium Code Reviews| Index: ui/gfx/render_text_harfbuzz.cc |
| diff --git a/ui/gfx/render_text_harfbuzz.cc b/ui/gfx/render_text_harfbuzz.cc |
| index 63b0e4e0cd79d009e83cb9989e680f987def1e06..2ade7510200be63e59909902129d4fe66a8a206d 100644 |
| --- a/ui/gfx/render_text_harfbuzz.cc |
| +++ b/ui/gfx/render_text_harfbuzz.cc |
| @@ -5,6 +5,7 @@ |
| #include "ui/gfx/render_text_harfbuzz.h" |
| #include <limits> |
| +#include <set> |
| #include "base/i18n/bidi_line_iterator.h" |
| #include "base/i18n/break_iterator.h" |
| @@ -467,6 +468,13 @@ class HarfBuzzLineBreaker { |
| DISALLOW_COPY_AND_ASSIGN(HarfBuzzLineBreaker); |
| }; |
| +// Function object for case insensitive string comparison. |
| +struct CaseInsensitiveCompare { |
| + bool operator() (const std::string& a, const std::string& b) const { |
| + return base::strncasecmp(a.c_str(), b.c_str(), b.length()) < 0; |
|
msw
2015/03/25 23:23:42
Will strncasecmp work if a.length() != b.length()?
ananta
2015/03/25 23:39:49
It should. As per docs, it compares upto count cha
|
| + } |
| +}; |
| + |
| } // namespace |
| namespace internal { |
| @@ -1306,18 +1314,9 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text, |
| } |
| #endif |
| - // Get rid of duplicate fonts in the fallback list. We use the std::unique |
| - // algorithm for this. However for this function to work we need to sort |
| - // the font list as the unique algorithm relies on duplicates being adjacent. |
| - // TODO(ananta) |
| - // Sorting the list changes the order in which fonts are evaluated. This may |
| - // cause problems in the way some characters appear. It may be best to do |
| - // font fallback on the same lines as blink or skia which do this based on |
| - // character glyph mapping. |
| - std::sort(fallback_families.begin(), fallback_families.end()); |
| - fallback_families.erase(std::unique( |
| - fallback_families.begin(), fallback_families.end()), |
| - fallback_families.end()); |
| + // Use a set to track the fallback fonts and avoid duplicate entries. |
| + std::set<std::string, CaseInsensitiveCompare> |
| + duplicate_fallback_font_tracker; |
|
msw
2015/03/25 23:23:42
optional nit: rename |tried_fallback_fonts| or sim
ananta
2015/03/25 23:39:49
Renamed to duplicate_fallback_fonts
msw
2015/03/25 23:42:06
Eh, they aren't duplicate themselves... the name |
|
| // Try shaping with the fallback fonts. |
| for (const auto& family : fallback_families) { |
| @@ -1327,6 +1326,12 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text, |
| if (family == uniscribe_family) |
| continue; |
| #endif |
| + if (duplicate_fallback_font_tracker.find(family) != |
| + duplicate_fallback_font_tracker.end()) |
| + continue; |
| + |
| + duplicate_fallback_font_tracker.insert(family); |
| + |
| FontRenderParamsQuery query(false); |
| query.families.push_back(family); |
| query.pixel_size = run->font_size; |