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

Side by Side 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: Add case insensitive comparison functionality to the set Created 5 years, 8 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 | « no previous file | no next file » | 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 9
9 #include "base/i18n/bidi_line_iterator.h" 10 #include "base/i18n/bidi_line_iterator.h"
10 #include "base/i18n/break_iterator.h" 11 #include "base/i18n/break_iterator.h"
11 #include "base/i18n/char_iterator.h" 12 #include "base/i18n/char_iterator.h"
12 #include "base/profiler/scoped_tracker.h" 13 #include "base/profiler/scoped_tracker.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
16 #include "third_party/harfbuzz-ng/src/hb.h" 17 #include "third_party/harfbuzz-ng/src/hb.h"
17 #include "third_party/icu/source/common/unicode/ubidi.h" 18 #include "third_party/icu/source/common/unicode/ubidi.h"
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 461
461 // Size of the multiline text, not including the currently processed line. 462 // Size of the multiline text, not including the currently processed line.
462 SizeF total_size_; 463 SizeF total_size_;
463 464
464 // The current RTL run segments, to be applied by |UpdateRTLSegmentRanges()|. 465 // The current RTL run segments, to be applied by |UpdateRTLSegmentRanges()|.
465 std::vector<SegmentHandle> rtl_segments_; 466 std::vector<SegmentHandle> rtl_segments_;
466 467
467 DISALLOW_COPY_AND_ASSIGN(HarfBuzzLineBreaker); 468 DISALLOW_COPY_AND_ASSIGN(HarfBuzzLineBreaker);
468 }; 469 };
469 470
471 // Function object for case insensitive string comparison.
472 struct CaseInsensitiveCompare {
473 bool operator() (const std::string& a, const std::string& b) const {
474 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
475 }
476 };
477
470 } // namespace 478 } // namespace
471 479
472 namespace internal { 480 namespace internal {
473 481
474 Range RoundRangeF(const RangeF& range_f) { 482 Range RoundRangeF(const RangeF& range_f) {
475 return Range(std::floor(range_f.start() + 0.5f), 483 return Range(std::floor(range_f.start() + 0.5f),
476 std::floor(range_f.end() + 0.5f)); 484 std::floor(range_f.end() + 0.5f));
477 } 485 }
478 486
479 TextRunHarfBuzz::TextRunHarfBuzz() 487 TextRunHarfBuzz::TextRunHarfBuzz()
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 // fallback font list. 1307 // fallback font list.
1300 if (!LowerCaseEqualsASCII(primary_family, "segoe ui") && 1308 if (!LowerCaseEqualsASCII(primary_family, "segoe ui") &&
1301 !LowerCaseEqualsASCII(uniscribe_family, "segoe ui")) { 1309 !LowerCaseEqualsASCII(uniscribe_family, "segoe ui")) {
1302 std::vector<std::string> default_fallback_families = 1310 std::vector<std::string> default_fallback_families =
1303 GetFallbackFontFamilies("Segoe UI"); 1311 GetFallbackFontFamilies("Segoe UI");
1304 fallback_families.insert(fallback_families.end(), 1312 fallback_families.insert(fallback_families.end(),
1305 default_fallback_families.begin(), default_fallback_families.end()); 1313 default_fallback_families.begin(), default_fallback_families.end());
1306 } 1314 }
1307 #endif 1315 #endif
1308 1316
1309 // Get rid of duplicate fonts in the fallback list. We use the std::unique 1317 // Use a set to track the fallback fonts and avoid duplicate entries.
1310 // algorithm for this. However for this function to work we need to sort 1318 std::set<std::string, CaseInsensitiveCompare>
1311 // the font list as the unique algorithm relies on duplicates being adjacent. 1319 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 |
1312 // TODO(ananta)
1313 // Sorting the list changes the order in which fonts are evaluated. This may
1314 // cause problems in the way some characters appear. It may be best to do
1315 // font fallback on the same lines as blink or skia which do this based on
1316 // character glyph mapping.
1317 std::sort(fallback_families.begin(), fallback_families.end());
1318 fallback_families.erase(std::unique(
1319 fallback_families.begin(), fallback_families.end()),
1320 fallback_families.end());
1321 1320
1322 // Try shaping with the fallback fonts. 1321 // Try shaping with the fallback fonts.
1323 for (const auto& family : fallback_families) { 1322 for (const auto& family : fallback_families) {
1324 if (family == primary_family) 1323 if (family == primary_family)
1325 continue; 1324 continue;
1326 #if defined(OS_WIN) 1325 #if defined(OS_WIN)
1327 if (family == uniscribe_family) 1326 if (family == uniscribe_family)
1328 continue; 1327 continue;
1329 #endif 1328 #endif
1329 if (duplicate_fallback_font_tracker.find(family) !=
1330 duplicate_fallback_font_tracker.end())
1331 continue;
1332
1333 duplicate_fallback_font_tracker.insert(family);
1334
1330 FontRenderParamsQuery query(false); 1335 FontRenderParamsQuery query(false);
1331 query.families.push_back(family); 1336 query.families.push_back(family);
1332 query.pixel_size = run->font_size; 1337 query.pixel_size = run->font_size;
1333 query.style = run->font_style; 1338 query.style = run->font_style;
1334 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); 1339 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL);
1335 if (CompareFamily(text, family, fallback_render_params, run, &best_family, 1340 if (CompareFamily(text, family, fallback_render_params, run, &best_family,
1336 &best_render_params, &best_missing_glyphs)) 1341 &best_render_params, &best_missing_glyphs))
1337 return; 1342 return;
1338 } 1343 }
1339 1344
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 DCHECK(!update_layout_run_list_); 1524 DCHECK(!update_layout_run_list_);
1520 DCHECK(!update_display_run_list_); 1525 DCHECK(!update_display_run_list_);
1521 return text_elided() ? display_run_list_.get() : &layout_run_list_; 1526 return text_elided() ? display_run_list_.get() : &layout_run_list_;
1522 } 1527 }
1523 1528
1524 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { 1529 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const {
1525 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); 1530 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList();
1526 } 1531 }
1527 1532
1528 } // namespace gfx 1533 } // namespace gfx
OLDNEW
« 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