OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2012 Google Inc. All rights reserved. |
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. | 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "config.h" | 32 #include "config.h" |
33 #include "platform/fonts/shaping/HarfBuzzShaper.h" | 33 #include "platform/fonts/shaping/HarfBuzzShaper.h" |
34 | 34 |
35 #include "hb.h" | 35 #include "hb.h" |
36 #include "platform/LayoutUnit.h" | 36 #include "platform/LayoutUnit.h" |
37 #include "platform/RuntimeEnabledFeatures.h" | 37 #include "platform/RuntimeEnabledFeatures.h" |
38 #include "platform/fonts/Character.h" | 38 #include "platform/fonts/Character.h" |
39 #include "platform/fonts/Font.h" | 39 #include "platform/fonts/Font.h" |
40 #include "platform/fonts/GlyphBuffer.h" | 40 #include "platform/fonts/GlyphBuffer.h" |
41 #include "platform/fonts/UTF16TextIterator.h" | 41 #include "platform/fonts/UTF16TextIterator.h" |
| 42 #include "platform/fonts/shaping/CachingWordShapeIterator.h" |
42 #include "platform/fonts/shaping/HarfBuzzFace.h" | 43 #include "platform/fonts/shaping/HarfBuzzFace.h" |
43 #include "platform/text/TextBreakIterator.h" | 44 #include "platform/text/TextBreakIterator.h" |
44 #include "wtf/Compiler.h" | 45 #include "wtf/Compiler.h" |
45 #include "wtf/MathExtras.h" | 46 #include "wtf/MathExtras.h" |
46 #include "wtf/text/Unicode.h" | 47 #include "wtf/text/Unicode.h" |
47 | 48 |
48 #include <list> | 49 #include <list> |
49 #include <map> | 50 #include <map> |
50 #include <string> | 51 #include <string> |
51 #include <unicode/normlzr.h> | 52 #include <unicode/normlzr.h> |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 toX = direction == RTL ? 0 : totalWidth; | 435 toX = direction == RTL ? 0 : totalWidth; |
435 | 436 |
436 // None of our runs is part of the selection, possibly invalid arguments. | 437 // None of our runs is part of the selection, possibly invalid arguments. |
437 if (!foundToX && !foundFromX) | 438 if (!foundToX && !foundFromX) |
438 fromX = toX = 0; | 439 fromX = toX = 0; |
439 if (fromX < toX) | 440 if (fromX < toX) |
440 return FloatRect(point.x() + fromX, point.y(), toX - fromX, height); | 441 return FloatRect(point.x() + fromX, point.y(), toX - fromX, height); |
441 return FloatRect(point.x() + toX, point.y(), fromX - toX, height); | 442 return FloatRect(point.x() + toX, point.y(), fromX - toX, height); |
442 } | 443 } |
443 | 444 |
| 445 int ShapeResult::offsetForPosition(CachingWordShapeIterator& iterator, |
| 446 const TextRun& run, float targetX) |
| 447 { |
| 448 RefPtr<ShapeResult> wordResult; |
| 449 unsigned totalOffset; |
| 450 if (run.rtl()) { |
| 451 totalOffset = run.length(); |
| 452 while (iterator.next(&wordResult)) { |
| 453 if (!wordResult) |
| 454 continue; |
| 455 totalOffset -= wordResult->numCharacters(); |
| 456 if (targetX >= 0 && targetX <= wordResult->width()) { |
| 457 int offsetForWord = wordResult->offsetForPosition(targetX); |
| 458 return totalOffset + offsetForWord; |
| 459 } |
| 460 targetX -= wordResult->width(); |
| 461 } |
| 462 } else { |
| 463 totalOffset = 0; |
| 464 while (iterator.next(&wordResult)) { |
| 465 if (!wordResult) |
| 466 continue; |
| 467 int offsetForWord = wordResult->offsetForPosition(targetX); |
| 468 ASSERT(offsetForWord >= 0); |
| 469 totalOffset += offsetForWord; |
| 470 if (targetX >= 0 && targetX <= wordResult->width()) |
| 471 return totalOffset; |
| 472 targetX -= wordResult->width(); |
| 473 } |
| 474 } |
| 475 return totalOffset; |
| 476 } |
| 477 |
444 int ShapeResult::offsetForPosition(float targetX) | 478 int ShapeResult::offsetForPosition(float targetX) |
445 { | 479 { |
446 int charactersSoFar = 0; | 480 int charactersSoFar = 0; |
447 float currentX = 0; | 481 float currentX = 0; |
448 | 482 |
449 if (m_direction == RTL) { | 483 if (m_direction == RTL) { |
450 charactersSoFar = m_numCharacters; | 484 charactersSoFar = m_numCharacters; |
451 for (unsigned i = 0; i < m_runs.size(); ++i) { | 485 for (unsigned i = 0; i < m_runs.size(); ++i) { |
452 if (!m_runs[i]) | 486 if (!m_runs[i]) |
453 continue; | 487 continue; |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 return spacing; | 1187 return spacing; |
1154 } | 1188 } |
1155 | 1189 |
1156 // Don't need to check m_textRun.allowsTrailingExpansion() since it's covere
d by !m_expansionOpportunityCount above | 1190 // Don't need to check m_textRun.allowsTrailingExpansion() since it's covere
d by !m_expansionOpportunityCount above |
1157 spacing += nextExpansionPerOpportunity(); | 1191 spacing += nextExpansionPerOpportunity(); |
1158 m_isAfterExpansion = true; | 1192 m_isAfterExpansion = true; |
1159 return spacing; | 1193 return spacing; |
1160 } | 1194 } |
1161 | 1195 |
1162 } // namespace blink | 1196 } // namespace blink |
OLD | NEW |