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

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

Issue 1411123014: [Line Layout API] Convert SVGTextLayoutEngine and SVGTextLayoutEngineBaseline to line Layout API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 m_textPathStartOffset = 0; 200 m_textPathStartOffset = 0;
201 m_textPathCurrentOffset = 0; 201 m_textPathCurrentOffset = 0;
202 m_textPathSpacing = 0; 202 m_textPathSpacing = 0;
203 m_textPathScaling = 1; 203 m_textPathScaling = 1;
204 } 204 }
205 205
206 void SVGTextLayoutEngine::layoutInlineTextBox(SVGInlineTextBox* textBox) 206 void SVGTextLayoutEngine::layoutInlineTextBox(SVGInlineTextBox* textBox)
207 { 207 {
208 ASSERT(textBox); 208 ASSERT(textBox);
209 209
210 LayoutSVGInlineText& text = toLayoutSVGInlineText(textBox->layoutObject()); 210 LineLayoutSVGInlineText textLineLayout = LineLayoutSVGInlineText(textBox->li neLayoutItem());
211 ASSERT(text.parent()); 211 ASSERT(textLineLayout.parent());
212 ASSERT(text.parent()->node()); 212 ASSERT(textLineLayout.parent().node());
213 ASSERT(text.parent()->node()->isSVGElement()); 213 ASSERT(textLineLayout.parent().node()->isSVGElement());
214 214
215 const ComputedStyle& style = text.styleRef(); 215 const ComputedStyle& style = textLineLayout.styleRef();
216 216
217 textBox->clearTextFragments(); 217 textBox->clearTextFragments();
218 m_isVerticalText = !style.isHorizontalWritingMode(); 218 m_isVerticalText = !style.isHorizontalWritingMode();
219 layoutTextOnLineOrPath(textBox, text, style); 219 layoutTextOnLineOrPath(textBox, textLineLayout, style);
220 220
221 if (m_inPathLayout) 221 if (m_inPathLayout)
222 return; 222 return;
223 223
224 m_lineLayoutBoxes.append(textBox); 224 m_lineLayoutBoxes.append(textBox);
225 } 225 }
226 226
227 static bool definesTextLengthWithSpacing(const InlineFlowBox* start) 227 static bool definesTextLengthWithSpacing(const InlineFlowBox* start)
228 { 228 {
229 SVGTextContentElement* textContentElement = SVGTextContentElement::elementFr omLayoutObject(&start->layoutObject()); 229 SVGTextContentElement* textContentElement = SVGTextContentElement::elementFr omLayoutObject(&start->layoutObject());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 ASSERT_NOT_REACHED(); 322 ASSERT_NOT_REACHED();
323 return true; 323 return true;
324 } 324 }
325 325
326 void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo gicalMetrics) 326 void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo gicalMetrics)
327 { 327 {
328 ++m_logicalMetricsListOffset; 328 ++m_logicalMetricsListOffset;
329 m_logicalCharacterOffset += logicalMetrics.length(); 329 m_logicalCharacterOffset += logicalMetrics.length();
330 } 330 }
331 331
332 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, cons t LayoutSVGInlineText& text, const ComputedStyle& style) 332 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line LayoutSVGInlineText textLineLayout, const ComputedStyle& style)
333 { 333 {
334 if (m_inPathLayout && !m_textPathCalculator) 334 if (m_inPathLayout && !m_textPathCalculator)
335 return; 335 return;
336 336
337 // Find the start of the current text box in the metrics list. 337 // Find the start of the current text box in the metrics list.
338 m_visualMetricsIterator.advanceToTextStart(&text, textBox->start()); 338 m_visualMetricsIterator.advanceToTextStart(&textLineLayout, textBox->start() );
339 339
340 const Font& font = style.font(); 340 const Font& font = style.font();
341 341
342 SVGTextLayoutEngineSpacing spacingLayout(font, style.effectiveZoom()); 342 SVGTextLayoutEngineSpacing spacingLayout(font, style.effectiveZoom());
343 SVGTextLayoutEngineBaseline baselineLayout(font, style.effectiveZoom()); 343 SVGTextLayoutEngineBaseline baselineLayout(font, style.effectiveZoom());
344 344
345 bool didStartTextFragment = false; 345 bool didStartTextFragment = false;
346 bool applySpacingToNextCharacter = false; 346 bool applySpacingToNextCharacter = false;
347 347
348 float lastAngle = 0; 348 float lastAngle = 0;
349 float baselineShift = baselineLayout.calculateBaselineShift(style); 349 float baselineShift = baselineLayout.calculateBaselineShift(style);
350 baselineShift -= baselineLayout.calculateAlignmentBaselineShift(m_isVertical Text, &text); 350 baselineShift -= baselineLayout.calculateAlignmentBaselineShift(m_isVertical Text, textLineLayout);
351 351
352 // Main layout algorithm. 352 // Main layout algorithm.
353 const unsigned boxEndOffset = textBox->start() + textBox->len(); 353 const unsigned boxEndOffset = textBox->start() + textBox->len();
354 while (!m_visualMetricsIterator.isAtEnd() && m_visualMetricsIterator.charact erOffset() < boxEndOffset) { 354 while (!m_visualMetricsIterator.isAtEnd() && m_visualMetricsIterator.charact erOffset() < boxEndOffset) {
355 const SVGTextMetrics& visualMetrics = m_visualMetricsIterator.metrics(); 355 const SVGTextMetrics& visualMetrics = m_visualMetricsIterator.metrics();
356 if (visualMetrics.isEmpty()) { 356 if (visualMetrics.isEmpty()) {
357 m_visualMetricsIterator.next(); 357 m_visualMetricsIterator.next();
358 continue; 358 continue;
359 } 359 }
360 360
(...skipping 18 matching lines...) Expand all
379 // When we've advanced to the box start offset, determine using the orig inal x/y values, 379 // When we've advanced to the box start offset, determine using the orig inal x/y values,
380 // whether this character starts a new text chunk, before doing any furt her processing. 380 // whether this character starts a new text chunk, before doing any furt her processing.
381 if (m_visualMetricsIterator.characterOffset() == textBox->start()) 381 if (m_visualMetricsIterator.characterOffset() == textBox->start())
382 textBox->setStartsNewTextChunk(logicalAttributes->context()->charact erStartsNewTextChunk(m_logicalCharacterOffset)); 382 textBox->setStartsNewTextChunk(logicalAttributes->context()->charact erStartsNewTextChunk(m_logicalCharacterOffset));
383 383
384 float angle = SVGTextLayoutAttributes::isEmptyValue(data.rotate) ? 0 : d ata.rotate; 384 float angle = SVGTextLayoutAttributes::isEmptyValue(data.rotate) ? 0 : d ata.rotate;
385 385
386 // Calculate glyph orientation angle. 386 // Calculate glyph orientation angle.
387 // Font::width() calculates the resolved FontOrientation for each charac ter, 387 // Font::width() calculates the resolved FontOrientation for each charac ter,
388 // but is not exposed today to avoid the API complexity. 388 // but is not exposed today to avoid the API complexity.
389 UChar32 currentCharacter = text.codepointAt(m_visualMetricsIterator.char acterOffset()); 389 UChar32 currentCharacter = textLineLayout.codepointAt(m_visualMetricsIte rator.characterOffset());
390 FontOrientation fontOrientation = font.fontDescription().orientation(); 390 FontOrientation fontOrientation = font.fontDescription().orientation();
391 fontOrientation = adjustOrientationForCharacterInMixedVertical(fontOrien tation, currentCharacter); 391 fontOrientation = adjustOrientationForCharacterInMixedVertical(fontOrien tation, currentCharacter);
392 392
393 // Calculate glyph advance. 393 // Calculate glyph advance.
394 // Shaping engine takes care of x/y orientation shifts for different fon tOrientation values. 394 // Shaping engine takes care of x/y orientation shifts for different fon tOrientation values.
395 float glyphAdvance = visualMetrics.advance(fontOrientation); 395 float glyphAdvance = visualMetrics.advance(fontOrientation);
396 396
397 // Assign current text position to x/y values, if needed. 397 // Assign current text position to x/y values, if needed.
398 updateCharacterPositionIfNeeded(x, y); 398 updateCharacterPositionIfNeeded(x, y);
399 399
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 536 }
537 537
538 if (!didStartTextFragment) 538 if (!didStartTextFragment)
539 return; 539 return;
540 540
541 // Close last open fragment, if needed. 541 // Close last open fragment, if needed.
542 recordTextFragment(textBox); 542 recordTextFragment(textBox);
543 } 543 }
544 544
545 } 545 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698