Commit 46b2013e authored by ananta's avatar ananta Committed by Commit bot

Remove the code which sorts and removes duplicates from the fallback font list

This causes wrong fallback fonts to be picked leading to text displaying badly.

To avoid duplicate fonts from being processed, the proposal is to use a set to track those
and skip them.

BUG=470397

Review URL: https://codereview.chromium.org/1037863002

Cr-Commit-Position: refs/heads/master@{#322320}
parent cee6bbcd
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ui/gfx/render_text_harfbuzz.h" #include "ui/gfx/render_text_harfbuzz.h"
#include <limits> #include <limits>
#include <set>
#include "base/i18n/bidi_line_iterator.h" #include "base/i18n/bidi_line_iterator.h"
#include "base/i18n/break_iterator.h" #include "base/i18n/break_iterator.h"
...@@ -470,6 +471,13 @@ class HarfBuzzLineBreaker { ...@@ -470,6 +471,13 @@ class HarfBuzzLineBreaker {
DISALLOW_COPY_AND_ASSIGN(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;
}
};
} // namespace } // namespace
namespace internal { namespace internal {
...@@ -1309,18 +1317,8 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text, ...@@ -1309,18 +1317,8 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text,
} }
#endif #endif
// Get rid of duplicate fonts in the fallback list. We use the std::unique // Use a set to track the fallback fonts and avoid duplicate entries.
// algorithm for this. However for this function to work we need to sort std::set<std::string, CaseInsensitiveCompare> fallback_fonts;
// 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());
// Try shaping with the fallback fonts. // Try shaping with the fallback fonts.
for (const auto& family : fallback_families) { for (const auto& family : fallback_families) {
...@@ -1330,6 +1328,11 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text, ...@@ -1330,6 +1328,11 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text,
if (family == uniscribe_family) if (family == uniscribe_family)
continue; continue;
#endif #endif
if (fallback_fonts.find(family) != fallback_fonts.end())
continue;
fallback_fonts.insert(family);
FontRenderParamsQuery query(false); FontRenderParamsQuery query(false);
query.families.push_back(family); query.families.push_back(family);
query.pixel_size = run->font_size; query.pixel_size = run->font_size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment