Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Side by Side Diff: Source/core/rendering/svg/SVGTextQuery.cpp

Issue 353003002: Simplify (and optimize) SVGTextQuery::characterNumberAtPositionCallback (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698