| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/fonts/shaping/ShapeResultBuffer.h" | 5 #include "platform/fonts/shaping/ShapeResultBuffer.h" |
| 6 | 6 |
| 7 #include "platform/fonts/CharacterRange.h" | 7 #include "platform/fonts/CharacterRange.h" |
| 8 #include "platform/fonts/GlyphBuffer.h" | 8 #include "platform/fonts/GlyphBuffer.h" |
| 9 #include "platform/fonts/SimpleFontData.h" | 9 #include "platform/fonts/SimpleFontData.h" |
| 10 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" | 10 #include "platform/fonts/shaping/ShapeResultInlineHeaders.h" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 unsigned runIndex = direction == RTL ? runCount - 1 - index : index; | 372 unsigned runIndex = direction == RTL ? runCount - 1 - index : index; |
| 373 addRunInfoRanges(*result->m_runs[runIndex], currentX, ranges); | 373 addRunInfoRanges(*result->m_runs[runIndex], currentX, ranges); |
| 374 currentX += result->m_runs[runIndex]->m_width; | 374 currentX += result->m_runs[runIndex]->m_width; |
| 375 } | 375 } |
| 376 if (direction == RTL) | 376 if (direction == RTL) |
| 377 currentX -= result->width(); | 377 currentX -= result->width(); |
| 378 } | 378 } |
| 379 return ranges; | 379 return ranges; |
| 380 } | 380 } |
| 381 | 381 |
| 382 int ShapeResultBuffer::offsetForPosition(const TextRun& run, float targetX) cons
t | 382 int ShapeResultBuffer::offsetForPosition(const TextRun& run, float targetX, bool
includePartialGlyphs) const |
| 383 { | 383 { |
| 384 unsigned totalOffset; | 384 unsigned totalOffset; |
| 385 if (run.rtl()) { | 385 if (run.rtl()) { |
| 386 totalOffset = run.length(); | 386 totalOffset = run.length(); |
| 387 for (unsigned i = m_results.size(); i; --i) { | 387 for (unsigned i = m_results.size(); i; --i) { |
| 388 const RefPtr<const ShapeResult>& wordResult = m_results[i - 1]; | 388 const RefPtr<const ShapeResult>& wordResult = m_results[i - 1]; |
| 389 if (!wordResult) | 389 if (!wordResult) |
| 390 continue; | 390 continue; |
| 391 totalOffset -= wordResult->numCharacters(); | 391 totalOffset -= wordResult->numCharacters(); |
| 392 if (targetX >= 0 && targetX <= wordResult->width()) { | 392 if (targetX >= 0 && targetX <= wordResult->width()) { |
| 393 int offsetForWord = wordResult->offsetForPosition(targetX); | 393 int offsetForWord = wordResult->offsetForPosition(targetX, inclu
dePartialGlyphs); |
| 394 return totalOffset + offsetForWord; | 394 return totalOffset + offsetForWord; |
| 395 } | 395 } |
| 396 targetX -= wordResult->width(); | 396 targetX -= wordResult->width(); |
| 397 } | 397 } |
| 398 } else { | 398 } else { |
| 399 totalOffset = 0; | 399 totalOffset = 0; |
| 400 for (const auto& wordResult : m_results) { | 400 for (const auto& wordResult : m_results) { |
| 401 if (!wordResult) | 401 if (!wordResult) |
| 402 continue; | 402 continue; |
| 403 int offsetForWord = wordResult->offsetForPosition(targetX); | 403 int offsetForWord = wordResult->offsetForPosition(targetX, includePa
rtialGlyphs); |
| 404 ASSERT(offsetForWord >= 0); | 404 ASSERT(offsetForWord >= 0); |
| 405 totalOffset += offsetForWord; | 405 totalOffset += offsetForWord; |
| 406 if (targetX >= 0 && targetX <= wordResult->width()) | 406 if (targetX >= 0 && targetX <= wordResult->width()) |
| 407 return totalOffset; | 407 return totalOffset; |
| 408 targetX -= wordResult->width(); | 408 targetX -= wordResult->width(); |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 return totalOffset; | 411 return totalOffset; |
| 412 } | 412 } |
| 413 | 413 |
| 414 } // namespace blink | 414 } // namespace blink |
| OLD | NEW |