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/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "third_party/harfbuzz-ng/src/hb.h" | 20 #include "third_party/harfbuzz-ng/src/hb.h" |
20 #include "third_party/icu/source/common/unicode/ubidi.h" | 21 #include "third_party/icu/source/common/unicode/ubidi.h" |
21 #include "third_party/icu/source/common/unicode/utf16.h" | 22 #include "third_party/icu/source/common/unicode/utf16.h" |
22 #include "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
23 #include "third_party/skia/include/core/SkTypeface.h" | 24 #include "third_party/skia/include/core/SkTypeface.h" |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 update_layout_run_list_(false), | 754 update_layout_run_list_(false), |
754 update_display_run_list_(false), | 755 update_display_run_list_(false), |
755 update_grapheme_iterator_(false), | 756 update_grapheme_iterator_(false), |
756 update_display_text_(false), | 757 update_display_text_(false), |
757 glyph_width_for_test_(0u) { | 758 glyph_width_for_test_(0u) { |
758 set_truncate_length(kMaxTextLength); | 759 set_truncate_length(kMaxTextLength); |
759 } | 760 } |
760 | 761 |
761 RenderTextHarfBuzz::~RenderTextHarfBuzz() {} | 762 RenderTextHarfBuzz::~RenderTextHarfBuzz() {} |
762 | 763 |
763 scoped_ptr<RenderText> RenderTextHarfBuzz::CreateInstanceOfSameType() const { | 764 std::unique_ptr<RenderText> RenderTextHarfBuzz::CreateInstanceOfSameType() |
764 return make_scoped_ptr(new RenderTextHarfBuzz); | 765 const { |
| 766 return base::WrapUnique(new RenderTextHarfBuzz); |
765 } | 767 } |
766 | 768 |
767 bool RenderTextHarfBuzz::MultilineSupported() const { | 769 bool RenderTextHarfBuzz::MultilineSupported() const { |
768 return true; | 770 return true; |
769 } | 771 } |
770 | 772 |
771 const base::string16& RenderTextHarfBuzz::GetDisplayText() { | 773 const base::string16& RenderTextHarfBuzz::GetDisplayText() { |
772 // TODO(oshima): Consider supporting eliding multi-line text. | 774 // TODO(oshima): Consider supporting eliding multi-line text. |
773 // This requires max_line support first. | 775 // This requires max_line support first. |
774 if (multiline() || | 776 if (multiline() || |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 } | 1084 } |
1083 update_display_run_list_ = false; | 1085 update_display_run_list_ = false; |
1084 | 1086 |
1085 std::vector<internal::Line> empty_lines; | 1087 std::vector<internal::Line> empty_lines; |
1086 set_lines(&empty_lines); | 1088 set_lines(&empty_lines); |
1087 } | 1089 } |
1088 | 1090 |
1089 if (lines().empty()) { | 1091 if (lines().empty()) { |
1090 // TODO(ckocagil): Remove ScopedTracker below once crbug.com/441028 is | 1092 // TODO(ckocagil): Remove ScopedTracker below once crbug.com/441028 is |
1091 // fixed. | 1093 // fixed. |
1092 scoped_ptr<tracked_objects::ScopedTracker> tracking_profile( | 1094 std::unique_ptr<tracked_objects::ScopedTracker> tracking_profile( |
1093 new tracked_objects::ScopedTracker( | 1095 new tracked_objects::ScopedTracker( |
1094 FROM_HERE_WITH_EXPLICIT_FUNCTION("441028 HarfBuzzLineBreaker"))); | 1096 FROM_HERE_WITH_EXPLICIT_FUNCTION("441028 HarfBuzzLineBreaker"))); |
1095 | 1097 |
1096 internal::TextRunList* run_list = GetRunList(); | 1098 internal::TextRunList* run_list = GetRunList(); |
1097 HarfBuzzLineBreaker line_breaker( | 1099 HarfBuzzLineBreaker line_breaker( |
1098 display_rect().width(), font_list().GetBaseline(), | 1100 display_rect().width(), font_list().GetBaseline(), |
1099 std::max(font_list().GetHeight(), min_line_height()), | 1101 std::max(font_list().GetHeight(), min_line_height()), |
1100 word_wrap_behavior(), GetDisplayText(), | 1102 word_wrap_behavior(), GetDisplayText(), |
1101 multiline() ? &GetLineBreaks() : nullptr, *run_list); | 1103 multiline() ? &GetLineBreaks() : nullptr, *run_list); |
1102 | 1104 |
(...skipping 25 matching lines...) Expand all Loading... |
1128 const internal::Line& line = lines()[i]; | 1130 const internal::Line& line = lines()[i]; |
1129 const Vector2d origin = GetLineOffset(i) + Vector2d(0, line.baseline); | 1131 const Vector2d origin = GetLineOffset(i) + Vector2d(0, line.baseline); |
1130 SkScalar preceding_segment_widths = 0; | 1132 SkScalar preceding_segment_widths = 0; |
1131 for (const internal::LineSegment& segment : line.segments) { | 1133 for (const internal::LineSegment& segment : line.segments) { |
1132 const internal::TextRunHarfBuzz& run = *run_list->runs()[segment.run]; | 1134 const internal::TextRunHarfBuzz& run = *run_list->runs()[segment.run]; |
1133 renderer->SetTypeface(run.skia_face.get()); | 1135 renderer->SetTypeface(run.skia_face.get()); |
1134 renderer->SetTextSize(SkIntToScalar(run.font_size)); | 1136 renderer->SetTextSize(SkIntToScalar(run.font_size)); |
1135 renderer->SetFontRenderParams(run.render_params, | 1137 renderer->SetFontRenderParams(run.render_params, |
1136 subpixel_rendering_suppressed()); | 1138 subpixel_rendering_suppressed()); |
1137 Range glyphs_range = run.CharRangeToGlyphRange(segment.char_range); | 1139 Range glyphs_range = run.CharRangeToGlyphRange(segment.char_range); |
1138 scoped_ptr<SkPoint[]> positions(new SkPoint[glyphs_range.length()]); | 1140 std::unique_ptr<SkPoint[]> positions(new SkPoint[glyphs_range.length()]); |
1139 SkScalar offset_x = preceding_segment_widths - | 1141 SkScalar offset_x = preceding_segment_widths - |
1140 ((glyphs_range.GetMin() != 0) | 1142 ((glyphs_range.GetMin() != 0) |
1141 ? run.positions[glyphs_range.GetMin()].x() | 1143 ? run.positions[glyphs_range.GetMin()].x() |
1142 : 0); | 1144 : 0); |
1143 for (size_t j = 0; j < glyphs_range.length(); ++j) { | 1145 for (size_t j = 0; j < glyphs_range.length(); ++j) { |
1144 positions[j] = run.positions[(glyphs_range.is_reversed()) ? | 1146 positions[j] = run.positions[(glyphs_range.is_reversed()) ? |
1145 (glyphs_range.start() - j) : | 1147 (glyphs_range.start() - j) : |
1146 (glyphs_range.start() + j)]; | 1148 (glyphs_range.start() + j)]; |
1147 positions[j].offset(SkIntToScalar(origin.x()) + offset_x, | 1149 positions[j].offset(SkIntToScalar(origin.x()) + offset_x, |
1148 SkIntToScalar(origin.y() + run.baseline_offset)); | 1150 SkIntToScalar(origin.y() + run.baseline_offset)); |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 DCHECK(!update_layout_run_list_); | 1569 DCHECK(!update_layout_run_list_); |
1568 DCHECK(!update_display_run_list_); | 1570 DCHECK(!update_display_run_list_); |
1569 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1571 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
1570 } | 1572 } |
1571 | 1573 |
1572 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1574 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
1573 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1575 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
1574 } | 1576 } |
1575 | 1577 |
1576 } // namespace gfx | 1578 } // namespace gfx |
OLD | NEW |