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" |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 } | 840 } |
841 return EdgeSelectionModel(CURSOR_RIGHT); | 841 return EdgeSelectionModel(CURSOR_RIGHT); |
842 } | 842 } |
843 | 843 |
844 std::vector<RenderText::FontSpan> RenderTextHarfBuzz::GetFontSpansForTesting() { | 844 std::vector<RenderText::FontSpan> RenderTextHarfBuzz::GetFontSpansForTesting() { |
845 EnsureLayout(); | 845 EnsureLayout(); |
846 | 846 |
847 internal::TextRunList* run_list = GetRunList(); | 847 internal::TextRunList* run_list = GetRunList(); |
848 std::vector<RenderText::FontSpan> spans; | 848 std::vector<RenderText::FontSpan> spans; |
849 for (auto* run : run_list->runs()) { | 849 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( | 850 spans.push_back(RenderText::FontSpan( |
854 font, | 851 run->font, Range(DisplayIndexToTextIndex(run->range.start()), |
855 Range(DisplayIndexToTextIndex(run->range.start()), | 852 DisplayIndexToTextIndex(run->range.end())))); |
856 DisplayIndexToTextIndex(run->range.end())))); | |
857 } | 853 } |
858 | 854 |
859 return spans; | 855 return spans; |
860 } | 856 } |
861 | 857 |
862 Range RenderTextHarfBuzz::GetGlyphBounds(size_t index) { | 858 Range RenderTextHarfBuzz::GetGlyphBounds(size_t index) { |
863 EnsureLayout(); | 859 EnsureLayout(); |
864 const size_t run_index = | 860 const size_t run_index = |
865 GetRunContainingCaret(SelectionModel(index, CURSOR_FORWARD)); | 861 GetRunContainingCaret(SelectionModel(index, CURSOR_FORWARD)); |
866 internal::TextRunList* run_list = GetRunList(); | 862 internal::TextRunList* run_list = GetRunList(); |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1583 internal::TextRunList* RenderTextHarfBuzz::GetRunList() { | 1579 internal::TextRunList* RenderTextHarfBuzz::GetRunList() { |
1584 DCHECK(!update_layout_run_list_); | 1580 DCHECK(!update_layout_run_list_); |
1585 DCHECK(!update_display_run_list_); | 1581 DCHECK(!update_display_run_list_); |
1586 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1582 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
1587 } | 1583 } |
1588 | 1584 |
1589 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1585 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
1590 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1586 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
1591 } | 1587 } |
1592 | 1588 |
1589 bool RenderTextHarfBuzz::GetDecoratedTextForRange( | |
1590 const Range& range, | |
1591 DecoratedText* decorated_text) const { | |
1592 if (obscured()) | |
1593 return false; | |
1594 | |
1595 decorated_text->attributes.clear(); | |
1596 decorated_text->text = GetTextFromRange(range); | |
1597 | |
1598 const internal::TextRunList* run_list = GetRunList(); | |
1599 for (size_t i = 0; i < run_list->size(); i++) { | |
1600 const internal::TextRunHarfBuzz& run = *run_list->runs()[i]; | |
1601 | |
1602 const Range intersection = range.Intersect(run.range); | |
1603 DCHECK(!intersection.is_reversed()); | |
1604 | |
1605 if (!intersection.is_empty()) { | |
1606 int style = Font::NORMAL; | |
1607 if (run.italic) | |
1608 style |= Font::ITALIC; | |
1609 if (run.underline) | |
1610 style |= Font::UNDERLINE; | |
1611 | |
1612 Font font_with_style = run.font.Derive(0, style, run.weight); | |
msw
2016/10/04 01:52:37
optional nit: inline below in DecoratedText::Range
karandeepb
2016/10/04 12:04:24
Done.
| |
1613 | |
1614 // Get range relative to the decorated text. | |
1615 DecoratedText::RangedAttribute attribute( | |
msw
2016/10/04 01:52:37
producing a range for every run might not give the
karandeepb
2016/10/04 12:04:24
It seems StyleIterator does support strikes and di
msw
2016/10/05 00:24:48
You're right, it does handle strikes as styles, bu
| |
1616 gfx::Range(intersection.start() - range.GetMin(), | |
1617 intersection.end() - range.GetMin()), | |
1618 font_with_style); | |
1619 | |
1620 attribute.strike = run.strike; | |
1621 attribute.diagonal_strike = run.diagonal_strike; | |
1622 decorated_text->attributes.push_back(attribute); | |
1623 } | |
1624 } | |
1625 return true; | |
1626 } | |
1627 | |
1593 } // namespace gfx | 1628 } // namespace gfx |
OLD | NEW |