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

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/SVGTextLayoutEngine.cpp

Issue 1941303003: Simplify logical iteration in SVGTextLayoutEngine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if (m_currentLogicalTextNodeIndex == m_descendantTextNodes.size()) 283 if (m_currentLogicalTextNodeIndex == m_descendantTextNodes.size())
284 return nullptr; 284 return nullptr;
285 285
286 m_logicalMetricsListOffset = 0; 286 m_logicalMetricsListOffset = 0;
287 m_logicalCharacterOffset = 0; 287 m_logicalCharacterOffset = 0;
288 return m_descendantTextNodes[m_currentLogicalTextNodeIndex]; 288 return m_descendantTextNodes[m_currentLogicalTextNodeIndex];
289 } 289 }
290 290
291 const LayoutSVGInlineText* SVGTextLayoutEngine::currentLogicalCharacterMetrics(S VGTextMetrics& logicalMetrics) 291 const LayoutSVGInlineText* SVGTextLayoutEngine::currentLogicalCharacterMetrics(S VGTextMetrics& logicalMetrics)
292 { 292 {
293 // If we're consumed all text nodes, there can be no more metrics. 293 // If we've consumed all text nodes, there can be no more metrics.
294 if (m_currentLogicalTextNodeIndex == m_descendantTextNodes.size()) 294 if (m_currentLogicalTextNodeIndex == m_descendantTextNodes.size())
295 return nullptr; 295 return nullptr;
296 296
297 const LayoutSVGInlineText* logicalTextNode = m_descendantTextNodes[m_current LogicalTextNodeIndex]; 297 const LayoutSVGInlineText* logicalTextNode = m_descendantTextNodes[m_current LogicalTextNodeIndex];
298 // If we reached the end of the text node associated with the current set
299 // of layout attributes, try to move to the next text node/set of layout
300 // attributes.
301 ASSERT(m_logicalCharacterOffset <= logicalTextNode->textLength());
302 if (m_logicalCharacterOffset == logicalTextNode->textLength()) {
303 logicalTextNode = nextLogicalTextNode();
304 if (!logicalTextNode)
305 return nullptr;
306 }
307
308 // We have set of layout attributes. Find the first non-collapsed text
309 // metrics cell.
310 const Vector<SVGTextMetrics>* metricsList = &logicalTextNode->metricsList(); 298 const Vector<SVGTextMetrics>* metricsList = &logicalTextNode->metricsList();
311 unsigned metricsListSize = metricsList->size(); 299 unsigned metricsListSize = metricsList->size();
300 ASSERT(m_logicalMetricsListOffset <= metricsListSize);
301
302 // Find the next non-collapsed text metrics cell.
312 while (true) { 303 while (true) {
313 // If we run out of metrics, move to the next set of layout attributes. 304 // If we run out of metrics, move to the next set of non-empty layout
305 // attributes.
314 if (m_logicalMetricsListOffset == metricsListSize) { 306 if (m_logicalMetricsListOffset == metricsListSize) {
315 logicalTextNode = nextLogicalTextNode(); 307 logicalTextNode = nextLogicalTextNode();
316 if (!logicalTextNode) 308 if (!logicalTextNode)
317 return nullptr; 309 return nullptr;
318
319 metricsList = &logicalTextNode->metricsList(); 310 metricsList = &logicalTextNode->metricsList();
320 metricsListSize = metricsList->size(); 311 metricsListSize = metricsList->size();
312 // Return to the while so that we check if the new metrics list is
313 // non-empty before using it.
321 continue; 314 continue;
322 } 315 }
323 316
324 ASSERT(metricsListSize); 317 ASSERT(metricsListSize);
325 ASSERT(m_logicalMetricsListOffset < metricsListSize);
326 logicalMetrics = metricsList->at(m_logicalMetricsListOffset); 318 logicalMetrics = metricsList->at(m_logicalMetricsListOffset);
327 if (logicalMetrics.isEmpty() || (!logicalMetrics.width() && !logicalMetr ics.height())) { 319 // Stop if we found the next valid logical text metrics object.
328 advanceToNextLogicalCharacter(logicalMetrics); 320 if (!logicalMetrics.isEmpty())
329 continue; 321 break;
330 }
331 322
332 // Stop if we found the next valid logical text metrics object. 323 advanceToNextLogicalCharacter(logicalMetrics);
333 return logicalTextNode;
334 } 324 }
335 325
336 ASSERT_NOT_REACHED(); 326 return logicalTextNode;
337 return nullptr;
338 } 327 }
339 328
340 void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo gicalMetrics) 329 void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo gicalMetrics)
341 { 330 {
342 ++m_logicalMetricsListOffset; 331 ++m_logicalMetricsListOffset;
343 m_logicalCharacterOffset += logicalMetrics.length(); 332 m_logicalCharacterOffset += logicalMetrics.length();
344 } 333 }
345 334
346 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line LayoutSVGInlineText textLineLayout, const ComputedStyle& style) 335 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line LayoutSVGInlineText textLineLayout, const ComputedStyle& style)
347 { 336 {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 495 }
507 496
508 if (!didStartTextFragment) 497 if (!didStartTextFragment)
509 return; 498 return;
510 499
511 // Close last open fragment, if needed. 500 // Close last open fragment, if needed.
512 recordTextFragment(textBox); 501 recordTextFragment(textBox);
513 } 502 }
514 503
515 } // namespace blink 504 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698