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

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

Issue 2924463002: Fix ShapeResult::OffsetForPosition edge behavior (Closed)
Patch Set: eae review suggestion 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..16a087b7c0504acbd01de2a117f82435eeb4deb6 100644
--- a/third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp
+++ b/third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp
@@ -100,10 +100,21 @@ float ShapeResult::RunInfo::XPositionForOffset(
return position;
}
+static bool TargetPastEdge(bool rtl, float target_x, float next_x) {
+ // In LTR, the edge belongs to the character on right.
+ if (!rtl)
+ return target_x < next_x;
+
+ // In RTL, the edge belongs to the character on left.
+ return target_x <= next_x;
+}
+
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 +136,15 @@ 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 (TargetPastEdge(Rtl(), 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