Chromium Code Reviews| Index: third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp |
| diff --git a/third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp b/third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp |
| index 9e1d3f5a1436298880b19f5ee96f9472a8696c9d..43f9dd0af0399f70e2bb1ccc996c57e7b678f9c3 100644 |
| --- a/third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp |
| +++ b/third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp |
| @@ -104,6 +104,8 @@ int ShapeResult::RunInfo::CharacterIndexForXPosition( |
| float target_x, |
| bool include_partial_glyphs) const { |
| DCHECK(target_x >= 0 && target_x <= width_); |
| + if (target_x <= 0) |
| + return !Rtl() ? 0 : num_characters_; |
| const unsigned num_glyphs = glyph_data_.size(); |
| float current_x = 0; |
| float current_advance = 0; |
| @@ -125,12 +127,22 @@ int ShapeResult::RunInfo::CharacterIndexForXPosition( |
| // character. |
| current_advance = current_advance / 2.0; |
| next_x = current_x + prev_advance + current_advance; |
| + // When include_partial_glyphs, "<=" or "<" is not a big deal because |
| + // |next_x| is not at the character boundary. |
| + if (target_x <= next_x) |
| + return Rtl() ? prev_character_index : current_character_index; |
| } else { |
| next_x = current_x + current_advance; |
| + if (!Rtl()) { |
|
eae
2017/06/06 00:03:54
How about
static bool targetPastEdge(bool rtl, fl
|
| + // In LTR, the edge belongs to the character on right. |
| + if (target_x < next_x) |
| + return current_character_index; |
| + } else { |
| + // In RTL, the edge belongs to the character on left. |
| + if (target_x <= next_x) |
| + return current_character_index; |
| + } |
| } |
| - if (current_x <= target_x && target_x <= next_x) |
| - return include_partial_glyphs && Rtl() ? prev_character_index |
| - : current_character_index; |
| current_x = next_x; |
| prev_character_index = current_character_index; |
| ++glyph_index; |