| 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 | 8 |
| 9 #include "base/i18n/bidi_line_iterator.h" | 9 #include "base/i18n/bidi_line_iterator.h" |
| 10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
| 11 #include "base/i18n/char_iterator.h" | 11 #include "base/i18n/char_iterator.h" |
| 12 #include "base/profiler/scoped_tracker.h" | 12 #include "base/profiler/scoped_tracker.h" |
| 13 #include "third_party/harfbuzz-ng/src/hb.h" | 13 #include "third_party/harfbuzz-ng/src/hb.h" |
| 14 #include "third_party/icu/source/common/unicode/ubidi.h" | 14 #include "third_party/icu/source/common/unicode/ubidi.h" |
| 15 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
| 16 #include "third_party/skia/include/core/SkTypeface.h" | 16 #include "third_party/skia/include/core/SkTypeface.h" |
| 17 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/font_fallback.h" | 18 #include "ui/gfx/font_fallback.h" |
| 19 #include "ui/gfx/font_render_params.h" | 19 #include "ui/gfx/font_render_params.h" |
| 20 #include "ui/gfx/harfbuzz_font_skia.h" | 20 #include "ui/gfx/harfbuzz_font_skia.h" |
| 21 #include "ui/gfx/range/range_f.h" |
| 21 #include "ui/gfx/utf16_indexing.h" | 22 #include "ui/gfx/utf16_indexing.h" |
| 22 | 23 |
| 23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 24 #include "ui/gfx/font_fallback_win.h" | 25 #include "ui/gfx/font_fallback_win.h" |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 using gfx::internal::RangeF; | |
| 28 using gfx::internal::RoundRangeF; | 28 using gfx::internal::RoundRangeF; |
| 29 | 29 |
| 30 namespace gfx { | 30 namespace gfx { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Text length limit. Longer strings are slow and not fully tested. | 34 // Text length limit. Longer strings are slow and not fully tested. |
| 35 const size_t kMaxTextLength = 10000; | 35 const size_t kMaxTextLength = 10000; |
| 36 | 36 |
| 37 // 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 std::vector<SegmentHandle> rtl_segments_; | 454 std::vector<SegmentHandle> rtl_segments_; |
| 455 | 455 |
| 456 DISALLOW_COPY_AND_ASSIGN(HarfBuzzLineBreaker); | 456 DISALLOW_COPY_AND_ASSIGN(HarfBuzzLineBreaker); |
| 457 }; | 457 }; |
| 458 | 458 |
| 459 } // namespace | 459 } // namespace |
| 460 | 460 |
| 461 namespace internal { | 461 namespace internal { |
| 462 | 462 |
| 463 Range RoundRangeF(const RangeF& range_f) { | 463 Range RoundRangeF(const RangeF& range_f) { |
| 464 return Range(std::floor(range_f.first + 0.5f), | 464 return Range(std::floor(range_f.start() + 0.5f), |
| 465 std::floor(range_f.second + 0.5f)); | 465 std::floor(range_f.end() + 0.5f)); |
| 466 } | 466 } |
| 467 | 467 |
| 468 TextRunHarfBuzz::TextRunHarfBuzz() | 468 TextRunHarfBuzz::TextRunHarfBuzz() |
| 469 : width(0.0f), | 469 : width(0.0f), |
| 470 preceding_run_widths(0.0f), | 470 preceding_run_widths(0.0f), |
| 471 is_rtl(false), | 471 is_rtl(false), |
| 472 level(0), | 472 level(0), |
| 473 script(USCRIPT_INVALID_CODE), | 473 script(USCRIPT_INVALID_CODE), |
| 474 glyph_count(static_cast<size_t>(-1)), | 474 glyph_count(static_cast<size_t>(-1)), |
| 475 font_size(0), | 475 font_size(0), |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 if (run_index >= runs_.size()) | 652 if (run_index >= runs_.size()) |
| 653 return Range(GetStringSize().width()); | 653 return Range(GetStringSize().width()); |
| 654 const size_t layout_index = TextIndexToLayoutIndex(index); | 654 const size_t layout_index = TextIndexToLayoutIndex(index); |
| 655 internal::TextRunHarfBuzz* run = runs_[run_index]; | 655 internal::TextRunHarfBuzz* run = runs_[run_index]; |
| 656 RangeF bounds = | 656 RangeF bounds = |
| 657 run->GetGraphemeBounds(grapheme_iterator_.get(), layout_index); | 657 run->GetGraphemeBounds(grapheme_iterator_.get(), layout_index); |
| 658 // If cursor is enabled, extend the last glyph up to the rightmost cursor | 658 // If cursor is enabled, extend the last glyph up to the rightmost cursor |
| 659 // position since clients expect them to be contiguous. | 659 // position since clients expect them to be contiguous. |
| 660 if (cursor_enabled() && run_index == runs_.size() - 1 && | 660 if (cursor_enabled() && run_index == runs_.size() - 1 && |
| 661 index == (run->is_rtl ? run->range.start() : run->range.end() - 1)) | 661 index == (run->is_rtl ? run->range.start() : run->range.end() - 1)) |
| 662 bounds.second = std::ceil(bounds.second); | 662 bounds.set_end(std::ceil(bounds.end())); |
| 663 return RoundRangeF(run->is_rtl ? | 663 return RoundRangeF(run->is_rtl ? |
| 664 RangeF(bounds.second, bounds.first) : bounds); | 664 RangeF(bounds.end(), bounds.start()) : bounds); |
| 665 } | 665 } |
| 666 | 666 |
| 667 int RenderTextHarfBuzz::GetLayoutTextBaseline() { | 667 int RenderTextHarfBuzz::GetLayoutTextBaseline() { |
| 668 EnsureLayout(); | 668 EnsureLayout(); |
| 669 return lines()[0].baseline; | 669 return lines()[0].baseline; |
| 670 } | 670 } |
| 671 | 671 |
| 672 SelectionModel RenderTextHarfBuzz::AdjacentCharSelectionModel( | 672 SelectionModel RenderTextHarfBuzz::AdjacentCharSelectionModel( |
| 673 const SelectionModel& selection, | 673 const SelectionModel& selection, |
| 674 VisualCursorDirection direction) { | 674 VisualCursorDirection direction) { |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 if (!run->render_params.subpixel_positioning) | 1324 if (!run->render_params.subpixel_positioning) |
| 1325 run->width = std::floor(run->width + 0.5f); | 1325 run->width = std::floor(run->width + 0.5f); |
| 1326 } | 1326 } |
| 1327 | 1327 |
| 1328 hb_buffer_destroy(buffer); | 1328 hb_buffer_destroy(buffer); |
| 1329 hb_font_destroy(harfbuzz_font); | 1329 hb_font_destroy(harfbuzz_font); |
| 1330 return true; | 1330 return true; |
| 1331 } | 1331 } |
| 1332 | 1332 |
| 1333 } // namespace gfx | 1333 } // namespace gfx |
| OLD | NEW |