Index: Source/core/rendering/svg/SVGTextQuery.cpp |
diff --git a/Source/core/rendering/svg/SVGTextQuery.cpp b/Source/core/rendering/svg/SVGTextQuery.cpp |
index fe7f7c08c3b9c361b9321c7fc1b1a00aac61f0bf..60d90c1795a81c32cda65dfa24a795b37fe81090 100644 |
--- a/Source/core/rendering/svg/SVGTextQuery.cpp |
+++ b/Source/core/rendering/svg/SVGTextQuery.cpp |
@@ -508,6 +508,18 @@ static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const |
extent = fragmentTransform.mapRect(extent); |
} |
+static inline FloatRect calculateFragmentBoundaries(const RenderSVGInlineText& textRenderer, const SVGTextFragment& fragment) |
+{ |
+ float scalingFactor = textRenderer.scalingFactor(); |
+ ASSERT(scalingFactor); |
+ float baseline = textRenderer.scaledFont().fontMetrics().floatAscent() / scalingFactor; |
+ |
+ AffineTransform fragmentTransform; |
+ FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height); |
+ fragment.buildFragmentTransform(fragmentTransform); |
+ return fragmentTransform.mapRect(fragmentRect); |
fs
2014/06/27 14:16:04
(Pondered putting these last four lines in a metho
|
+} |
+ |
bool SVGTextQuery::extentOfCharacterCallback(Data* queryData, const SVGTextFragment& fragment) const |
{ |
ExtentOfCharacterData* data = static_cast<ExtentOfCharacterData*>(queryData); |
@@ -545,6 +557,11 @@ bool SVGTextQuery::characterNumberAtPositionCallback(Data* queryData, const SVGT |
{ |
CharacterNumberAtPositionData* data = static_cast<CharacterNumberAtPositionData*>(queryData); |
+ // Test the query point against the bounds of the entire fragment first. |
+ FloatRect fragmentExtents = calculateFragmentBoundaries(*queryData->textRenderer, fragment); |
+ if (!fragmentExtents.contains(data->position)) |
+ return false; |
+ |
// Iterate through the glyphs in this fragment, and check if their extents |
// contain the query point. |
FloatRect extent; |