1/* 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20#include "config.h" 21 22#if ENABLE(SVG) 23#include "SVGTextLayoutEngine.h" 24 25#include "RenderSVGInlineText.h" 26#include "RenderSVGTextPath.h" 27#include "SVGElement.h" 28#include "SVGInlineTextBox.h" 29#include "SVGLengthContext.h" 30#include "SVGTextLayoutEngineBaseline.h" 31#include "SVGTextLayoutEngineSpacing.h" 32 33// Set to a value > 0 to dump the text fragments 34#define DUMP_TEXT_FRAGMENTS 0 35 36namespace WebCore { 37 38SVGTextLayoutEngine::SVGTextLayoutEngine(Vector<SVGTextLayoutAttributes*>& layoutAttributes) 39 : m_layoutAttributes(layoutAttributes) 40 , m_layoutAttributesPosition(0) 41 , m_logicalCharacterOffset(0) 42 , m_logicalMetricsListOffset(0) 43 , m_visualCharacterOffset(0) 44 , m_visualMetricsListOffset(0) 45 , m_x(0) 46 , m_y(0) 47 , m_dx(0) 48 , m_dy(0) 49 , m_isVerticalText(false) 50 , m_inPathLayout(false) 51 , m_textPathLength(0) 52 , m_textPathCurrentOffset(0) 53 , m_textPathSpacing(0) 54 , m_textPathScaling(1) 55{ 56 ASSERT(!m_layoutAttributes.isEmpty()); 57} 58 59void SVGTextLayoutEngine::updateCharacerPositionIfNeeded(float& x, float& y) 60{ 61 if (m_inPathLayout) 62 return; 63 64 // Replace characters x/y position, with the current text position plus any 65 // relative adjustments, if it doesn't specify an absolute position itself. 66 if (x == SVGTextLayoutAttributes::emptyValue()) 67 x = m_x + m_dx; 68 69 if (y == SVGTextLayoutAttributes::emptyValue()) 70 y = m_y + m_dy; 71 72 m_dx = 0; 73 m_dy = 0; 74} 75 76void SVGTextLayoutEngine::updateCurrentTextPosition(float x, float y, float glyphAdvance) 77{ 78 // Update current text position after processing the character. 79 if (m_isVerticalText) { 80 m_x = x; 81 m_y = y + glyphAdvance; 82 } else { 83 m_x = x + glyphAdvance; 84 m_y = y; 85 } 86} 87 88void SVGTextLayoutEngine::updateRelativePositionAdjustmentsIfNeeded(float dx, float dy) 89{ 90 // Update relative positioning information. 91 if (dx == SVGTextLayoutAttributes::emptyValue() && dy == SVGTextLayoutAttributes::emptyValue()) 92 return; 93 94 if (dx == SVGTextLayoutAttributes::emptyValue()) 95 dx = 0; 96 if (dy == SVGTextLayoutAttributes::emptyValue()) 97 dy = 0; 98 99 if (m_inPathLayout) { 100 if (m_isVerticalText) { 101 m_dx += dx; 102 m_dy = dy; 103 } else { 104 m_dx = dx; 105 m_dy += dy; 106 } 107 108 return; 109 } 110 111 m_dx = dx; 112 m_dy = dy; 113} 114 115void SVGTextLayoutEngine::recordTextFragment(SVGInlineTextBox* textBox, Vector<SVGTextMetrics>& textMetricsValues) 116{ 117 ASSERT(!m_currentTextFragment.length); 118 ASSERT(m_visualMetricsListOffset > 0); 119 120 // Figure out length of fragment. 121 m_currentTextFragment.length = m_visualCharacterOffset - m_currentTextFragment.characterOffset; 122 123 // Figure out fragment metrics. 124 SVGTextMetrics& lastCharacterMetrics = textMetricsValues.at(m_visualMetricsListOffset - 1); 125 m_currentTextFragment.width = lastCharacterMetrics.width(); 126 m_currentTextFragment.height = lastCharacterMetrics.height(); 127 128 if (m_currentTextFragment.length > 1) { 129 // SVGTextLayoutAttributesBuilder assures that the length of the range is equal to the sum of the individual lengths of the glyphs. 130 float length = 0; 131 if (m_isVerticalText) { 132 for (unsigned i = m_currentTextFragment.metricsListOffset; i < m_visualMetricsListOffset; ++i) 133 length += textMetricsValues.at(i).height(); 134 m_currentTextFragment.height = length; 135 } else { 136 for (unsigned i = m_currentTextFragment.metricsListOffset; i < m_visualMetricsListOffset; ++i) 137 length += textMetricsValues.at(i).width(); 138 m_currentTextFragment.width = length; 139 } 140 } 141 142 textBox->textFragments().append(m_currentTextFragment); 143 m_currentTextFragment = SVGTextFragment(); 144} 145 146bool SVGTextLayoutEngine::parentDefinesTextLength(RenderObject* parent) const 147{ 148 RenderObject* currentParent = parent; 149 while (currentParent) { 150 if (SVGTextContentElement* textContentElement = SVGTextContentElement::elementFromRenderer(currentParent)) { 151 SVGLengthContext lengthContext(textContentElement); 152 if (textContentElement->lengthAdjust() == SVGLengthAdjustSpacing && textContentElement->specifiedTextLength().value(lengthContext) > 0) 153 return true; 154 } 155 156 if (currentParent->isSVGText()) 157 return false; 158 159 currentParent = currentParent->parent(); 160 } 161 162 ASSERT_NOT_REACHED(); 163 return false; 164} 165 166void SVGTextLayoutEngine::beginTextPathLayout(RenderObject* object, SVGTextLayoutEngine& lineLayout) 167{ 168 ASSERT(object); 169 170 m_inPathLayout = true; 171 RenderSVGTextPath* textPath = toRenderSVGTextPath(object); 172 173 m_textPath = textPath->layoutPath(); 174 if (m_textPath.isEmpty()) 175 return; 176 m_textPathStartOffset = textPath->startOffset(); 177 m_textPathLength = m_textPath.length(); 178 if (m_textPathStartOffset > 0 && m_textPathStartOffset <= 1) 179 m_textPathStartOffset *= m_textPathLength; 180 181 float totalLength = 0; 182 unsigned totalCharacters = 0; 183 184 lineLayout.m_chunkLayoutBuilder.buildTextChunks(lineLayout.m_lineLayoutBoxes); 185 const Vector<SVGTextChunk>& textChunks = lineLayout.m_chunkLayoutBuilder.textChunks(); 186 187 unsigned size = textChunks.size(); 188 for (unsigned i = 0; i < size; ++i) { 189 const SVGTextChunk& chunk = textChunks.at(i); 190 191 float length = 0; 192 unsigned characters = 0; 193 chunk.calculateLength(length, characters); 194 195 // Handle text-anchor as additional start offset for text paths. 196 m_textPathStartOffset += chunk.calculateTextAnchorShift(length); 197 198 totalLength += length; 199 totalCharacters += characters; 200 } 201 202 m_textPathCurrentOffset = m_textPathStartOffset; 203 204 // Eventually handle textLength adjustments. 205 SVGLengthAdjustType lengthAdjust = SVGLengthAdjustUnknown; 206 float desiredTextLength = 0; 207 208 if (SVGTextContentElement* textContentElement = SVGTextContentElement::elementFromRenderer(textPath)) { 209 SVGLengthContext lengthContext(textContentElement); 210 lengthAdjust = textContentElement->lengthAdjust(); 211 desiredTextLength = textContentElement->specifiedTextLength().value(lengthContext); 212 } 213 214 if (!desiredTextLength) 215 return; 216 217 if (lengthAdjust == SVGLengthAdjustSpacing) 218 m_textPathSpacing = (desiredTextLength - totalLength) / totalCharacters; 219 else 220 m_textPathScaling = desiredTextLength / totalLength; 221} 222 223void SVGTextLayoutEngine::endTextPathLayout() 224{ 225 m_inPathLayout = false; 226 m_textPath = Path(); 227 m_textPathLength = 0; 228 m_textPathStartOffset = 0; 229 m_textPathCurrentOffset = 0; 230 m_textPathSpacing = 0; 231 m_textPathScaling = 1; 232} 233 234void SVGTextLayoutEngine::layoutInlineTextBox(SVGInlineTextBox* textBox) 235{ 236 ASSERT(textBox); 237 238 RenderSVGInlineText* text = toRenderSVGInlineText(textBox->textRenderer()); 239 ASSERT(text); 240 ASSERT(text->parent()); 241 ASSERT(text->parent()->node()); 242 ASSERT(text->parent()->node()->isSVGElement()); 243 244 const RenderStyle* style = text->style(); 245 ASSERT(style); 246 247 textBox->clearTextFragments(); 248 m_isVerticalText = style->svgStyle()->isVerticalWritingMode(); 249 layoutTextOnLineOrPath(textBox, text, style); 250 251 if (m_inPathLayout) { 252 m_pathLayoutBoxes.append(textBox); 253 return; 254 } 255 256 m_lineLayoutBoxes.append(textBox); 257} 258 259#if DUMP_TEXT_FRAGMENTS > 0 260static inline void dumpTextBoxes(Vector<SVGInlineTextBox*>& boxes) 261{ 262 unsigned boxCount = boxes.size(); 263 fprintf(stderr, "Dumping all text fragments in text sub tree, %i boxes\n", boxCount); 264 265 for (unsigned boxPosition = 0; boxPosition < boxCount; ++boxPosition) { 266 SVGInlineTextBox* textBox = boxes.at(boxPosition); 267 Vector<SVGTextFragment>& fragments = textBox->textFragments(); 268 fprintf(stderr, "-> Box %i: Dumping text fragments for SVGInlineTextBox, textBox=%p, textRenderer=%p\n", boxPosition, textBox, textBox->textRenderer()); 269 fprintf(stderr, " textBox properties, start=%i, len=%i, box direction=%i\n", textBox->start(), textBox->len(), textBox->direction()); 270 fprintf(stderr, " textRenderer properties, textLength=%i\n", textBox->textRenderer()->textLength()); 271 272 const UChar* characters = textBox->textRenderer()->characters(); 273 274 unsigned fragmentCount = fragments.size(); 275 for (unsigned i = 0; i < fragmentCount; ++i) { 276 SVGTextFragment& fragment = fragments.at(i); 277 String fragmentString(characters + fragment.characterOffset, fragment.length); 278 fprintf(stderr, " -> Fragment %i, x=%lf, y=%lf, width=%lf, height=%lf, characterOffset=%i, length=%i, characters='%s'\n" 279 , i, fragment.x, fragment.y, fragment.width, fragment.height, fragment.characterOffset, fragment.length, fragmentString.utf8().data()); 280 } 281 } 282} 283#endif 284 285void SVGTextLayoutEngine::finalizeTransformMatrices(Vector<SVGInlineTextBox*>& boxes) 286{ 287 unsigned boxCount = boxes.size(); 288 if (!boxCount) 289 return; 290 291 AffineTransform textBoxTransformation; 292 for (unsigned boxPosition = 0; boxPosition < boxCount; ++boxPosition) { 293 SVGInlineTextBox* textBox = boxes.at(boxPosition); 294 Vector<SVGTextFragment>& fragments = textBox->textFragments(); 295 296 unsigned fragmentCount = fragments.size(); 297 for (unsigned i = 0; i < fragmentCount; ++i) { 298 m_chunkLayoutBuilder.transformationForTextBox(textBox, textBoxTransformation); 299 if (textBoxTransformation.isIdentity()) 300 continue; 301 ASSERT(fragments[i].lengthAdjustTransform.isIdentity()); 302 fragments[i].lengthAdjustTransform = textBoxTransformation; 303 } 304 } 305 306 boxes.clear(); 307} 308 309void SVGTextLayoutEngine::finishLayout() 310{ 311 // After all text fragments are stored in their correpsonding SVGInlineTextBoxes, we can layout individual text chunks. 312 // Chunk layouting is only performed for line layout boxes, not for path layout, where it has already been done. 313 m_chunkLayoutBuilder.layoutTextChunks(m_lineLayoutBoxes); 314 315 // Finalize transform matrices, after the chunk layout corrections have been applied, and all fragment x/y positions are finalized. 316 if (!m_lineLayoutBoxes.isEmpty()) { 317#if DUMP_TEXT_FRAGMENTS > 0 318 fprintf(stderr, "Line layout: "); 319 dumpTextBoxes(m_lineLayoutBoxes); 320#endif 321 322 finalizeTransformMatrices(m_lineLayoutBoxes); 323 } 324 325 if (!m_pathLayoutBoxes.isEmpty()) { 326#if DUMP_TEXT_FRAGMENTS > 0 327 fprintf(stderr, "Path layout: "); 328 dumpTextBoxes(m_pathLayoutBoxes); 329#endif 330 331 finalizeTransformMatrices(m_pathLayoutBoxes); 332 } 333} 334 335bool SVGTextLayoutEngine::currentLogicalCharacterAttributes(SVGTextLayoutAttributes*& logicalAttributes) 336{ 337 if (m_layoutAttributesPosition == m_layoutAttributes.size()) 338 return false; 339 340 logicalAttributes = m_layoutAttributes[m_layoutAttributesPosition]; 341 ASSERT(logicalAttributes); 342 343 if (m_logicalCharacterOffset != logicalAttributes->context()->textLength()) 344 return true; 345 346 ++m_layoutAttributesPosition; 347 if (m_layoutAttributesPosition == m_layoutAttributes.size()) 348 return false; 349 350 logicalAttributes = m_layoutAttributes[m_layoutAttributesPosition]; 351 m_logicalMetricsListOffset = 0; 352 m_logicalCharacterOffset = 0; 353 return true; 354} 355 356bool SVGTextLayoutEngine::currentLogicalCharacterMetrics(SVGTextLayoutAttributes*& logicalAttributes, SVGTextMetrics& logicalMetrics) 357{ 358 Vector<SVGTextMetrics>* textMetricsValues = &logicalAttributes->textMetricsValues(); 359 unsigned textMetricsSize = textMetricsValues->size(); 360 while (true) { 361 if (m_logicalMetricsListOffset == textMetricsSize) { 362 if (!currentLogicalCharacterAttributes(logicalAttributes)) 363 return false; 364 365 textMetricsValues = &logicalAttributes->textMetricsValues(); 366 textMetricsSize = textMetricsValues->size(); 367 continue; 368 } 369 370 ASSERT(textMetricsSize); 371 ASSERT(m_logicalMetricsListOffset < textMetricsSize); 372 logicalMetrics = textMetricsValues->at(m_logicalMetricsListOffset); 373 if (logicalMetrics.isEmpty() || (!logicalMetrics.width() && !logicalMetrics.height())) { 374 advanceToNextLogicalCharacter(logicalMetrics); 375 continue; 376 } 377 378 // Stop if we found the next valid logical text metrics object. 379 return true; 380 } 381 382 ASSERT_NOT_REACHED(); 383 return true; 384} 385 386bool SVGTextLayoutEngine::currentVisualCharacterMetrics(SVGInlineTextBox* textBox, Vector<SVGTextMetrics>& visualMetricsValues, SVGTextMetrics& visualMetrics) 387{ 388 ASSERT(!visualMetricsValues.isEmpty()); 389 unsigned textMetricsSize = visualMetricsValues.size(); 390 unsigned boxStart = textBox->start(); 391 unsigned boxLength = textBox->len(); 392 393 if (m_visualMetricsListOffset == textMetricsSize) 394 return false; 395 396 while (m_visualMetricsListOffset < textMetricsSize) { 397 // Advance to text box start location. 398 if (m_visualCharacterOffset < boxStart) { 399 advanceToNextVisualCharacter(visualMetricsValues[m_visualMetricsListOffset]); 400 continue; 401 } 402 403 // Stop if we've finished processing this text box. 404 if (m_visualCharacterOffset >= boxStart + boxLength) 405 return false; 406 407 visualMetrics = visualMetricsValues[m_visualMetricsListOffset]; 408 return true; 409 } 410 411 return false; 412} 413 414void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& logicalMetrics) 415{ 416 ++m_logicalMetricsListOffset; 417 m_logicalCharacterOffset += logicalMetrics.length(); 418} 419 420void SVGTextLayoutEngine::advanceToNextVisualCharacter(const SVGTextMetrics& visualMetrics) 421{ 422 ++m_visualMetricsListOffset; 423 m_visualCharacterOffset += visualMetrics.length(); 424} 425 426void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, RenderSVGInlineText* text, const RenderStyle* style) 427{ 428 if (m_inPathLayout && m_textPath.isEmpty()) 429 return; 430 431 SVGElement* lengthContext = toSVGElement(text->parent()->node()); 432 433 RenderObject* textParent = text->parent(); 434 bool definesTextLength = textParent ? parentDefinesTextLength(textParent) : false; 435 436 const SVGRenderStyle* svgStyle = style->svgStyle(); 437 ASSERT(svgStyle); 438 439 m_visualMetricsListOffset = 0; 440 m_visualCharacterOffset = 0; 441 442 Vector<SVGTextMetrics>& visualMetricsValues = text->layoutAttributes()->textMetricsValues(); 443 ASSERT(!visualMetricsValues.isEmpty()); 444 445 const UChar* characters = text->characters(); 446 const Font& font = style->font(); 447 448 SVGTextLayoutEngineSpacing spacingLayout(font); 449 SVGTextLayoutEngineBaseline baselineLayout(font); 450 451 bool didStartTextFragment = false; 452 bool applySpacingToNextCharacter = false; 453 454 float lastAngle = 0; 455 float baselineShift = baselineLayout.calculateBaselineShift(svgStyle, lengthContext); 456 baselineShift -= baselineLayout.calculateAlignmentBaselineShift(m_isVerticalText, text); 457 458 // Main layout algorithm. 459 while (true) { 460 // Find the start of the current text box in this list, respecting ligatures. 461 SVGTextMetrics visualMetrics(SVGTextMetrics::SkippedSpaceMetrics); 462 if (!currentVisualCharacterMetrics(textBox, visualMetricsValues, visualMetrics)) 463 break; 464 465 if (visualMetrics.isEmpty()) { 466 advanceToNextVisualCharacter(visualMetrics); 467 continue; 468 } 469 470 SVGTextLayoutAttributes* logicalAttributes = 0; 471 if (!currentLogicalCharacterAttributes(logicalAttributes)) 472 break; 473 474 ASSERT(logicalAttributes); 475 SVGTextMetrics logicalMetrics(SVGTextMetrics::SkippedSpaceMetrics); 476 if (!currentLogicalCharacterMetrics(logicalAttributes, logicalMetrics)) 477 break; 478 479 SVGCharacterDataMap& characterDataMap = logicalAttributes->characterDataMap(); 480 SVGCharacterData data; 481 SVGCharacterDataMap::iterator it = characterDataMap.find(m_logicalCharacterOffset + 1); 482 if (it != characterDataMap.end()) 483 data = it->value; 484 485 float x = data.x; 486 float y = data.y; 487 488 // When we've advanced to the box start offset, determine using the original x/y values, 489 // whether this character starts a new text chunk, before doing any further processing. 490 if (m_visualCharacterOffset == textBox->start()) 491 textBox->setStartsNewTextChunk(logicalAttributes->context()->characterStartsNewTextChunk(m_logicalCharacterOffset)); 492 493 float angle = data.rotate == SVGTextLayoutAttributes::emptyValue() ? 0 : data.rotate; 494 495 // Calculate glyph orientation angle. 496 const UChar* currentCharacter = characters + m_visualCharacterOffset; 497 float orientationAngle = baselineLayout.calculateGlyphOrientationAngle(m_isVerticalText, svgStyle, *currentCharacter); 498 499 // Calculate glyph advance & x/y orientation shifts. 500 float xOrientationShift = 0; 501 float yOrientationShift = 0; 502 float glyphAdvance = baselineLayout.calculateGlyphAdvanceAndOrientation(m_isVerticalText, visualMetrics, orientationAngle, xOrientationShift, yOrientationShift); 503 504 // Assign current text position to x/y values, if needed. 505 updateCharacerPositionIfNeeded(x, y); 506 507 // Apply dx/dy value adjustments to current text position, if needed. 508 updateRelativePositionAdjustmentsIfNeeded(data.dx, data.dy); 509 510 // Calculate SVG Fonts kerning, if needed. 511 float kerning = spacingLayout.calculateSVGKerning(m_isVerticalText, visualMetrics.glyph()); 512 513 // Calculate CSS 'kerning', 'letter-spacing' and 'word-spacing' for next character, if needed. 514 float spacing = spacingLayout.calculateCSSKerningAndSpacing(svgStyle, lengthContext, currentCharacter); 515 516 float textPathOffset = 0; 517 if (m_inPathLayout) { 518 float scaledGlyphAdvance = glyphAdvance * m_textPathScaling; 519 if (m_isVerticalText) { 520 // If there's an absolute y position available, it marks the beginning of a new position along the path. 521 if (y != SVGTextLayoutAttributes::emptyValue()) 522 m_textPathCurrentOffset = y + m_textPathStartOffset; 523 524 m_textPathCurrentOffset += m_dy - kerning; 525 m_dy = 0; 526 527 // Apply dx/dy correction and setup translations that move to the glyph midpoint. 528 xOrientationShift += m_dx + baselineShift; 529 yOrientationShift -= scaledGlyphAdvance / 2; 530 } else { 531 // If there's an absolute x position available, it marks the beginning of a new position along the path. 532 if (x != SVGTextLayoutAttributes::emptyValue()) 533 m_textPathCurrentOffset = x + m_textPathStartOffset; 534 535 m_textPathCurrentOffset += m_dx - kerning; 536 m_dx = 0; 537 538 // Apply dx/dy correction and setup translations that move to the glyph midpoint. 539 xOrientationShift -= scaledGlyphAdvance / 2; 540 yOrientationShift += m_dy - baselineShift; 541 } 542 543 // Calculate current offset along path. 544 textPathOffset = m_textPathCurrentOffset + scaledGlyphAdvance / 2; 545 546 // Move to next character. 547 m_textPathCurrentOffset += scaledGlyphAdvance + m_textPathSpacing + spacing * m_textPathScaling; 548 549 // Skip character, if we're before the path. 550 if (textPathOffset < 0) { 551 advanceToNextLogicalCharacter(logicalMetrics); 552 advanceToNextVisualCharacter(visualMetrics); 553 continue; 554 } 555 556 // Stop processing, if the next character lies behind the path. 557 if (textPathOffset > m_textPathLength) 558 break; 559 560 bool ok = false; 561 FloatPoint point = m_textPath.pointAtLength(textPathOffset, ok); 562 ASSERT(ok); 563 564 x = point.x(); 565 y = point.y(); 566 angle = m_textPath.normalAngleAtLength(textPathOffset, ok); 567 ASSERT(ok); 568 569 // For vertical text on path, the actual angle has to be rotated 90 degrees anti-clockwise, not the orientation angle! 570 if (m_isVerticalText) 571 angle -= 90; 572 } else { 573 // Apply all previously calculated shift values. 574 if (m_isVerticalText) { 575 x += baselineShift; 576 y -= kerning; 577 } else { 578 x -= kerning; 579 y -= baselineShift; 580 } 581 582 x += m_dx; 583 y += m_dy; 584 } 585 586 // Determine whether we have to start a new fragment. 587 bool shouldStartNewFragment = m_dx || m_dy || m_isVerticalText || m_inPathLayout || angle || angle != lastAngle 588 || orientationAngle || kerning || applySpacingToNextCharacter || definesTextLength; 589 590 // If we already started a fragment, close it now. 591 if (didStartTextFragment && shouldStartNewFragment) { 592 applySpacingToNextCharacter = false; 593 recordTextFragment(textBox, visualMetricsValues); 594 } 595 596 // Eventually start a new fragment, if not yet done. 597 if (!didStartTextFragment || shouldStartNewFragment) { 598 ASSERT(!m_currentTextFragment.characterOffset); 599 ASSERT(!m_currentTextFragment.length); 600 601 didStartTextFragment = true; 602 m_currentTextFragment.characterOffset = m_visualCharacterOffset; 603 m_currentTextFragment.metricsListOffset = m_visualMetricsListOffset; 604 m_currentTextFragment.x = x; 605 m_currentTextFragment.y = y; 606 607 // Build fragment transformation. 608 if (angle) 609 m_currentTextFragment.transform.rotate(angle); 610 611 if (xOrientationShift || yOrientationShift) 612 m_currentTextFragment.transform.translate(xOrientationShift, yOrientationShift); 613 614 if (orientationAngle) 615 m_currentTextFragment.transform.rotate(orientationAngle); 616 617 m_currentTextFragment.isTextOnPath = m_inPathLayout && m_textPathScaling != 1; 618 if (m_currentTextFragment.isTextOnPath) { 619 if (m_isVerticalText) 620 m_currentTextFragment.lengthAdjustTransform.scaleNonUniform(1, m_textPathScaling); 621 else 622 m_currentTextFragment.lengthAdjustTransform.scaleNonUniform(m_textPathScaling, 1); 623 } 624 } 625 626 // Update current text position, after processing of the current character finished. 627 if (m_inPathLayout) 628 updateCurrentTextPosition(x, y, glyphAdvance); 629 else { 630 // Apply CSS 'kerning', 'letter-spacing' and 'word-spacing' to next character, if needed. 631 if (spacing) 632 applySpacingToNextCharacter = true; 633 634 float xNew = x - m_dx; 635 float yNew = y - m_dy; 636 637 if (m_isVerticalText) 638 xNew -= baselineShift; 639 else 640 yNew += baselineShift; 641 642 updateCurrentTextPosition(xNew, yNew, glyphAdvance + spacing); 643 } 644 645 advanceToNextLogicalCharacter(logicalMetrics); 646 advanceToNextVisualCharacter(visualMetrics); 647 lastAngle = angle; 648 } 649 650 if (!didStartTextFragment) 651 return; 652 653 // Close last open fragment, if needed. 654 recordTextFragment(textBox, visualMetricsValues); 655} 656 657} 658 659#endif // ENABLE(SVG) 660