| 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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 while (end_pos < segment.char_range.end()) { | 453 while (end_pos < segment.char_range.end()) { |
| 454 const SkScalar char_width = | 454 const SkScalar char_width = |
| 455 run.GetGlyphWidthForCharRange(Range(end_pos, end_pos + 1)); | 455 run.GetGlyphWidthForCharRange(Range(end_pos, end_pos + 1)); |
| 456 if (width + char_width > available_width_) | 456 if (width + char_width > available_width_) |
| 457 break; | 457 break; |
| 458 width += char_width; | 458 width += char_width; |
| 459 end_pos++; | 459 end_pos++; |
| 460 } | 460 } |
| 461 | 461 |
| 462 const size_t valid_end_pos = std::max( | 462 const size_t valid_end_pos = std::max( |
| 463 segment.char_range.start(), FindValidBoundaryBefore(text_, end_pos)); | 463 segment.char_range.start(), |
| 464 static_cast<uint32_t>(FindValidBoundaryBefore(text_, end_pos))); |
| 464 if (end_pos != valid_end_pos) { | 465 if (end_pos != valid_end_pos) { |
| 465 end_pos = valid_end_pos; | 466 end_pos = valid_end_pos; |
| 466 width = run.GetGlyphWidthForCharRange( | 467 width = run.GetGlyphWidthForCharRange( |
| 467 Range(segment.char_range.start(), end_pos)); | 468 Range(segment.char_range.start(), end_pos)); |
| 468 } | 469 } |
| 469 | 470 |
| 470 // |max_width_| might be smaller than a single character. In this case we | 471 // |max_width_| might be smaller than a single character. In this case we |
| 471 // need to put at least one character in the line. Note that, we should | 472 // need to put at least one character in the line. Note that, we should |
| 472 // not separate surrogate pair or combining characters. | 473 // not separate surrogate pair or combining characters. |
| 473 // See RenderTextTest.Multiline_MinWidth for an example. | 474 // See RenderTextTest.Multiline_MinWidth for an example. |
| 474 if (width == 0 && available_width_ == max_width_) { | 475 if (width == 0 && available_width_ == max_width_) { |
| 475 end_pos = std::min(segment.char_range.end(), | 476 end_pos = std::min( |
| 476 FindValidBoundaryAfter(text_, end_pos + 1)); | 477 segment.char_range.end(), |
| 478 static_cast<uint32_t>(FindValidBoundaryAfter(text_, end_pos + 1))); |
| 477 } | 479 } |
| 478 | 480 |
| 479 return end_pos; | 481 return end_pos; |
| 480 } | 482 } |
| 481 | 483 |
| 482 // Gets the glyph width for |word_range|, and splits the |word| into different | 484 // Gets the glyph width for |word_range|, and splits the |word| into different |
| 483 // segments based on its runs. | 485 // segments based on its runs. |
| 484 SkScalar GetWordWidth(const Range& word_range, | 486 SkScalar GetWordWidth(const Range& word_range, |
| 485 std::vector<internal::LineSegment>* segments) const { | 487 std::vector<internal::LineSegment>* segments) const { |
| 486 DCHECK(words_); | 488 DCHECK(words_); |
| (...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 DCHECK(!update_layout_run_list_); | 1564 DCHECK(!update_layout_run_list_); |
| 1563 DCHECK(!update_display_run_list_); | 1565 DCHECK(!update_display_run_list_); |
| 1564 return text_elided() ? display_run_list_.get() : &layout_run_list_; | 1566 return text_elided() ? display_run_list_.get() : &layout_run_list_; |
| 1565 } | 1567 } |
| 1566 | 1568 |
| 1567 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { | 1569 const internal::TextRunList* RenderTextHarfBuzz::GetRunList() const { |
| 1568 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); | 1570 return const_cast<RenderTextHarfBuzz*>(this)->GetRunList(); |
| 1569 } | 1571 } |
| 1570 | 1572 |
| 1571 } // namespace gfx | 1573 } // namespace gfx |
| OLD | NEW |