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 <map> | 7 #include <map> |
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 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 } // namespace internal | 450 } // namespace internal |
451 | 451 |
452 RenderTextHarfBuzz::RenderTextHarfBuzz() | 452 RenderTextHarfBuzz::RenderTextHarfBuzz() |
453 : RenderText(), | 453 : RenderText(), |
454 needs_layout_(false) {} | 454 needs_layout_(false) {} |
455 | 455 |
456 RenderTextHarfBuzz::~RenderTextHarfBuzz() {} | 456 RenderTextHarfBuzz::~RenderTextHarfBuzz() {} |
457 | 457 |
458 Size RenderTextHarfBuzz::GetStringSize() { | 458 Size RenderTextHarfBuzz::GetStringSize() { |
459 EnsureLayout(); | 459 EnsureLayout(); |
460 return Size(lines()[0].size.width(), font_list().GetHeight()); | 460 return lines()[0].size; |
461 } | 461 } |
462 | 462 |
463 SelectionModel RenderTextHarfBuzz::FindCursorPosition(const Point& point) { | 463 SelectionModel RenderTextHarfBuzz::FindCursorPosition(const Point& point) { |
464 EnsureLayout(); | 464 EnsureLayout(); |
465 | 465 |
466 int x = ToTextPoint(point).x(); | 466 int x = ToTextPoint(point).x(); |
467 int offset = 0; | 467 int offset = 0; |
468 size_t run_index = GetRunContainingXCoord(x, &offset); | 468 size_t run_index = GetRunContainingXCoord(x, &offset); |
469 if (run_index >= runs_.size()) | 469 if (run_index >= runs_.size()) |
470 return EdgeSelectionModel((x < 0) ? CURSOR_LEFT : CURSOR_RIGHT); | 470 return EdgeSelectionModel((x < 0) ? CURSOR_LEFT : CURSOR_RIGHT); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 } | 695 } |
696 | 696 |
697 needs_layout_ = false; | 697 needs_layout_ = false; |
698 std::vector<internal::Line> empty_lines; | 698 std::vector<internal::Line> empty_lines; |
699 set_lines(&empty_lines); | 699 set_lines(&empty_lines); |
700 } | 700 } |
701 | 701 |
702 if (lines().empty()) { | 702 if (lines().empty()) { |
703 std::vector<internal::Line> lines; | 703 std::vector<internal::Line> lines; |
704 lines.push_back(internal::Line()); | 704 lines.push_back(internal::Line()); |
| 705 lines[0].baseline = font_list().GetBaseline(); |
| 706 lines[0].size.set_height(font_list().GetHeight()); |
705 | 707 |
706 int current_x = 0; | 708 int current_x = 0; |
707 SkPaint paint; | 709 SkPaint paint; |
708 | 710 |
709 for (size_t i = 0; i < runs_.size(); ++i) { | 711 for (size_t i = 0; i < runs_.size(); ++i) { |
710 const internal::TextRunHarfBuzz& run = *runs_[visual_to_logical_[i]]; | 712 const internal::TextRunHarfBuzz& run = *runs_[visual_to_logical_[i]]; |
711 internal::LineSegment segment; | 713 internal::LineSegment segment; |
712 segment.x_range = Range(current_x, current_x + run.width); | 714 segment.x_range = Range(current_x, current_x + run.width); |
713 segment.char_range = run.range; | 715 segment.char_range = run.range; |
714 segment.run = i; | 716 segment.run = i; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 run->positions[i].set(run->width + x_offset, y_offset); | 974 run->positions[i].set(run->width + x_offset, y_offset); |
973 run->width += | 975 run->width += |
974 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); | 976 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); |
975 } | 977 } |
976 | 978 |
977 hb_buffer_destroy(buffer); | 979 hb_buffer_destroy(buffer); |
978 hb_font_destroy(harfbuzz_font); | 980 hb_font_destroy(harfbuzz_font); |
979 } | 981 } |
980 | 982 |
981 } // namespace gfx | 983 } // namespace gfx |
OLD | NEW |