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

Unified Diff: ui/gfx/render_text_harfbuzz.cc

Issue 1037863002: Remove the code which sorts and removes duplicates from the fallback font list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c139b92a950501bec20709fd32918d6e49e0b571 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;
+ }
+};
+
} // namespace
namespace internal {
@@ -1306,18 +1314,8 @@ 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_fonts;
// Try shaping with the fallback fonts.
for (const auto& family : fallback_families) {
@@ -1327,6 +1325,12 @@ void RenderTextHarfBuzz::ShapeRun(const base::string16& text,
if (family == uniscribe_family)
continue;
#endif
+ if (duplicate_fallback_fonts.find(family) !=
+ duplicate_fallback_fonts.end())
msw 2015/03/25 23:42:07 nit: fits on line above.
ananta 2015/03/25 23:47:27 Done.
+ continue;
+
+ duplicate_fallback_fonts.insert(family);
+
FontRenderParamsQuery query(false);
query.families.push_back(family);
query.pixel_size = run->font_size;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698