| 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 26 matching lines...) Expand all Loading... |
| 37 , m_layoutAttributesPosition(0) | 37 , m_layoutAttributesPosition(0) |
| 38 , m_logicalCharacterOffset(0) | 38 , m_logicalCharacterOffset(0) |
| 39 , m_logicalMetricsListOffset(0) | 39 , m_logicalMetricsListOffset(0) |
| 40 , m_x(0) | 40 , m_x(0) |
| 41 , m_y(0) | 41 , m_y(0) |
| 42 , m_dx(0) | 42 , m_dx(0) |
| 43 , m_dy(0) | 43 , m_dy(0) |
| 44 , m_isVerticalText(false) | 44 , m_isVerticalText(false) |
| 45 , m_inPathLayout(false) | 45 , m_inPathLayout(false) |
| 46 , m_textLengthSpacingInEffect(false) | 46 , m_textLengthSpacingInEffect(false) |
| 47 , m_textPathCalculator(nullptr) | 47 , m_textPath(nullptr) |
| 48 , m_textPathLength(0) | |
| 49 , m_textPathCurrentOffset(0) | 48 , m_textPathCurrentOffset(0) |
| 50 , m_textPathSpacing(0) | 49 , m_textPathSpacing(0) |
| 51 , m_textPathScaling(1) | 50 , m_textPathScaling(1) |
| 52 { | 51 { |
| 53 ASSERT(!m_layoutAttributes.isEmpty()); | 52 ASSERT(!m_layoutAttributes.isEmpty()); |
| 54 } | 53 } |
| 55 | 54 |
| 55 SVGTextLayoutEngine::~SVGTextLayoutEngine() = default; |
| 56 |
| 56 void SVGTextLayoutEngine::updateCharacterPositionIfNeeded(float& x, float& y) | 57 void SVGTextLayoutEngine::updateCharacterPositionIfNeeded(float& x, float& y) |
| 57 { | 58 { |
| 58 if (m_inPathLayout) | 59 if (m_inPathLayout) |
| 59 return; | 60 return; |
| 60 | 61 |
| 61 // Replace characters x/y position, with the current text position plus any | 62 // Replace characters x/y position, with the current text position plus any |
| 62 // relative adjustments, if it doesn't specify an absolute position itself. | 63 // relative adjustments, if it doesn't specify an absolute position itself. |
| 63 if (SVGTextLayoutAttributes::isEmptyValue(x)) | 64 if (SVGTextLayoutAttributes::isEmptyValue(x)) |
| 64 x = m_x + m_dx; | 65 x = m_x + m_dx; |
| 65 | 66 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 void SVGTextLayoutEngine::beginTextPathLayout(SVGInlineFlowBox* flowBox) | 166 void SVGTextLayoutEngine::beginTextPathLayout(SVGInlineFlowBox* flowBox) |
| 166 { | 167 { |
| 167 // Build text chunks for all <textPath> children, using the line layout algo
rithm. | 168 // Build text chunks for all <textPath> children, using the line layout algo
rithm. |
| 168 // This is needeed as text-anchor is just an additional startOffset for text
paths. | 169 // This is needeed as text-anchor is just an additional startOffset for text
paths. |
| 169 SVGTextLayoutEngine lineLayout(m_layoutAttributes); | 170 SVGTextLayoutEngine lineLayout(m_layoutAttributes); |
| 170 lineLayout.m_textLengthSpacingInEffect = m_textLengthSpacingInEffect; | 171 lineLayout.m_textLengthSpacingInEffect = m_textLengthSpacingInEffect; |
| 171 lineLayout.layoutCharactersInTextBoxes(flowBox); | 172 lineLayout.layoutCharactersInTextBoxes(flowBox); |
| 172 | 173 |
| 173 m_inPathLayout = true; | 174 m_inPathLayout = true; |
| 174 LayoutSVGTextPath* textPath = &toLayoutSVGTextPath(flowBox->layoutObject()); | 175 LayoutSVGTextPath* textPath = &toLayoutSVGTextPath(flowBox->layoutObject()); |
| 175 | 176 m_textPath = textPath->layoutPath(); |
| 176 Path path = textPath->layoutPath(); | 177 if (!m_textPath) |
| 177 if (path.isEmpty()) | |
| 178 return; | 178 return; |
| 179 m_textPathCalculator = new Path::PositionCalculator(path); | 179 m_textPathStartOffset = textPath->calculateStartOffset(m_textPath->length())
; |
| 180 m_textPathLength = path.length(); | |
| 181 m_textPathStartOffset = textPath->calculateStartOffset(m_textPathLength); | |
| 182 | 180 |
| 183 SVGTextPathChunkBuilder textPathChunkLayoutBuilder; | 181 SVGTextPathChunkBuilder textPathChunkLayoutBuilder; |
| 184 textPathChunkLayoutBuilder.processTextChunks(lineLayout.m_lineLayoutBoxes); | 182 textPathChunkLayoutBuilder.processTextChunks(lineLayout.m_lineLayoutBoxes); |
| 185 | 183 |
| 186 m_textPathStartOffset += textPathChunkLayoutBuilder.totalTextAnchorShift(); | 184 m_textPathStartOffset += textPathChunkLayoutBuilder.totalTextAnchorShift(); |
| 187 m_textPathCurrentOffset = m_textPathStartOffset; | 185 m_textPathCurrentOffset = m_textPathStartOffset; |
| 188 | 186 |
| 189 // Eventually handle textLength adjustments. | 187 // Eventually handle textLength adjustments. |
| 190 SVGLengthAdjustType lengthAdjust = SVGLengthAdjustUnknown; | 188 SVGLengthAdjustType lengthAdjust = SVGLengthAdjustUnknown; |
| 191 float desiredTextLength = 0; | 189 float desiredTextLength = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 205 float totalLength = textPathChunkLayoutBuilder.totalLength(); | 203 float totalLength = textPathChunkLayoutBuilder.totalLength(); |
| 206 if (lengthAdjust == SVGLengthAdjustSpacing) | 204 if (lengthAdjust == SVGLengthAdjustSpacing) |
| 207 m_textPathSpacing = (desiredTextLength - totalLength) / textPathChunkLay
outBuilder.totalCharacters(); | 205 m_textPathSpacing = (desiredTextLength - totalLength) / textPathChunkLay
outBuilder.totalCharacters(); |
| 208 else | 206 else |
| 209 m_textPathScaling = desiredTextLength / totalLength; | 207 m_textPathScaling = desiredTextLength / totalLength; |
| 210 } | 208 } |
| 211 | 209 |
| 212 void SVGTextLayoutEngine::endTextPathLayout() | 210 void SVGTextLayoutEngine::endTextPathLayout() |
| 213 { | 211 { |
| 214 m_inPathLayout = false; | 212 m_inPathLayout = false; |
| 215 delete m_textPathCalculator; | 213 m_textPath = nullptr; |
| 216 m_textPathCalculator = 0; | |
| 217 m_textPathLength = 0; | |
| 218 m_textPathStartOffset = 0; | 214 m_textPathStartOffset = 0; |
| 219 m_textPathCurrentOffset = 0; | 215 m_textPathCurrentOffset = 0; |
| 220 m_textPathSpacing = 0; | 216 m_textPathSpacing = 0; |
| 221 m_textPathScaling = 1; | 217 m_textPathScaling = 1; |
| 222 } | 218 } |
| 223 | 219 |
| 224 void SVGTextLayoutEngine::layoutInlineTextBox(SVGInlineTextBox* textBox) | 220 void SVGTextLayoutEngine::layoutInlineTextBox(SVGInlineTextBox* textBox) |
| 225 { | 221 { |
| 226 ASSERT(textBox); | 222 ASSERT(textBox); |
| 227 | 223 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 } | 338 } |
| 343 | 339 |
| 344 void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo
gicalMetrics) | 340 void SVGTextLayoutEngine::advanceToNextLogicalCharacter(const SVGTextMetrics& lo
gicalMetrics) |
| 345 { | 341 { |
| 346 ++m_logicalMetricsListOffset; | 342 ++m_logicalMetricsListOffset; |
| 347 m_logicalCharacterOffset += logicalMetrics.length(); | 343 m_logicalCharacterOffset += logicalMetrics.length(); |
| 348 } | 344 } |
| 349 | 345 |
| 350 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line
LayoutSVGInlineText textLineLayout, const ComputedStyle& style) | 346 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line
LayoutSVGInlineText textLineLayout, const ComputedStyle& style) |
| 351 { | 347 { |
| 352 if (m_inPathLayout && !m_textPathCalculator) | 348 if (m_inPathLayout && !m_textPath) |
| 353 return; | 349 return; |
| 354 | 350 |
| 355 // Find the start of the current text box in the metrics list. | 351 // Find the start of the current text box in the metrics list. |
| 356 m_visualMetricsIterator.advanceToTextStart(textLineLayout, textBox->start())
; | 352 m_visualMetricsIterator.advanceToTextStart(textLineLayout, textBox->start())
; |
| 357 | 353 |
| 358 const Font& font = style.font(); | 354 const Font& font = style.font(); |
| 359 | 355 |
| 360 SVGTextLayoutEngineSpacing spacingLayout(font, style.effectiveZoom()); | 356 SVGTextLayoutEngineSpacing spacingLayout(font, style.effectiveZoom()); |
| 361 SVGTextLayoutEngineBaseline baselineLayout(font, style.effectiveZoom()); | 357 SVGTextLayoutEngineBaseline baselineLayout(font, style.effectiveZoom()); |
| 362 | 358 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 410 |
| 415 // Assign current text position to x/y values, if needed. | 411 // Assign current text position to x/y values, if needed. |
| 416 updateCharacterPositionIfNeeded(x, y); | 412 updateCharacterPositionIfNeeded(x, y); |
| 417 | 413 |
| 418 // Apply dx/dy value adjustments to current text position, if needed. | 414 // Apply dx/dy value adjustments to current text position, if needed. |
| 419 updateRelativePositionAdjustmentsIfNeeded(data.dx, data.dy); | 415 updateRelativePositionAdjustmentsIfNeeded(data.dx, data.dy); |
| 420 | 416 |
| 421 // Calculate CSS 'letter-spacing' and 'word-spacing' for next character,
if needed. | 417 // Calculate CSS 'letter-spacing' and 'word-spacing' for next character,
if needed. |
| 422 float spacing = spacingLayout.calculateCSSSpacing(currentCharacter); | 418 float spacing = spacingLayout.calculateCSSSpacing(currentCharacter); |
| 423 | 419 |
| 424 float textPathOffset = 0; | |
| 425 float textPathShiftX = 0; | 420 float textPathShiftX = 0; |
| 426 float textPathShiftY = 0; | 421 float textPathShiftY = 0; |
| 427 if (m_inPathLayout) { | 422 if (m_inPathLayout) { |
| 428 float scaledGlyphAdvance = glyphAdvance * m_textPathScaling; | 423 float scaledGlyphAdvance = glyphAdvance * m_textPathScaling; |
| 429 if (m_isVerticalText) { | 424 if (m_isVerticalText) { |
| 430 // If there's an absolute y position available, it marks the beg
inning of a new position along the path. | 425 // If there's an absolute y position available, it marks the beg
inning of a new position along the path. |
| 431 if (!SVGTextLayoutAttributes::isEmptyValue(y)) | 426 if (!SVGTextLayoutAttributes::isEmptyValue(y)) |
| 432 m_textPathCurrentOffset = y + m_textPathStartOffset; | 427 m_textPathCurrentOffset = y + m_textPathStartOffset; |
| 433 | 428 |
| 434 m_textPathCurrentOffset += m_dy; | 429 m_textPathCurrentOffset += m_dy; |
| 435 m_dy = 0; | 430 m_dy = 0; |
| 436 | 431 |
| 437 // Apply dx/dy correction and setup translations that move to th
e glyph midpoint. | 432 // Apply dx/dy correction and setup translations that move to th
e glyph midpoint. |
| 438 textPathShiftX += m_dx + baselineShift; | 433 textPathShiftX += m_dx + baselineShift; |
| 439 textPathShiftY -= scaledGlyphAdvance / 2; | 434 textPathShiftY -= scaledGlyphAdvance / 2; |
| 440 } else { | 435 } else { |
| 441 // If there's an absolute x position available, it marks the beg
inning of a new position along the path. | 436 // If there's an absolute x position available, it marks the beg
inning of a new position along the path. |
| 442 if (!SVGTextLayoutAttributes::isEmptyValue(x)) | 437 if (!SVGTextLayoutAttributes::isEmptyValue(x)) |
| 443 m_textPathCurrentOffset = x + m_textPathStartOffset; | 438 m_textPathCurrentOffset = x + m_textPathStartOffset; |
| 444 | 439 |
| 445 m_textPathCurrentOffset += m_dx; | 440 m_textPathCurrentOffset += m_dx; |
| 446 m_dx = 0; | 441 m_dx = 0; |
| 447 | 442 |
| 448 // Apply dx/dy correction and setup translations that move to th
e glyph midpoint. | 443 // Apply dx/dy correction and setup translations that move to th
e glyph midpoint. |
| 449 textPathShiftX -= scaledGlyphAdvance / 2; | 444 textPathShiftX -= scaledGlyphAdvance / 2; |
| 450 textPathShiftY += m_dy - baselineShift; | 445 textPathShiftY += m_dy - baselineShift; |
| 451 } | 446 } |
| 452 | 447 |
| 453 // Calculate current offset along path. | 448 // Calculate current offset along path. |
| 454 textPathOffset = m_textPathCurrentOffset + scaledGlyphAdvance / 2; | 449 float textPathOffset = m_textPathCurrentOffset + scaledGlyphAdvance
/ 2; |
| 455 | 450 |
| 456 // Move to next character. | 451 // Move to next character. |
| 457 m_textPathCurrentOffset += scaledGlyphAdvance + m_textPathSpacing +
spacing * m_textPathScaling; | 452 m_textPathCurrentOffset += scaledGlyphAdvance + m_textPathSpacing +
spacing * m_textPathScaling; |
| 458 | 453 |
| 454 FloatPoint point; |
| 455 PathPositionMapper::PositionType positionType = m_textPath->pointAnd
NormalAtLength(textPathOffset, point, angle); |
| 456 |
| 459 // Skip character, if we're before the path. | 457 // Skip character, if we're before the path. |
| 460 if (textPathOffset < 0) { | 458 if (positionType == PathPositionMapper::BeforePath) { |
| 461 advanceToNextLogicalCharacter(logicalMetrics); | 459 advanceToNextLogicalCharacter(logicalMetrics); |
| 462 m_visualMetricsIterator.next(); | 460 m_visualMetricsIterator.next(); |
| 463 continue; | 461 continue; |
| 464 } | 462 } |
| 465 | 463 |
| 466 // Stop processing, if the next character lies behind the path. | 464 // Stop processing if the next character lies behind the path. |
| 467 if (textPathOffset > m_textPathLength) | 465 if (positionType == PathPositionMapper::AfterPath) |
| 468 break; | 466 break; |
| 469 | 467 |
| 470 FloatPoint point; | |
| 471 m_textPathCalculator->pointAndNormalAtLength(textPathOffset, point,
angle); | |
| 472 x = point.x(); | 468 x = point.x(); |
| 473 y = point.y(); | 469 y = point.y(); |
| 474 | 470 |
| 475 // For vertical text on path, the actual angle has to be rotated 90
degrees anti-clockwise, not the orientation angle! | 471 // For vertical text on path, the actual angle has to be rotated 90
degrees anti-clockwise, not the orientation angle! |
| 476 if (m_isVerticalText) | 472 if (m_isVerticalText) |
| 477 angle -= 90; | 473 angle -= 90; |
| 478 } else { | 474 } else { |
| 479 // Apply all previously calculated shift values. | 475 // Apply all previously calculated shift values. |
| 480 if (m_isVerticalText) | 476 if (m_isVerticalText) |
| 481 x += baselineShift; | 477 x += baselineShift; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 } | 546 } |
| 551 | 547 |
| 552 if (!didStartTextFragment) | 548 if (!didStartTextFragment) |
| 553 return; | 549 return; |
| 554 | 550 |
| 555 // Close last open fragment, if needed. | 551 // Close last open fragment, if needed. |
| 556 recordTextFragment(textBox); | 552 recordTextFragment(textBox); |
| 557 } | 553 } |
| 558 | 554 |
| 559 } // namespace blink | 555 } // namespace blink |
| OLD | NEW |