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 #include <set> |
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/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "third_party/harfbuzz-ng/src/hb.h" | 20 #include "third_party/harfbuzz-ng/src/hb.h" |
21 #include "third_party/icu/source/common/unicode/ubidi.h" | 21 #include "third_party/icu/source/common/unicode/ubidi.h" |
22 #include "third_party/icu/source/common/unicode/utf16.h" | 22 #include "third_party/icu/source/common/unicode/utf16.h" |
23 #include "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
24 #include "third_party/skia/include/core/SkTypeface.h" | 24 #include "third_party/skia/include/core/SkTypeface.h" |
25 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 26 #include "ui/gfx/decorated_text.h" |
26 #include "ui/gfx/font.h" | 27 #include "ui/gfx/font.h" |
27 #include "ui/gfx/font_fallback.h" | 28 #include "ui/gfx/font_fallback.h" |
28 #include "ui/gfx/font_render_params.h" | 29 #include "ui/gfx/font_render_params.h" |
29 #include "ui/gfx/geometry/safe_integer_conversions.h" | 30 #include "ui/gfx/geometry/safe_integer_conversions.h" |
30 #include "ui/gfx/harfbuzz_font_skia.h" | 31 #include "ui/gfx/harfbuzz_font_skia.h" |
31 #include "ui/gfx/range/range_f.h" | 32 #include "ui/gfx/range/range_f.h" |
32 #include "ui/gfx/skia_util.h" | 33 #include "ui/gfx/skia_util.h" |
33 #include "ui/gfx/text_utils.h" | 34 #include "ui/gfx/text_utils.h" |
34 #include "ui/gfx/utf16_indexing.h" | 35 #include "ui/gfx/utf16_indexing.h" |
35 | 36 |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 } | 841 } |
841 return EdgeSelectionModel(CURSOR_RIGHT); | 842 return EdgeSelectionModel(CURSOR_RIGHT); |
842 } | 843 } |
843 | 844 |
844 std::vector<RenderText::FontSpan> RenderTextHarfBuzz::GetFontSpansForTesting() { | 845 std::vector<RenderText::FontSpan> RenderTextHarfBuzz::GetFontSpansForTesting() { |
845 EnsureLayout(); | 846 EnsureLayout(); |
846 | 847 |
847 internal::TextRunList* run_list = GetRunList(); | 848 internal::TextRunList* run_list = GetRunList(); |
848 std::vector<RenderText::FontSpan> spans; | 849 std::vector<RenderText::FontSpan> spans; |
849 for (auto* run : run_list->runs()) { | 850 for (auto* run : run_list->runs()) { |
850 SkString family_name; | |
851 run->skia_face->getFamilyName(&family_name); | |
852 Font font(family_name.c_str(), run->font_size); | |
853 spans.push_back(RenderText::FontSpan( | 851 spans.push_back(RenderText::FontSpan( |
854 font, | 852 run->font, Range(DisplayIndexToTextIndex(run->range.start()), |
855 Range(DisplayIndexToTextIndex(run->range.start()), | 853 DisplayIndexToTextIndex(run->range.end())))); |
856 DisplayIndexToTextIndex(run->range.end())))); | |
857 } | 854 } |
858 | 855 |
859 return spans; | 856 return spans; |
860 } | 857 } |
861 | 858 |
862 Range RenderTextHarfBuzz::GetGlyphBounds(size_t index) { | 859 Range RenderTextHarfBuzz::GetGlyphBounds(size_t index) { |
863 EnsureLayout(); | 860 EnsureLayout(); |
864 const size_t run_index = | 861 const size_t run_index = |
865 GetRunContainingCaret(SelectionModel(index, CURSOR_FORWARD)); | 862 GetRunContainingCaret(SelectionModel(index, CURSOR_FORWARD)); |
866 internal::TextRunList* run_list = GetRunList(); | 863 internal::TextRunList* run_list = GetRunList(); |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 internal::TextRunList* RenderTextHarfBuzz::GetRunList() { | 1580 internal::TextRunList* RenderTextHarfBuzz::GetRunList() { |
1584 DCHECK(!update_layout_run_list_); | 1581 DCHECK(!update_layout_run_list_); |
1585 DCHECK(!update_display_run_list_); | 1582 DCHECK(!update_display_run_list_); |
1586 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1583 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
1587 } | 1584 } |
1588 | 1585 |
1589 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1586 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
1590 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1587 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
1591 } | 1588 } |
1592 | 1589 |
| 1590 bool RenderTextHarfBuzz::GetDecoratedTextForRange( |
| 1591 const Range& range, |
| 1592 DecoratedText* decorated_text) { |
| 1593 if (obscured()) |
| 1594 return false; |
| 1595 |
| 1596 EnsureLayout(); |
| 1597 |
| 1598 decorated_text->attributes.clear(); |
| 1599 decorated_text->text = GetTextFromRange(range); |
| 1600 |
| 1601 const internal::TextRunList* run_list = GetRunList(); |
| 1602 for (size_t i = 0; i < run_list->size(); i++) { |
| 1603 const internal::TextRunHarfBuzz& run = *run_list->runs()[i]; |
| 1604 |
| 1605 const Range intersection = range.Intersect(run.range); |
| 1606 DCHECK(!intersection.is_reversed()); |
| 1607 |
| 1608 if (!intersection.is_empty()) { |
| 1609 int style = Font::NORMAL; |
| 1610 if (run.italic) |
| 1611 style |= Font::ITALIC; |
| 1612 if (run.underline) |
| 1613 style |= Font::UNDERLINE; |
| 1614 |
| 1615 // Get range relative to the decorated text. |
| 1616 DecoratedText::RangedAttribute attribute( |
| 1617 Range(intersection.start() - range.GetMin(), |
| 1618 intersection.end() - range.GetMin()), |
| 1619 run.font.Derive(0, style, run.weight)); |
| 1620 |
| 1621 attribute.strike = run.strike; |
| 1622 attribute.diagonal_strike = run.diagonal_strike; |
| 1623 decorated_text->attributes.push_back(attribute); |
| 1624 } |
| 1625 } |
| 1626 return true; |
| 1627 } |
| 1628 |
1593 } // namespace gfx | 1629 } // namespace gfx |
OLD | NEW |