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

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

Issue 183203003: Reduce state kept in MeasureTextData by SVGTextMetricsBuilder (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 | « Source/core/rendering/svg/SVGTextMetricsBuilder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/svg/SVGTextMetricsBuilder.cpp
diff --git a/Source/core/rendering/svg/SVGTextMetricsBuilder.cpp b/Source/core/rendering/svg/SVGTextMetricsBuilder.cpp
index a0d6c70218f06e17e56be25718ee1ba87e4664ae..a7cccd026d5456ea721e521447ea754b507112cc 100644
--- a/Source/core/rendering/svg/SVGTextMetricsBuilder.cpp
+++ b/Source/core/rendering/svg/SVGTextMetricsBuilder.cpp
@@ -112,29 +112,23 @@ void SVGTextMetricsBuilder::initializeMeasurementWithTextRenderer(RenderSVGInlin
struct MeasureTextData {
MeasureTextData(SVGCharacterDataMap* characterDataMap)
: allCharactersMap(characterDataMap)
- , hasLastCharacter(false)
- , lastCharacter(0)
- , processRenderer(false)
+ , lastCharacterWasWhiteSpace(true)
, valueListPosition(0)
- , skippedCharacters(0)
{
}
SVGCharacterDataMap* allCharactersMap;
- bool hasLastCharacter;
- UChar lastCharacter;
- bool processRenderer;
+ bool lastCharacterWasWhiteSpace;
unsigned valueListPosition;
- unsigned skippedCharacters;
};
-void SVGTextMetricsBuilder::measureTextRenderer(RenderSVGInlineText* text, MeasureTextData* data)
+void SVGTextMetricsBuilder::measureTextRenderer(RenderSVGInlineText* text, MeasureTextData* data, bool processRenderer)
{
ASSERT(text);
SVGTextLayoutAttributes* attributes = text->layoutAttributes();
Vector<SVGTextMetrics>* textMetricsValues = &attributes->textMetricsValues();
- if (data->processRenderer) {
+ if (processRenderer) {
if (data->allCharactersMap)
attributes->clear();
else
@@ -143,21 +137,22 @@ void SVGTextMetricsBuilder::measureTextRenderer(RenderSVGInlineText* text, Measu
initializeMeasurementWithTextRenderer(text);
bool preserveWhiteSpace = text->style()->whiteSpace() == PRE;
- int surrogatePairCharacters = 0;
+ unsigned surrogatePairCharacters = 0;
+ unsigned skippedCharacters = 0;
while (advance()) {
- UChar currentCharacter = m_run[m_textPosition];
- if (currentCharacter == ' ' && !preserveWhiteSpace && (!data->hasLastCharacter || data->lastCharacter == ' ')) {
- if (data->processRenderer)
+ bool characterIsWhiteSpace = m_run[m_textPosition] == ' ';
+ if (characterIsWhiteSpace && !preserveWhiteSpace && data->lastCharacterWasWhiteSpace) {
+ if (processRenderer)
textMetricsValues->append(SVGTextMetrics(SVGTextMetrics::SkippedSpaceMetrics));
if (data->allCharactersMap)
- data->skippedCharacters += m_currentMetrics.length();
+ skippedCharacters += m_currentMetrics.length();
continue;
}
- if (data->processRenderer) {
+ if (processRenderer) {
if (data->allCharactersMap) {
- const SVGCharacterDataMap::const_iterator it = data->allCharactersMap->find(data->valueListPosition + m_textPosition - data->skippedCharacters - surrogatePairCharacters + 1);
+ const SVGCharacterDataMap::const_iterator it = data->allCharactersMap->find(data->valueListPosition + m_textPosition - skippedCharacters - surrogatePairCharacters + 1);
if (it != data->allCharactersMap->end())
attributes->characterDataMap().set(m_textPosition + 1, it->value);
}
@@ -167,15 +162,13 @@ void SVGTextMetricsBuilder::measureTextRenderer(RenderSVGInlineText* text, Measu
if (data->allCharactersMap && currentCharacterStartsSurrogatePair())
surrogatePairCharacters++;
- data->hasLastCharacter = true;
- data->lastCharacter = currentCharacter;
+ data->lastCharacterWasWhiteSpace = characterIsWhiteSpace;
}
if (!data->allCharactersMap)
return;
- data->valueListPosition += m_textPosition - data->skippedCharacters;
- data->skippedCharacters = 0;
+ data->valueListPosition += m_textPosition - skippedCharacters;
}
void SVGTextMetricsBuilder::walkTree(RenderObject* start, RenderSVGInlineText* stopAtLeaf, MeasureTextData* data)
@@ -184,8 +177,7 @@ void SVGTextMetricsBuilder::walkTree(RenderObject* start, RenderSVGInlineText* s
while (child) {
if (child->isSVGInlineText()) {
RenderSVGInlineText* text = toRenderSVGInlineText(child);
- data->processRenderer = !stopAtLeaf || stopAtLeaf == text;
- measureTextRenderer(text, data);
+ measureTextRenderer(text, data, !stopAtLeaf || stopAtLeaf == text);
if (stopAtLeaf && stopAtLeaf == text)
return;
} else if (child->isSVGInline()) {
« no previous file with comments | « Source/core/rendering/svg/SVGTextMetricsBuilder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698