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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 m_visualMetricsIterator = SVGInlineTextMetricsIterator(); | 269 m_visualMetricsIterator = SVGInlineTextMetricsIterator(); |
270 | 270 |
271 // After all text fragments are stored in their correpsonding SVGInlineTextB oxes, we can layout individual text chunks. | 271 // After all text fragments are stored in their correpsonding SVGInlineTextB oxes, we can layout individual text chunks. |
272 // Chunk layouting is only performed for line layout boxes, not for path lay out, where it has already been done. | 272 // Chunk layouting is only performed for line layout boxes, not for path lay out, where it has already been done. |
273 SVGTextChunkBuilder chunkLayoutBuilder; | 273 SVGTextChunkBuilder chunkLayoutBuilder; |
274 chunkLayoutBuilder.processTextChunks(m_lineLayoutBoxes); | 274 chunkLayoutBuilder.processTextChunks(m_lineLayoutBoxes); |
275 | 275 |
276 m_lineLayoutBoxes.clear(); | 276 m_lineLayoutBoxes.clear(); |
277 } | 277 } |
278 | 278 |
279 bool SVGTextLayoutEngine::currentLogicalCharacterAttributes(SVGTextLayoutAttribu tes*& logicalAttributes) | 279 const SVGTextLayoutAttributes* SVGTextLayoutEngine::nextLogicalAttributes() |
280 { | 280 { |
f(malita)
2016/04/29 18:06:07
nit: ASSERT(m_layoutAttributesPosition < m_layoutA
fs
2016/04/29 18:56:34
Added.
| |
281 if (m_layoutAttributesPosition == m_layoutAttributes.size()) | |
282 return false; | |
283 | |
284 logicalAttributes = m_layoutAttributes[m_layoutAttributesPosition]; | |
285 ASSERT(logicalAttributes); | |
286 | |
287 if (m_logicalCharacterOffset != logicalAttributes->context()->textLength()) | |
288 return true; | |
289 | |
290 ++m_layoutAttributesPosition; | 281 ++m_layoutAttributesPosition; |
291 if (m_layoutAttributesPosition == m_layoutAttributes.size()) | 282 if (m_layoutAttributesPosition == m_layoutAttributes.size()) |
292 return false; | 283 return nullptr; |
293 | 284 |
294 logicalAttributes = m_layoutAttributes[m_layoutAttributesPosition]; | |
295 m_logicalMetricsListOffset = 0; | 285 m_logicalMetricsListOffset = 0; |
296 m_logicalCharacterOffset = 0; | 286 m_logicalCharacterOffset = 0; |
297 return true; | 287 return m_layoutAttributes[m_layoutAttributesPosition]; |
298 } | 288 } |
299 | 289 |
300 bool SVGTextLayoutEngine::currentLogicalCharacterMetrics(SVGTextLayoutAttributes *& logicalAttributes, SVGTextMetrics& logicalMetrics) | 290 const SVGTextLayoutAttributes* SVGTextLayoutEngine::currentLogicalCharacterMetri cs(SVGTextMetrics& logicalMetrics) |
301 { | 291 { |
292 // If we're consumed all layout attributes, there can be no more metrics. | |
293 if (m_layoutAttributesPosition == m_layoutAttributes.size()) | |
294 return nullptr; | |
295 | |
296 const SVGTextLayoutAttributes* logicalAttributes = m_layoutAttributes[m_layo utAttributesPosition]; | |
297 // If we reached the end of the text node associated with the current set | |
298 // of layout attributes, try to move to the next text node/set of layout | |
299 // attributes. | |
f(malita)
2016/04/29 18:06:07
nit: ASSERT(m_logicalCharacterOffset <= logicalAtt
fs
2016/04/29 18:56:34
Yepp. Added.
| |
300 if (m_logicalCharacterOffset == logicalAttributes->context()->textLength()) { | |
301 logicalAttributes = nextLogicalAttributes(); | |
302 if (!logicalAttributes) | |
303 return nullptr; | |
304 } | |
305 | |
306 // We have set of layout attributes. Find the first non-collapsed text | |
307 // metrics cell. | |
302 const Vector<SVGTextMetrics>* metricsList = &logicalAttributes->context()->m etricsList(); | 308 const Vector<SVGTextMetrics>* metricsList = &logicalAttributes->context()->m etricsList(); |
303 unsigned metricsListSize = metricsList->size(); | 309 unsigned metricsListSize = metricsList->size(); |
304 while (true) { | 310 while (true) { |
311 // If we run out of metrics, move to the next set of layout attributes. | |
305 if (m_logicalMetricsListOffset == metricsListSize) { | 312 if (m_logicalMetricsListOffset == metricsListSize) { |
306 if (!currentLogicalCharacterAttributes(logicalAttributes)) | 313 logicalAttributes = nextLogicalAttributes(); |
307 return false; | 314 if (!logicalAttributes) |
315 return nullptr; | |
308 | 316 |
309 metricsList = &logicalAttributes->context()->metricsList(); | 317 metricsList = &logicalAttributes->context()->metricsList(); |
310 metricsListSize = metricsList->size(); | 318 metricsListSize = metricsList->size(); |
311 continue; | 319 continue; |
312 } | 320 } |
313 | 321 |
314 ASSERT(metricsListSize); | 322 ASSERT(metricsListSize); |
315 ASSERT(m_logicalMetricsListOffset < metricsListSize); | 323 ASSERT(m_logicalMetricsListOffset < metricsListSize); |
316 logicalMetrics = metricsList->at(m_logicalMetricsListOffset); | 324 logicalMetrics = metricsList->at(m_logicalMetricsListOffset); |
317 if (logicalMetrics.isEmpty() || (!logicalMetrics.width() && !logicalMetr ics.height())) { | 325 if (logicalMetrics.isEmpty() || (!logicalMetrics.width() && !logicalMetr ics.height())) { |
318 advanceToNextLogicalCharacter(logicalMetrics); | 326 advanceToNextLogicalCharacter(logicalMetrics); |
319 continue; | 327 continue; |
320 } | 328 } |
321 | 329 |
322 // Stop if we found the next valid logical text metrics object. | 330 // Stop if we found the next valid logical text metrics object. |
323 return true; | 331 return logicalAttributes; |
324 } | 332 } |
325 | 333 |
326 ASSERT_NOT_REACHED(); | 334 ASSERT_NOT_REACHED(); |
327 return true; | 335 return nullptr; |
328 } | 336 } |
329 | 337 |
330 void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo gicalMetrics) | 338 void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo gicalMetrics) |
331 { | 339 { |
332 ++m_logicalMetricsListOffset; | 340 ++m_logicalMetricsListOffset; |
333 m_logicalCharacterOffset += logicalMetrics.length(); | 341 m_logicalCharacterOffset += logicalMetrics.length(); |
334 } | 342 } |
335 | 343 |
336 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line LayoutSVGInlineText textLineLayout, const ComputedStyle& style) | 344 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line LayoutSVGInlineText textLineLayout, const ComputedStyle& style) |
337 { | 345 { |
(...skipping 23 matching lines...) Expand all Loading... | |
361 | 369 |
362 // Main layout algorithm. | 370 // Main layout algorithm. |
363 const unsigned boxEndOffset = textBox->start() + textBox->len(); | 371 const unsigned boxEndOffset = textBox->start() + textBox->len(); |
364 while (!m_visualMetricsIterator.isAtEnd() && m_visualMetricsIterator.charact erOffset() < boxEndOffset) { | 372 while (!m_visualMetricsIterator.isAtEnd() && m_visualMetricsIterator.charact erOffset() < boxEndOffset) { |
365 const SVGTextMetrics& visualMetrics = m_visualMetricsIterator.metrics(); | 373 const SVGTextMetrics& visualMetrics = m_visualMetricsIterator.metrics(); |
366 if (visualMetrics.isEmpty()) { | 374 if (visualMetrics.isEmpty()) { |
367 m_visualMetricsIterator.next(); | 375 m_visualMetricsIterator.next(); |
368 continue; | 376 continue; |
369 } | 377 } |
370 | 378 |
371 SVGTextLayoutAttributes* logicalAttributes = nullptr; | 379 SVGTextMetrics logicalMetrics(SVGTextMetrics::SkippedSpaceMetrics); |
372 if (!currentLogicalCharacterAttributes(logicalAttributes)) | 380 const SVGTextLayoutAttributes* logicalAttributes = currentLogicalCharact erMetrics(logicalMetrics); |
381 if (!logicalAttributes) | |
373 break; | 382 break; |
374 | 383 |
375 ASSERT(logicalAttributes); | 384 const SVGCharacterDataMap& characterDataMap = logicalAttributes->charact erDataMap(); |
376 SVGTextMetrics logicalMetrics(SVGTextMetrics::SkippedSpaceMetrics); | |
377 if (!currentLogicalCharacterMetrics(logicalAttributes, logicalMetrics)) | |
378 break; | |
379 | |
380 SVGCharacterDataMap& characterDataMap = logicalAttributes->characterData Map(); | |
381 SVGCharacterData data; | 385 SVGCharacterData data; |
382 SVGCharacterDataMap::iterator it = characterDataMap.find(m_logicalCharac terOffset + 1); | 386 SVGCharacterDataMap::const_iterator it = characterDataMap.find(m_logical CharacterOffset + 1); |
383 if (it != characterDataMap.end()) | 387 if (it != characterDataMap.end()) |
384 data = it->value; | 388 data = it->value; |
385 | 389 |
386 // TODO(fs): Use the return value to eliminate the additional | 390 // TODO(fs): Use the return value to eliminate the additional |
387 // hash-lookup below when determining if this text box should be tagged | 391 // hash-lookup below when determining if this text box should be tagged |
388 // as starting a new text chunk. | 392 // as starting a new text chunk. |
389 setCurrentTextPosition(data); | 393 setCurrentTextPosition(data); |
390 | 394 |
391 // When we've advanced to the box start offset, determine using the orig inal x/y values, | 395 // When we've advanced to the box start offset, determine using the orig inal x/y values, |
392 // whether this character starts a new text chunk, before doing any furt her processing. | 396 // whether this character starts a new text chunk, before doing any furt her processing. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 } | 508 } |
505 | 509 |
506 if (!didStartTextFragment) | 510 if (!didStartTextFragment) |
507 return; | 511 return; |
508 | 512 |
509 // Close last open fragment, if needed. | 513 // Close last open fragment, if needed. |
510 recordTextFragment(textBox); | 514 recordTextFragment(textBox); |
511 } | 515 } |
512 | 516 |
513 } // namespace blink | 517 } // namespace blink |
OLD | NEW |