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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/svg/SVGTextQuery.cpp
diff --git a/Source/core/rendering/svg/SVGTextQuery.cpp b/Source/core/rendering/svg/SVGTextQuery.cpp
index e9096d9bab498b9bbaf7113a2e0e8a24ff47013f..fe7f7c08c3b9c361b9321c7fc1b1a00aac61f0bf 100644
--- a/Source/core/rendering/svg/SVGTextQuery.cpp
+++ b/Source/core/rendering/svg/SVGTextQuery.cpp
@@ -545,23 +545,24 @@ bool SVGTextQuery::characterNumberAtPositionCallback(Data* queryData, const SVGT
{
CharacterNumberAtPositionData* data = static_cast<CharacterNumberAtPositionData*>(queryData);
- // Offset of the fragment within the text box.
- unsigned boxOffset = fragment.characterOffset - queryData->textBox->start();
-
+ // Iterate through the glyphs in this fragment, and check if their extents
+ // contain the query point.
FloatRect extent;
- for (unsigned i = 0; i < fragment.length; ++i) {
- int startPosition = data->processedCharacters + boxOffset + i;
- int endPosition = startPosition + 1;
- if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition))
- continue;
-
- calculateGlyphBoundaries(queryData, fragment, startPosition, extent);
+ const Vector<SVGTextMetrics>& textMetrics = queryData->textRenderer->layoutAttributes()->textMetricsValues();
+ unsigned textMetricsOffset = fragment.metricsListOffset;
+ unsigned fragmentOffset = 0;
+ while (fragmentOffset < fragment.length) {
+ calculateGlyphBoundaries(queryData, fragment, fragmentOffset, extent);
if (extent.contains(data->position)) {
- data->processedCharacters += boxOffset + i;
+ // Compute the character offset of the glyph within the text box
+ // and add to processedCharacters.
+ unsigned characterOffset = fragment.characterOffset + fragmentOffset;
+ data->processedCharacters += characterOffset - data->textBox->start();
return true;
}
+ fragmentOffset += textMetrics[textMetricsOffset].length();
+ textMetricsOffset++;
}
-
return false;
}
« 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