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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 { | 538 { |
539 } | 539 } |
540 | 540 |
541 FloatPoint position; | 541 FloatPoint position; |
542 }; | 542 }; |
543 | 543 |
544 bool SVGTextQuery::characterNumberAtPositionCallback(Data* queryData, const SVGT
extFragment& fragment) const | 544 bool SVGTextQuery::characterNumberAtPositionCallback(Data* queryData, const SVGT
extFragment& fragment) const |
545 { | 545 { |
546 CharacterNumberAtPositionData* data = static_cast<CharacterNumberAtPositionD
ata*>(queryData); | 546 CharacterNumberAtPositionData* data = static_cast<CharacterNumberAtPositionD
ata*>(queryData); |
547 | 547 |
548 // Offset of the fragment within the text box. | 548 // Iterate through the glyphs in this fragment, and check if their extents |
549 unsigned boxOffset = fragment.characterOffset - queryData->textBox->start(); | 549 // contain the query point. |
550 | |
551 FloatRect extent; | 550 FloatRect extent; |
552 for (unsigned i = 0; i < fragment.length; ++i) { | 551 const Vector<SVGTextMetrics>& textMetrics = queryData->textRenderer->layoutA
ttributes()->textMetricsValues(); |
553 int startPosition = data->processedCharacters + boxOffset + i; | 552 unsigned textMetricsOffset = fragment.metricsListOffset; |
554 int endPosition = startPosition + 1; | 553 unsigned fragmentOffset = 0; |
555 if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, st
artPosition, endPosition)) | 554 while (fragmentOffset < fragment.length) { |
556 continue; | 555 calculateGlyphBoundaries(queryData, fragment, fragmentOffset, extent); |
557 | |
558 calculateGlyphBoundaries(queryData, fragment, startPosition, extent); | |
559 if (extent.contains(data->position)) { | 556 if (extent.contains(data->position)) { |
560 data->processedCharacters += boxOffset + i; | 557 // Compute the character offset of the glyph within the text box |
| 558 // and add to processedCharacters. |
| 559 unsigned characterOffset = fragment.characterOffset + fragmentOffset
; |
| 560 data->processedCharacters += characterOffset - data->textBox->start(
); |
561 return true; | 561 return true; |
562 } | 562 } |
| 563 fragmentOffset += textMetrics[textMetricsOffset].length(); |
| 564 textMetricsOffset++; |
563 } | 565 } |
564 | |
565 return false; | 566 return false; |
566 } | 567 } |
567 | 568 |
568 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const | 569 int SVGTextQuery::characterNumberAtPosition(const FloatPoint& position) const |
569 { | 570 { |
570 if (m_textBoxes.isEmpty()) | 571 if (m_textBoxes.isEmpty()) |
571 return -1; | 572 return -1; |
572 | 573 |
573 CharacterNumberAtPositionData data(position); | 574 CharacterNumberAtPositionData data(position); |
574 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback)) | 575 if (!executeQuery(&data, &SVGTextQuery::characterNumberAtPositionCallback)) |
575 return -1; | 576 return -1; |
576 | 577 |
577 return data.processedCharacters; | 578 return data.processedCharacters; |
578 } | 579 } |
579 | 580 |
580 } | 581 } |
OLD | NEW |