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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/svg/SVGTextMetricsBuilder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 if (m_isComplexText) 106 if (m_isComplexText)
107 m_simpleWidthIterator.clear(); 107 m_simpleWidthIterator.clear();
108 else 108 else
109 m_simpleWidthIterator = adoptPtr(new WidthIterator(&scaledFont, m_run)); 109 m_simpleWidthIterator = adoptPtr(new WidthIterator(&scaledFont, m_run));
110 } 110 }
111 111
112 struct MeasureTextData { 112 struct MeasureTextData {
113 MeasureTextData(SVGCharacterDataMap* characterDataMap) 113 MeasureTextData(SVGCharacterDataMap* characterDataMap)
114 : allCharactersMap(characterDataMap) 114 : allCharactersMap(characterDataMap)
115 , hasLastCharacter(false) 115 , lastCharacterWasWhiteSpace(true)
116 , lastCharacter(0)
117 , processRenderer(false)
118 , valueListPosition(0) 116 , valueListPosition(0)
119 , skippedCharacters(0)
120 { 117 {
121 } 118 }
122 119
123 SVGCharacterDataMap* allCharactersMap; 120 SVGCharacterDataMap* allCharactersMap;
124 bool hasLastCharacter; 121 bool lastCharacterWasWhiteSpace;
125 UChar lastCharacter;
126 bool processRenderer;
127 unsigned valueListPosition; 122 unsigned valueListPosition;
128 unsigned skippedCharacters;
129 }; 123 };
130 124
131 void SVGTextMetricsBuilder::measureTextRenderer(RenderSVGInlineText* text, Measu reTextData* data) 125 void SVGTextMetricsBuilder::measureTextRenderer(RenderSVGInlineText* text, Measu reTextData* data, bool processRenderer)
132 { 126 {
133 ASSERT(text); 127 ASSERT(text);
134 128
135 SVGTextLayoutAttributes* attributes = text->layoutAttributes(); 129 SVGTextLayoutAttributes* attributes = text->layoutAttributes();
136 Vector<SVGTextMetrics>* textMetricsValues = &attributes->textMetricsValues() ; 130 Vector<SVGTextMetrics>* textMetricsValues = &attributes->textMetricsValues() ;
137 if (data->processRenderer) { 131 if (processRenderer) {
138 if (data->allCharactersMap) 132 if (data->allCharactersMap)
139 attributes->clear(); 133 attributes->clear();
140 else 134 else
141 textMetricsValues->clear(); 135 textMetricsValues->clear();
142 } 136 }
143 137
144 initializeMeasurementWithTextRenderer(text); 138 initializeMeasurementWithTextRenderer(text);
145 bool preserveWhiteSpace = text->style()->whiteSpace() == PRE; 139 bool preserveWhiteSpace = text->style()->whiteSpace() == PRE;
146 int surrogatePairCharacters = 0; 140 unsigned surrogatePairCharacters = 0;
141 unsigned skippedCharacters = 0;
147 142
148 while (advance()) { 143 while (advance()) {
149 UChar currentCharacter = m_run[m_textPosition]; 144 bool characterIsWhiteSpace = m_run[m_textPosition] == ' ';
150 if (currentCharacter == ' ' && !preserveWhiteSpace && (!data->hasLastCha racter || data->lastCharacter == ' ')) { 145 if (characterIsWhiteSpace && !preserveWhiteSpace && data->lastCharacterW asWhiteSpace) {
151 if (data->processRenderer) 146 if (processRenderer)
152 textMetricsValues->append(SVGTextMetrics(SVGTextMetrics::Skipped SpaceMetrics)); 147 textMetricsValues->append(SVGTextMetrics(SVGTextMetrics::Skipped SpaceMetrics));
153 if (data->allCharactersMap) 148 if (data->allCharactersMap)
154 data->skippedCharacters += m_currentMetrics.length(); 149 skippedCharacters += m_currentMetrics.length();
155 continue; 150 continue;
156 } 151 }
157 152
158 if (data->processRenderer) { 153 if (processRenderer) {
159 if (data->allCharactersMap) { 154 if (data->allCharactersMap) {
160 const SVGCharacterDataMap::const_iterator it = data->allCharacte rsMap->find(data->valueListPosition + m_textPosition - data->skippedCharacters - surrogatePairCharacters + 1); 155 const SVGCharacterDataMap::const_iterator it = data->allCharacte rsMap->find(data->valueListPosition + m_textPosition - skippedCharacters - surro gatePairCharacters + 1);
161 if (it != data->allCharactersMap->end()) 156 if (it != data->allCharactersMap->end())
162 attributes->characterDataMap().set(m_textPosition + 1, it->v alue); 157 attributes->characterDataMap().set(m_textPosition + 1, it->v alue);
163 } 158 }
164 textMetricsValues->append(m_currentMetrics); 159 textMetricsValues->append(m_currentMetrics);
165 } 160 }
166 161
167 if (data->allCharactersMap && currentCharacterStartsSurrogatePair()) 162 if (data->allCharactersMap && currentCharacterStartsSurrogatePair())
168 surrogatePairCharacters++; 163 surrogatePairCharacters++;
169 164
170 data->hasLastCharacter = true; 165 data->lastCharacterWasWhiteSpace = characterIsWhiteSpace;
171 data->lastCharacter = currentCharacter;
172 } 166 }
173 167
174 if (!data->allCharactersMap) 168 if (!data->allCharactersMap)
175 return; 169 return;
176 170
177 data->valueListPosition += m_textPosition - data->skippedCharacters; 171 data->valueListPosition += m_textPosition - skippedCharacters;
178 data->skippedCharacters = 0;
179 } 172 }
180 173
181 void SVGTextMetricsBuilder::walkTree(RenderObject* start, RenderSVGInlineText* s topAtLeaf, MeasureTextData* data) 174 void SVGTextMetricsBuilder::walkTree(RenderObject* start, RenderSVGInlineText* s topAtLeaf, MeasureTextData* data)
182 { 175 {
183 RenderObject* child = start->firstChild(); 176 RenderObject* child = start->firstChild();
184 while (child) { 177 while (child) {
185 if (child->isSVGInlineText()) { 178 if (child->isSVGInlineText()) {
186 RenderSVGInlineText* text = toRenderSVGInlineText(child); 179 RenderSVGInlineText* text = toRenderSVGInlineText(child);
187 data->processRenderer = !stopAtLeaf || stopAtLeaf == text; 180 measureTextRenderer(text, data, !stopAtLeaf || stopAtLeaf == text);
188 measureTextRenderer(text, data);
189 if (stopAtLeaf && stopAtLeaf == text) 181 if (stopAtLeaf && stopAtLeaf == text)
190 return; 182 return;
191 } else if (child->isSVGInline()) { 183 } else if (child->isSVGInline()) {
192 // Visit children of text content elements. 184 // Visit children of text content elements.
193 if (RenderObject* inlineChild = child->firstChild()) { 185 if (RenderObject* inlineChild = child->firstChild()) {
194 child = inlineChild; 186 child = inlineChild;
195 continue; 187 continue;
196 } 188 }
197 } 189 }
198 child = child->nextInPreOrderAfterChildren(start); 190 child = child->nextInPreOrderAfterChildren(start);
(...skipping 13 matching lines...) Expand all
212 } 204 }
213 205
214 void SVGTextMetricsBuilder::buildMetricsAndLayoutAttributes(RenderSVGText* textR oot, RenderSVGInlineText* stopAtLeaf, SVGCharacterDataMap& allCharactersMap) 206 void SVGTextMetricsBuilder::buildMetricsAndLayoutAttributes(RenderSVGText* textR oot, RenderSVGInlineText* stopAtLeaf, SVGCharacterDataMap& allCharactersMap)
215 { 207 {
216 ASSERT(textRoot); 208 ASSERT(textRoot);
217 MeasureTextData data(&allCharactersMap); 209 MeasureTextData data(&allCharactersMap);
218 walkTree(textRoot, stopAtLeaf, &data); 210 walkTree(textRoot, stopAtLeaf, &data);
219 } 211 }
220 212
221 } 213 }
OLDNEW
« 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