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

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

Issue 1045793002: Determine the right SVGTextMetrics using the correct approach (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add test. Created 5 years, 9 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 | « LayoutTests/svg/text/getextentofchar-nonbmp-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/layout/svg/SVGTextQuery.cpp
diff --git a/Source/core/layout/svg/SVGTextQuery.cpp b/Source/core/layout/svg/SVGTextQuery.cpp
index e152abb11612fd7119e2655a8fa04c34ee95344d..2fa358df026b86ceada57817e3276995fbf90361 100644
--- a/Source/core/layout/svg/SVGTextQuery.cpp
+++ b/Source/core/layout/svg/SVGTextQuery.cpp
@@ -420,6 +420,21 @@ struct ExtentOfCharacterData : SVGTextQuery::Data {
FloatRect extent;
};
+const SVGTextMetrics& findMetricsForCharacter(const Vector<SVGTextMetrics>& textMetricsValues, const SVGTextFragment& fragment, unsigned startInFragment)
+{
+ // Find the text metrics cell that start at or contain the character at |startInFragment|.
+ unsigned textMetricsOffset = fragment.metricsListOffset;
+ unsigned fragmentOffset = 0;
+ while (fragmentOffset < fragment.length) {
+ const SVGTextMetrics& metrics = textMetricsValues[textMetricsOffset++];
+ unsigned glyphEnd = fragmentOffset + metrics.length();
+ if (startInFragment < glyphEnd)
+ break;
+ fragmentOffset = glyphEnd;
+ }
+ return textMetricsValues[textMetricsOffset - 1];
+}
+
static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const SVGTextFragment& fragment, int startPosition, FloatRect& extent)
{
float scalingFactor = queryData->textLayoutObject->scalingFactor();
@@ -432,8 +447,8 @@ static inline void calculateGlyphBoundaries(SVGTextQuery::Data* queryData, const
// Use the SVGTextMetrics computed by SVGTextMetricsBuilder (which spends
// time attempting to compute more correct glyph bounds already, handling
// cursive scripts to some degree.)
- Vector<SVGTextMetrics>& textMetricsValues = queryData->textLayoutObject->layoutAttributes()->textMetricsValues();
- const SVGTextMetrics& metrics = textMetricsValues[fragment.characterOffset + startPosition];
+ const Vector<SVGTextMetrics>& textMetricsValues = queryData->textLayoutObject->layoutAttributes()->textMetricsValues();
+ const SVGTextMetrics& metrics = findMetricsForCharacter(textMetricsValues, fragment, startPosition);
// TODO(fs): Negative glyph extents seems kind of weird to have, but
// presently it can occur in some cases (like Arabic.)
« no previous file with comments | « LayoutTests/svg/text/getextentofchar-nonbmp-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698