| 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 <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/i18n/bidi_line_iterator.h" | 10 #include "base/i18n/bidi_line_iterator.h" |
| 11 #include "base/i18n/break_iterator.h" | 11 #include "base/i18n/break_iterator.h" |
| 12 #include "base/i18n/char_iterator.h" | 12 #include "base/i18n/char_iterator.h" |
| 13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 14 #include "base/profiler/scoped_tracker.h" | 14 #include "base/profiler/scoped_tracker.h" |
| 15 #include "third_party/harfbuzz-ng/src/hb.h" | 15 #include "third_party/harfbuzz-ng/src/hb.h" |
| 16 #include "third_party/icu/source/common/unicode/ubidi.h" | 16 #include "third_party/icu/source/common/unicode/ubidi.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
| 18 #include "third_party/skia/include/core/SkTypeface.h" | 18 #include "third_party/skia/include/core/SkTypeface.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/font_fallback.h" | 20 #include "ui/gfx/font_fallback.h" |
| 21 #include "ui/gfx/font_render_params.h" | 21 #include "ui/gfx/font_render_params.h" |
| 22 #include "ui/gfx/utf16_indexing.h" | 22 #include "ui/gfx/utf16_indexing.h" |
| 23 | 23 |
| 24 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 25 #include "ui/gfx/font_fallback_win.h" | 25 #include "ui/gfx/font_fallback_win.h" |
| 26 #endif | 26 #endif |
| 27 | 27 |
| 28 using gfx::internal::RangeF; | |
| 29 using gfx::internal::RoundRangeF; | 28 using gfx::internal::RoundRangeF; |
| 30 | 29 |
| 31 namespace gfx { | 30 namespace gfx { |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 | 33 |
| 35 // Text length limit. Longer strings are slow and not fully tested. | 34 // Text length limit. Longer strings are slow and not fully tested. |
| 36 const size_t kMaxTextLength = 10000; | 35 const size_t kMaxTextLength = 10000; |
| 37 | 36 |
| 38 // The maximum number of scripts a Unicode character can belong to. This value | 37 // The maximum number of scripts a Unicode character can belong to. This value |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 DCHECK(!chars->is_empty()); | 461 DCHECK(!chars->is_empty()); |
| 463 DCHECK(!glyphs->is_reversed()); | 462 DCHECK(!glyphs->is_reversed()); |
| 464 DCHECK(!glyphs->is_empty()); | 463 DCHECK(!glyphs->is_empty()); |
| 465 } | 464 } |
| 466 | 465 |
| 467 } // namespace | 466 } // namespace |
| 468 | 467 |
| 469 namespace internal { | 468 namespace internal { |
| 470 | 469 |
| 471 Range RoundRangeF(const RangeF& range_f) { | 470 Range RoundRangeF(const RangeF& range_f) { |
| 472 return Range(std::floor(range_f.first + 0.5f), | 471 return Range(std::floor(range_f.start() + 0.5f), |
| 473 std::floor(range_f.second + 0.5f)); | 472 std::floor(range_f.end() + 0.5f)); |
| 474 } | 473 } |
| 475 | 474 |
| 476 TextRunHarfBuzz::TextRunHarfBuzz() | 475 TextRunHarfBuzz::TextRunHarfBuzz() |
| 477 : width(0.0f), | 476 : width(0.0f), |
| 478 preceding_run_widths(0.0f), | 477 preceding_run_widths(0.0f), |
| 479 is_rtl(false), | 478 is_rtl(false), |
| 480 level(0), | 479 level(0), |
| 481 script(USCRIPT_INVALID_CODE), | 480 script(USCRIPT_INVALID_CODE), |
| 482 glyph_count(static_cast<size_t>(-1)), | 481 glyph_count(static_cast<size_t>(-1)), |
| 483 font_size(0), | 482 font_size(0), |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 if (run_index >= runs_.size()) | 658 if (run_index >= runs_.size()) |
| 660 return Range(GetStringSize().width()); | 659 return Range(GetStringSize().width()); |
| 661 const size_t layout_index = TextIndexToLayoutIndex(index); | 660 const size_t layout_index = TextIndexToLayoutIndex(index); |
| 662 internal::TextRunHarfBuzz* run = runs_[run_index]; | 661 internal::TextRunHarfBuzz* run = runs_[run_index]; |
| 663 RangeF bounds = | 662 RangeF bounds = |
| 664 run->GetGraphemeBounds(grapheme_iterator_.get(), layout_index); | 663 run->GetGraphemeBounds(grapheme_iterator_.get(), layout_index); |
| 665 // If cursor is enabled, extend the last glyph up to the rightmost cursor | 664 // If cursor is enabled, extend the last glyph up to the rightmost cursor |
| 666 // position since clients expect them to be contiguous. | 665 // position since clients expect them to be contiguous. |
| 667 if (cursor_enabled() && run_index == runs_.size() - 1 && | 666 if (cursor_enabled() && run_index == runs_.size() - 1 && |
| 668 index == (run->is_rtl ? run->range.start() : run->range.end() - 1)) | 667 index == (run->is_rtl ? run->range.start() : run->range.end() - 1)) |
| 669 bounds.second = std::ceil(bounds.second); | 668 bounds.set_end(std::ceil(bounds.end())); |
| 670 return RoundRangeF(run->is_rtl ? | 669 return RoundRangeF(run->is_rtl ? |
| 671 RangeF(bounds.second, bounds.first) : bounds); | 670 RangeF(bounds.end(), bounds.start()) : bounds); |
| 672 } | 671 } |
| 673 | 672 |
| 674 int RenderTextHarfBuzz::GetLayoutTextBaseline() { | 673 int RenderTextHarfBuzz::GetLayoutTextBaseline() { |
| 675 EnsureLayout(); | 674 EnsureLayout(); |
| 676 return lines()[0].baseline; | 675 return lines()[0].baseline; |
| 677 } | 676 } |
| 678 | 677 |
| 679 SelectionModel RenderTextHarfBuzz::AdjacentCharSelectionModel( | 678 SelectionModel RenderTextHarfBuzz::AdjacentCharSelectionModel( |
| 680 const SelectionModel& selection, | 679 const SelectionModel& selection, |
| 681 VisualCursorDirection direction) { | 680 VisualCursorDirection direction) { |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 if (!run->render_params.subpixel_positioning) | 1332 if (!run->render_params.subpixel_positioning) |
| 1334 run->width = std::floor(run->width + 0.5f); | 1333 run->width = std::floor(run->width + 0.5f); |
| 1335 } | 1334 } |
| 1336 | 1335 |
| 1337 hb_buffer_destroy(buffer); | 1336 hb_buffer_destroy(buffer); |
| 1338 hb_font_destroy(harfbuzz_font); | 1337 hb_font_destroy(harfbuzz_font); |
| 1339 return true; | 1338 return true; |
| 1340 } | 1339 } |
| 1341 | 1340 |
| 1342 } // namespace gfx | 1341 } // namespace gfx |
| OLD | NEW |