Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/svg/SVGTextQuery.cpp |
| diff --git a/third_party/WebKit/Source/core/layout/svg/SVGTextQuery.cpp b/third_party/WebKit/Source/core/layout/svg/SVGTextQuery.cpp |
| index 865eaac6026ea7f636a2ce46526039ea84b7f08f..3f0240069fc1d04092cc0dd46b35fc7c722ea2bc 100644 |
| --- a/third_party/WebKit/Source/core/layout/svg/SVGTextQuery.cpp |
| +++ b/third_party/WebKit/Source/core/layout/svg/SVGTextQuery.cpp |
| @@ -256,6 +256,35 @@ float SVGTextQuery::textLength() const |
| return data.textLength; |
| } |
| +const SVGTextMetrics& findMetricsForCharacter(const Vector<SVGTextMetrics>& textMetricsValues, const SVGTextFragment& fragment, unsigned startInFragment) |
| +{ |
| + // Find the text metrics cell that starts at or contains 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 float calculateGlyphRange(const QueryData* queryData, const SVGTextFragment& fragment, unsigned start, unsigned end) |
| +{ |
| + float glyphRange = 0; |
| + if (end <= start) |
|
fs
2016/03/09 09:55:42
Nit: I believe this should be uncommon enough here
pdr.
2016/03/09 19:13:50
SGTM, done.
|
| + return glyphRange; |
| + |
| + const Vector<SVGTextMetrics>& textMetricsValues = queryData->textLineLayout.layoutAttributes()->textMetricsValues(); |
| + for (unsigned character = start; character < end; character++) { |
| + SVGTextMetrics metrics = findMetricsForCharacter(textMetricsValues, fragment, character); |
|
fs
2016/03/09 09:55:42
Nit: const SVGTextMetrics&
pdr.
2016/03/09 19:13:50
Done.
|
| + glyphRange += queryData->isVerticalText ? metrics.height() : metrics.width(); |
| + } |
| + return glyphRange; |
| +} |
| + |
| // subStringLength() implementation |
| struct SubStringLengthData : QueryData { |
| SubStringLengthData(unsigned queryStartPosition, unsigned queryLength) |
| @@ -280,8 +309,7 @@ static bool subStringLengthCallback(QueryData* queryData, const SVGTextFragment& |
| if (!mapStartEndPositionsIntoFragmentCoordinates(queryData, fragment, startPosition, endPosition)) |
| return false; |
| - SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData->textLineLayout, fragment.characterOffset + startPosition, endPosition - startPosition, queryData->textBox->direction()); |
| - data->subStringLength += queryData->isVerticalText ? metrics.height() : metrics.width(); |
| + data->subStringLength += calculateGlyphRange(queryData, fragment, startPosition, endPosition); |
| return false; |
| } |
| @@ -305,14 +333,7 @@ struct StartPositionOfCharacterData : QueryData { |
| static FloatPoint calculateGlyphPositionWithoutTransform(const QueryData* queryData, const SVGTextFragment& fragment, int offsetInFragment) |
| { |
| - float glyphOffsetInDirection = 0; |
| - if (offsetInFragment) { |
| - SVGTextMetrics metrics = SVGTextMetrics::measureCharacterRange(queryData->textLineLayout, fragment.characterOffset, offsetInFragment, queryData->textBox->direction()); |
| - if (queryData->isVerticalText) |
| - glyphOffsetInDirection = metrics.height(); |
| - else |
| - glyphOffsetInDirection = metrics.width(); |
| - } |
| + float glyphOffsetInDirection = calculateGlyphRange(queryData, fragment, 0, offsetInFragment); |
| if (!queryData->textBox->isLeftToRightDirection()) { |
| float fragmentExtent = queryData->isVerticalText ? fragment.height : fragment.width; |
| @@ -441,21 +462,6 @@ struct ExtentOfCharacterData : QueryData { |
| 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(const QueryData* queryData, const SVGTextFragment& fragment, int startPosition, FloatRect& extent) |
| { |
| float scalingFactor = queryData->textLineLayout.scalingFactor(); |