Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(598)

Unified Diff: third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp

Issue 2924463002: Fix ShapeResult::OffsetForPosition edge behavior (Closed)
Patch Set: TestExpectations Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaperTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaperTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698