Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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; | |
| 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 Loading... | |
| 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> duplicate_fallback_fonts; |
| 1311 // the font list as the unique algorithm relies on duplicates being adjacent. | |
| 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 | 1319 |
| 1322 // Try shaping with the fallback fonts. | 1320 // Try shaping with the fallback fonts. |
| 1323 for (const auto& family : fallback_families) { | 1321 for (const auto& family : fallback_families) { |
| 1324 if (family == primary_family) | 1322 if (family == primary_family) |
| 1325 continue; | 1323 continue; |
| 1326 #if defined(OS_WIN) | 1324 #if defined(OS_WIN) |
| 1327 if (family == uniscribe_family) | 1325 if (family == uniscribe_family) |
| 1328 continue; | 1326 continue; |
| 1329 #endif | 1327 #endif |
| 1328 if (duplicate_fallback_fonts.find(family) != | |
| 1329 duplicate_fallback_fonts.end()) | |
|
msw
2015/03/25 23:42:07
nit: fits on line above.
ananta
2015/03/25 23:47:27
Done.
| |
| 1330 continue; | |
| 1331 | |
| 1332 duplicate_fallback_fonts.insert(family); | |
| 1333 | |
| 1330 FontRenderParamsQuery query(false); | 1334 FontRenderParamsQuery query(false); |
| 1331 query.families.push_back(family); | 1335 query.families.push_back(family); |
| 1332 query.pixel_size = run->font_size; | 1336 query.pixel_size = run->font_size; |
| 1333 query.style = run->font_style; | 1337 query.style = run->font_style; |
| 1334 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); | 1338 FontRenderParams fallback_render_params = GetFontRenderParams(query, NULL); |
| 1335 if (CompareFamily(text, family, fallback_render_params, run, &best_family, | 1339 if (CompareFamily(text, family, fallback_render_params, run, &best_family, |
| 1336 &best_render_params, &best_missing_glyphs)) | 1340 &best_render_params, &best_missing_glyphs)) |
| 1337 return; | 1341 return; |
| 1338 } | 1342 } |
| 1339 | 1343 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1519 DCHECK(!update_layout_run_list_); | 1523 DCHECK(!update_layout_run_list_); |
| 1520 DCHECK(!update_display_run_list_); | 1524 DCHECK(!update_display_run_list_); |
| 1521 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1525 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
| 1522 } | 1526 } |
| 1523 | 1527 |
| 1524 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1528 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
| 1525 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1529 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
| 1526 } | 1530 } |
| 1527 | 1531 |
| 1528 } // namespace gfx | 1532 } // namespace gfx |
| OLD | NEW |