OLD | NEW |
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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 attributesToUpdate->clearExistingAttributes(); | 263 attributesToUpdate->clearExistingAttributes(); |
264 | 264 |
265 if (!textLayoutItem.textLength()) | 265 if (!textLayoutItem.textLength()) |
266 return; | 266 return; |
267 | 267 |
268 // TODO(pdr): This loop is too tightly coupled to SVGTextMetricsCalculator. | 268 // TODO(pdr): This loop is too tightly coupled to SVGTextMetricsCalculator. |
269 // We should refactor SVGTextMetricsCalculator to be a simple bidi run | 269 // We should refactor SVGTextMetricsCalculator to be a simple bidi run |
270 // iterator and move all subrun logic to a single function. | 270 // iterator and move all subrun logic to a single function. |
271 SVGTextMetricsCalculator calculator(textLayoutItem); | 271 SVGTextMetricsCalculator calculator(textLayoutItem); |
272 bool preserveWhiteSpace = textLayoutItem.styleRef().whiteSpace() == PRE; | 272 bool preserveWhiteSpace = textLayoutItem.styleRef().whiteSpace() == PRE; |
273 unsigned surrogatePairCharacters = 0; | |
274 unsigned skippedWhitespace = 0; | |
275 do { | 273 do { |
276 bool currentCharacterIsWhiteSpace = calculator.currentCharacterIsWhiteSp
ace(); | 274 bool currentCharacterIsWhiteSpace = calculator.currentCharacterIsWhiteSp
ace(); |
277 if (currentCharacterIsWhiteSpace && !preserveWhiteSpace && textState.las
tCharacterWasWhiteSpace) { | 275 if (currentCharacterIsWhiteSpace && !preserveWhiteSpace && textState.las
tCharacterWasWhiteSpace) { |
278 if (attributesToUpdate) | 276 if (attributesToUpdate) |
279 attributesToUpdate->addMetrics(SVGTextMetrics(SVGTextMetrics::Sk
ippedSpaceMetrics)); | 277 attributesToUpdate->addMetrics(SVGTextMetrics(SVGTextMetrics::Sk
ippedSpaceMetrics)); |
280 ASSERT(calculator.currentCharacterMetrics().length() == 1); | 278 ASSERT(calculator.currentCharacterMetrics().length() == 1); |
281 skippedWhitespace++; | |
282 continue; | 279 continue; |
283 } | 280 } |
284 | 281 |
285 if (attributesToUpdate) { | 282 if (attributesToUpdate) { |
286 unsigned currentTextValueListPosition = calculator.currentPosition()
- skippedWhitespace - surrogatePairCharacters; | 283 attributesToUpdate->updateCharacterDataMap(textState.valueListPositi
on + 1, calculator.currentPosition() + 1); |
287 attributesToUpdate->updateCharacterDataMap(textState.valueListPositi
on + currentTextValueListPosition + 1, calculator.currentPosition() + 1); | |
288 attributesToUpdate->addMetrics(calculator.currentCharacterMetrics())
; | 284 attributesToUpdate->addMetrics(calculator.currentCharacterMetrics())
; |
289 } | 285 } |
290 | 286 |
291 if (calculator.currentCharacterStartsSurrogatePair()) | 287 // Increase the position in the value/attribute list with one for each |
292 surrogatePairCharacters++; | 288 // "character unit" (that will be displayed.) |
| 289 textState.valueListPosition++; |
293 textState.lastCharacterWasWhiteSpace = currentCharacterIsWhiteSpace; | 290 textState.lastCharacterWasWhiteSpace = currentCharacterIsWhiteSpace; |
294 } while (calculator.advancePosition()); | 291 } while (calculator.advancePosition()); |
295 | |
296 unsigned currentTextValueListPosition = calculator.currentPosition() - skipp
edWhitespace - surrogatePairCharacters; | |
297 textState.valueListPosition += currentTextValueListPosition; | |
298 } | 292 } |
299 | 293 |
300 void walkTree(LayoutSVGText* start, LayoutSVGInlineText* stopAtText, SVGCharacte
rDataMap* allCharactersMap = nullptr) | 294 void walkTree(LayoutSVGText* start, LayoutSVGInlineText* stopAtText, SVGCharacte
rDataMap* allCharactersMap = nullptr) |
301 { | 295 { |
302 TreeWalkTextState textState; | 296 TreeWalkTextState textState; |
303 LayoutObject* child = start->firstChild(); | 297 LayoutObject* child = start->firstChild(); |
304 while (child) { | 298 while (child) { |
305 if (child->isSVGInlineText()) { | 299 if (child->isSVGInlineText()) { |
306 LayoutSVGInlineText* text = toLayoutSVGInlineText(child); | 300 LayoutSVGInlineText* text = toLayoutSVGInlineText(child); |
307 OwnPtr<UpdateAttributes> attributesToUpdate = nullptr; | 301 OwnPtr<UpdateAttributes> attributesToUpdate = nullptr; |
(...skipping 22 matching lines...) Expand all Loading... |
330 walkTree(textRoot, text); | 324 walkTree(textRoot, text); |
331 } | 325 } |
332 | 326 |
333 void SVGTextMetricsBuilder::buildMetricsAndLayoutAttributes(LayoutSVGText* textR
oot, LayoutSVGInlineText* stopAtText, SVGCharacterDataMap& allCharactersMap) | 327 void SVGTextMetricsBuilder::buildMetricsAndLayoutAttributes(LayoutSVGText* textR
oot, LayoutSVGInlineText* stopAtText, SVGCharacterDataMap& allCharactersMap) |
334 { | 328 { |
335 ASSERT(textRoot); | 329 ASSERT(textRoot); |
336 walkTree(textRoot, stopAtText, &allCharactersMap); | 330 walkTree(textRoot, stopAtText, &allCharactersMap); |
337 } | 331 } |
338 | 332 |
339 } // namespace blink | 333 } // namespace blink |
OLD | NEW |