| 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/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
| 10 #include "base/i18n/bidi_line_iterator.h" | 10 #include "base/i18n/bidi_line_iterator.h" |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 return EdgeSelectionModel(CURSOR_RIGHT); | 531 return EdgeSelectionModel(CURSOR_RIGHT); |
| 532 } | 532 } |
| 533 | 533 |
| 534 std::vector<RenderText::FontSpan> RenderTextHarfBuzz::GetFontSpansForTesting() { | 534 std::vector<RenderText::FontSpan> RenderTextHarfBuzz::GetFontSpansForTesting() { |
| 535 NOTIMPLEMENTED(); | 535 NOTIMPLEMENTED(); |
| 536 return std::vector<RenderText::FontSpan>(); | 536 return std::vector<RenderText::FontSpan>(); |
| 537 } | 537 } |
| 538 | 538 |
| 539 Range RenderTextHarfBuzz::GetGlyphBounds(size_t index) { |
| 540 EnsureLayout(); |
| 541 const size_t run_index = |
| 542 GetRunContainingCaret(SelectionModel(index, CURSOR_FORWARD)); |
| 543 // Return edge bounds if the index is invalid or beyond the layout text size. |
| 544 if (run_index >= runs_.size()) |
| 545 return Range(GetStringSize().width()); |
| 546 const size_t layout_index = TextIndexToLayoutIndex(index); |
| 547 return Range(runs_[run_index]->GetGlyphXBoundary(layout_index, false), |
| 548 runs_[run_index]->GetGlyphXBoundary(layout_index, true)); |
| 549 } |
| 550 |
| 539 int RenderTextHarfBuzz::GetLayoutTextBaseline() { | 551 int RenderTextHarfBuzz::GetLayoutTextBaseline() { |
| 540 EnsureLayout(); | 552 EnsureLayout(); |
| 541 return lines()[0].baseline; | 553 return lines()[0].baseline; |
| 542 } | 554 } |
| 543 | 555 |
| 544 SelectionModel RenderTextHarfBuzz::AdjacentCharSelectionModel( | 556 SelectionModel RenderTextHarfBuzz::AdjacentCharSelectionModel( |
| 545 const SelectionModel& selection, | 557 const SelectionModel& selection, |
| 546 VisualCursorDirection direction) { | 558 VisualCursorDirection direction) { |
| 547 DCHECK(!needs_layout_); | 559 DCHECK(!needs_layout_); |
| 548 internal::TextRunHarfBuzz* run; | 560 internal::TextRunHarfBuzz* run; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 pos = begin; | 636 pos = begin; |
| 625 break; | 637 break; |
| 626 } | 638 } |
| 627 pos = iter.pos() - iter.GetString().length(); | 639 pos = iter.pos() - iter.GetString().length(); |
| 628 } | 640 } |
| 629 } | 641 } |
| 630 } | 642 } |
| 631 return SelectionModel(pos, CURSOR_FORWARD); | 643 return SelectionModel(pos, CURSOR_FORWARD); |
| 632 } | 644 } |
| 633 | 645 |
| 634 Range RenderTextHarfBuzz::GetGlyphBounds(size_t index) { | |
| 635 const size_t run_index = | |
| 636 GetRunContainingCaret(SelectionModel(index, CURSOR_FORWARD)); | |
| 637 // Return edge bounds if the index is invalid or beyond the layout text size. | |
| 638 if (run_index >= runs_.size()) | |
| 639 return Range(GetStringSize().width()); | |
| 640 const size_t layout_index = TextIndexToLayoutIndex(index); | |
| 641 return Range(runs_[run_index]->GetGlyphXBoundary(layout_index, false), | |
| 642 runs_[run_index]->GetGlyphXBoundary(layout_index, true)); | |
| 643 } | |
| 644 | |
| 645 std::vector<Rect> RenderTextHarfBuzz::GetSubstringBounds(const Range& range) { | 646 std::vector<Rect> RenderTextHarfBuzz::GetSubstringBounds(const Range& range) { |
| 646 DCHECK(!needs_layout_); | 647 DCHECK(!needs_layout_); |
| 647 DCHECK(Range(0, text().length()).Contains(range)); | 648 DCHECK(Range(0, text().length()).Contains(range)); |
| 648 Range layout_range(TextIndexToLayoutIndex(range.start()), | 649 Range layout_range(TextIndexToLayoutIndex(range.start()), |
| 649 TextIndexToLayoutIndex(range.end())); | 650 TextIndexToLayoutIndex(range.end())); |
| 650 DCHECK(Range(0, GetLayoutText().length()).Contains(layout_range)); | 651 DCHECK(Range(0, GetLayoutText().length()).Contains(layout_range)); |
| 651 | 652 |
| 652 std::vector<Rect> rects; | 653 std::vector<Rect> rects; |
| 653 if (layout_range.is_empty()) | 654 if (layout_range.is_empty()) |
| 654 return rects; | 655 return rects; |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 run->positions[i].set(run->width + x_offset, -y_offset); | 1038 run->positions[i].set(run->width + x_offset, -y_offset); |
| 1038 run->width += | 1039 run->width += |
| 1039 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); | 1040 SkScalarRoundToInt(SkFixedToScalar(hb_positions[i].x_advance)); |
| 1040 } | 1041 } |
| 1041 | 1042 |
| 1042 hb_buffer_destroy(buffer); | 1043 hb_buffer_destroy(buffer); |
| 1043 hb_font_destroy(harfbuzz_font); | 1044 hb_font_destroy(harfbuzz_font); |
| 1044 } | 1045 } |
| 1045 | 1046 |
| 1046 } // namespace gfx | 1047 } // namespace gfx |
| OLD | NEW |