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

Unified Diff: Source/core/rendering/svg/SVGTextQuery.cpp

Issue 355173002: Add per-fragment early-out for getCharNumAtPosition (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 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;
« 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