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 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); |