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

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

Issue 2739993002: Add ShapeResult::positionForOffset method (Closed)
Patch Set: Created 3 years, 9 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/ShapeResult.h ('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 c844454624f9075ddbd65735e62e65a31662cd38..504df23d42d2a7f45f845ac2badafe006b6531d7 100644
--- a/third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp
+++ b/third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.cpp
@@ -181,9 +181,9 @@ size_t ShapeResult::byteSize() const {
return selfByteSize;
}
-int ShapeResult::offsetForPosition(float targetX,
- bool includePartialGlyphs) const {
- int charactersSoFar = 0;
+unsigned ShapeResult::offsetForPosition(float targetX,
+ bool includePartialGlyphs) const {
+ unsigned charactersSoFar = 0;
float currentX = 0;
if (rtl()) {
@@ -221,6 +221,49 @@ int ShapeResult::offsetForPosition(float targetX,
return charactersSoFar;
}
+float ShapeResult::positionForOffset(unsigned absoluteOffset) const {
eae 2017/03/09 05:16:32 This is similar to how ShapeResultBuffer::getChara
+ float x = 0;
+ float offsetX = 0;
+
+ // The absoluteOffset argument represents the offset for the entire
+ // ShapeResult while offset is continuously updated to be relative to the
+ // current run.
+ unsigned offset = absoluteOffset;
+
+ if (rtl()) {
+ // Convert logical offsets to visual offsets, because results are in
+ // logical order while runs are in visual order.
+ x = m_width;
+ if (offset < numCharacters())
+ offset = numCharacters() - offset - 1;
+ x -= width();
+ }
+
+ for (unsigned i = 0; i < m_runs.size(); i++) {
+ if (!m_runs[i])
+ continue;
+ DCHECK_EQ(rtl(), m_runs[i]->rtl());
+ unsigned numCharacters = m_runs[i]->m_numCharacters;
+
+ if (!offsetX && offset < numCharacters) {
+ offsetX = m_runs[i]->xPositionForVisualOffset(offset, AdjustToEnd) + x;
+ break;
+ }
+
+ offset -= numCharacters;
+ x += m_runs[i]->m_width;
+ }
+
+ if (rtl())
+ x -= width();
+
+ // The position in question might be just after the text.
+ if (!offsetX && absoluteOffset == numCharacters())
+ return rtl() ? 0 : m_width;
+
+ return offsetX;
+}
+
void ShapeResult::fallbackFonts(
HashSet<const SimpleFontData*>* fallback) const {
ASSERT(fallback);
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/shaping/ShapeResult.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698