OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 { | 511 { |
512 } | 512 } |
513 | 513 |
514 FloatPoint position; | 514 FloatPoint position; |
515 }; | 515 }; |
516 | 516 |
517 bool SVGTextQuery::characterNumberAtPositionCallback(Data* queryData, const SVGT
extFragment& fragment) const | 517 bool SVGTextQuery::characterNumberAtPositionCallback(Data* queryData, const SVGT
extFragment& fragment) const |
518 { | 518 { |
519 CharacterNumberAtPositionData* data = static_cast<CharacterNumberAtPositionD
ata*>(queryData); | 519 CharacterNumberAtPositionData* data = static_cast<CharacterNumberAtPositionD
ata*>(queryData); |
520 | 520 |
| 521 // Offset of the fragment within the text box. |
| 522 unsigned boxOffset = fragment.characterOffset - queryData->textBox->start(); |
| 523 |
521 FloatRect extent; | 524 FloatRect extent; |
522 for (unsigned i = 0; i < fragment.length; ++i) { | 525 for (unsigned i = 0; i < fragment.length; ++i) { |
523 int startPosition = data->processedCharacters + i; | 526 int startPosition = data->processedCharacters + boxOffset + i; |
524 int endPosition = startPosition + 1; | 527 int endPosition = startPosition + 1; |
525 if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, st
artPosition, endPosition)) | 528 if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, st
artPosition, endPosition)) |
526 continue; | 529 continue; |
527 | 530 |
528 calculateGlyphBoundaries(queryData, fragment, startPosition, extent); | 531 calculateGlyphBoundaries(queryData, fragment, startPosition, extent); |
529 if (extent.contains(data->position)) { | 532 if (extent.contains(data->position)) { |
530 data->processedCharacters += i; | 533 data->processedCharacters += boxOffset + i; |
531 return true; | 534 return true; |
532 } | 535 } |
533 } | 536 } |
534 | 537 |
535 return false; | 538 return false; |
536 } | 539 } |
537 | 540 |
538 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const | 541 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const |
539 { | 542 { |
540 if (m_textBoxes.isEmpty()) | 543 if (m_textBoxes.isEmpty()) |
541 return -1; | 544 return -1; |
542 | 545 |
543 CharacterNumberAtPositionData data(position); | 546 CharacterNumberAtPositionData data(position); |
544 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback)) | 547 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback)) |
545 return -1; | 548 return -1; |
546 | 549 |
547 return data.processedCharacters; | 550 return data.processedCharacters; |
548 } | 551 } |
549 | 552 |
550 } | 553 } |
OLD | NEW |