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" |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 update_display_text_ = false; | 640 update_display_text_ = false; |
641 display_run_list_.reset(); | 641 display_run_list_.reset(); |
642 return layout_text(); | 642 return layout_text(); |
643 } | 643 } |
644 | 644 |
645 EnsureLayoutRunList(); | 645 EnsureLayoutRunList(); |
646 DCHECK(!update_display_text_); | 646 DCHECK(!update_display_text_); |
647 return text_elided() ? display_text() : layout_text(); | 647 return text_elided() ? display_text() : layout_text(); |
648 } | 648 } |
649 | 649 |
| 650 bool RenderTextHarfBuzz::MultilineSupported() const { |
| 651 return true; |
| 652 } |
| 653 |
650 Size RenderTextHarfBuzz::GetStringSize() { | 654 Size RenderTextHarfBuzz::GetStringSize() { |
651 const SizeF size_f = GetStringSizeF(); | 655 const SizeF size_f = GetStringSizeF(); |
652 return Size(std::ceil(size_f.width()), size_f.height()); | 656 return Size(std::ceil(size_f.width()), size_f.height()); |
653 } | 657 } |
654 | 658 |
655 SizeF RenderTextHarfBuzz::GetStringSizeF() { | 659 SizeF RenderTextHarfBuzz::GetStringSizeF() { |
656 EnsureLayout(); | 660 EnsureLayout(); |
657 return total_size_; | 661 return total_size_; |
658 } | 662 } |
659 | 663 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 internal::TextRunList* run_list = GetRunList(); | 1006 internal::TextRunList* run_list = GetRunList(); |
1003 for (size_t i = 0; i < lines().size(); ++i) { | 1007 for (size_t i = 0; i < lines().size(); ++i) { |
1004 const internal::Line& line = lines()[i]; | 1008 const internal::Line& line = lines()[i]; |
1005 const Vector2d origin = GetLineOffset(i) + Vector2d(0, line.baseline); | 1009 const Vector2d origin = GetLineOffset(i) + Vector2d(0, line.baseline); |
1006 SkScalar preceding_segment_widths = 0; | 1010 SkScalar preceding_segment_widths = 0; |
1007 for (const internal::LineSegment& segment : line.segments) { | 1011 for (const internal::LineSegment& segment : line.segments) { |
1008 const internal::TextRunHarfBuzz& run = *run_list->runs()[segment.run]; | 1012 const internal::TextRunHarfBuzz& run = *run_list->runs()[segment.run]; |
1009 renderer.SetTypeface(run.skia_face.get()); | 1013 renderer.SetTypeface(run.skia_face.get()); |
1010 renderer.SetTextSize(SkIntToScalar(run.font_size)); | 1014 renderer.SetTextSize(SkIntToScalar(run.font_size)); |
1011 renderer.SetFontRenderParams(run.render_params, | 1015 renderer.SetFontRenderParams(run.render_params, |
1012 background_is_transparent()); | 1016 subpixel_rendering_enabled()); |
1013 Range glyphs_range = run.CharRangeToGlyphRange(segment.char_range); | 1017 Range glyphs_range = run.CharRangeToGlyphRange(segment.char_range); |
1014 scoped_ptr<SkPoint[]> positions(new SkPoint[glyphs_range.length()]); | 1018 scoped_ptr<SkPoint[]> positions(new SkPoint[glyphs_range.length()]); |
1015 SkScalar offset_x = | 1019 SkScalar offset_x = |
1016 preceding_segment_widths - run.positions[glyphs_range.start()].x(); | 1020 preceding_segment_widths - run.positions[glyphs_range.start()].x(); |
1017 for (size_t j = 0; j < glyphs_range.length(); ++j) { | 1021 for (size_t j = 0; j < glyphs_range.length(); ++j) { |
1018 positions[j] = run.positions[(glyphs_range.is_reversed()) ? | 1022 positions[j] = run.positions[(glyphs_range.is_reversed()) ? |
1019 (glyphs_range.start() - j) : | 1023 (glyphs_range.start() - j) : |
1020 (glyphs_range.start() + j)]; | 1024 (glyphs_range.start() + j)]; |
1021 positions[j].offset(SkIntToScalar(origin.x()) + offset_x, | 1025 positions[j].offset(SkIntToScalar(origin.x()) + offset_x, |
1022 SkIntToScalar(origin.y())); | 1026 SkIntToScalar(origin.y())); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1290 run->family = font_family; | 1294 run->family = font_family; |
1291 run->render_params = params; | 1295 run->render_params = params; |
1292 | 1296 |
1293 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 1297 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
1294 tracked_objects::ScopedTracker tracking_profile01( | 1298 tracked_objects::ScopedTracker tracking_profile01( |
1295 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1299 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1296 "431326 RenderTextHarfBuzz::ShapeRunWithFont01")); | 1300 "431326 RenderTextHarfBuzz::ShapeRunWithFont01")); |
1297 | 1301 |
1298 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( | 1302 hb_font_t* harfbuzz_font = CreateHarfBuzzFont( |
1299 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params, | 1303 run->skia_face.get(), SkIntToScalar(run->font_size), run->render_params, |
1300 background_is_transparent()); | 1304 subpixel_rendering_enabled()); |
1301 | 1305 |
1302 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 1306 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
1303 tracked_objects::ScopedTracker tracking_profile1( | 1307 tracked_objects::ScopedTracker tracking_profile1( |
1304 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1308 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
1305 "431326 RenderTextHarfBuzz::ShapeRunWithFont1")); | 1309 "431326 RenderTextHarfBuzz::ShapeRunWithFont1")); |
1306 | 1310 |
1307 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz | 1311 // Create a HarfBuzz buffer and add the string to be shaped. The HarfBuzz |
1308 // buffer holds our text, run information to be used by the shaping engine, | 1312 // buffer holds our text, run information to be used by the shaping engine, |
1309 // and the resulting glyph data. | 1313 // and the resulting glyph data. |
1310 hb_buffer_t* buffer = hb_buffer_create(); | 1314 hb_buffer_t* buffer = hb_buffer_create(); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 DCHECK(!update_layout_run_list_); | 1461 DCHECK(!update_layout_run_list_); |
1458 DCHECK(!update_display_run_list_); | 1462 DCHECK(!update_display_run_list_); |
1459 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1463 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
1460 } | 1464 } |
1461 | 1465 |
1462 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1466 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
1463 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1467 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
1464 } | 1468 } |
1465 | 1469 |
1466 } // namespace gfx | 1470 } // namespace gfx |
OLD | NEW |