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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 ASSERT(!m_layoutAttributes.isEmpty()); | 56 ASSERT(!m_layoutAttributes.isEmpty()); |
57 } | 57 } |
58 | 58 |
59 void SVGTextLayoutEngine::updateCharacterPositionIfNeeded(float& x, float& y) | 59 void SVGTextLayoutEngine::updateCharacterPositionIfNeeded(float& x, float& y) |
60 { | 60 { |
61 if (m_inPathLayout) | 61 if (m_inPathLayout) |
62 return; | 62 return; |
63 | 63 |
64 // Replace characters x/y position, with the current text position plus any | 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. | 65 // relative adjustments, if it doesn't specify an absolute position itself. |
66 if (x == SVGTextLayoutAttributes::emptyValue()) | 66 if (SVGTextLayoutAttributes::isEmptyValue(x)) |
67 x = m_x + m_dx; | 67 x = m_x + m_dx; |
68 | 68 |
69 if (y == SVGTextLayoutAttributes::emptyValue()) | 69 if (SVGTextLayoutAttributes::isEmptyValue(y)) |
70 y = m_y + m_dy; | 70 y = m_y + m_dy; |
71 | 71 |
72 m_dx = 0; | 72 m_dx = 0; |
73 m_dy = 0; | 73 m_dy = 0; |
74 } | 74 } |
75 | 75 |
76 void SVGTextLayoutEngine::updateCurrentTextPosition(float x, float y, float glyp
hAdvance) | 76 void SVGTextLayoutEngine::updateCurrentTextPosition(float x, float y, float glyp
hAdvance) |
77 { | 77 { |
78 // Update current text position after processing the character. | 78 // Update current text position after processing the character. |
79 if (m_isVerticalText) { | 79 if (m_isVerticalText) { |
80 m_x = x; | 80 m_x = x; |
81 m_y = y + glyphAdvance; | 81 m_y = y + glyphAdvance; |
82 } else { | 82 } else { |
83 m_x = x + glyphAdvance; | 83 m_x = x + glyphAdvance; |
84 m_y = y; | 84 m_y = y; |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 void SVGTextLayoutEngine::updateRelativePositionAdjustmentsIfNeeded(float dx, fl
oat dy) | 88 void SVGTextLayoutEngine::updateRelativePositionAdjustmentsIfNeeded(float dx, fl
oat dy) |
89 { | 89 { |
90 // Update relative positioning information. | 90 // Update relative positioning information. |
91 if (dx == SVGTextLayoutAttributes::emptyValue() && dy == SVGTextLayoutAttrib
utes::emptyValue()) | 91 if (SVGTextLayoutAttributes::isEmptyValue(dx) && SVGTextLayoutAttributes::is
EmptyValue(dy)) |
92 return; | 92 return; |
93 | 93 |
94 if (dx == SVGTextLayoutAttributes::emptyValue()) | 94 if (SVGTextLayoutAttributes::isEmptyValue(dx)) |
95 dx = 0; | 95 dx = 0; |
96 if (dy == SVGTextLayoutAttributes::emptyValue()) | 96 if (SVGTextLayoutAttributes::isEmptyValue(dy)) |
97 dy = 0; | 97 dy = 0; |
98 | 98 |
99 if (m_inPathLayout) { | 99 if (m_inPathLayout) { |
100 if (m_isVerticalText) { | 100 if (m_isVerticalText) { |
101 m_dx += dx; | 101 m_dx += dx; |
102 m_dy = dy; | 102 m_dy = dy; |
103 } else { | 103 } else { |
104 m_dx = dx; | 104 m_dx = dx; |
105 m_dy += dy; | 105 m_dy += dy; |
106 } | 106 } |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 data = it->value; | 478 data = it->value; |
479 | 479 |
480 float x = data.x; | 480 float x = data.x; |
481 float y = data.y; | 481 float y = data.y; |
482 | 482 |
483 // When we've advanced to the box start offset, determine using the orig
inal x/y values, | 483 // When we've advanced to the box start offset, determine using the orig
inal x/y values, |
484 // whether this character starts a new text chunk, before doing any furt
her processing. | 484 // whether this character starts a new text chunk, before doing any furt
her processing. |
485 if (m_visualCharacterOffset == textBox->start()) | 485 if (m_visualCharacterOffset == textBox->start()) |
486 textBox->setStartsNewTextChunk(logicalAttributes->context()->charact
erStartsNewTextChunk(m_logicalCharacterOffset)); | 486 textBox->setStartsNewTextChunk(logicalAttributes->context()->charact
erStartsNewTextChunk(m_logicalCharacterOffset)); |
487 | 487 |
488 float angle = data.rotate == SVGTextLayoutAttributes::emptyValue() ? 0 :
data.rotate; | 488 float angle = SVGTextLayoutAttributes::isEmptyValue(data.rotate) ? 0 : d
ata.rotate; |
489 | 489 |
490 // Calculate glyph orientation angle. | 490 // Calculate glyph orientation angle. |
491 UChar currentCharacter = text.characterAt(m_visualCharacterOffset); | 491 UChar currentCharacter = text.characterAt(m_visualCharacterOffset); |
492 float orientationAngle = baselineLayout.calculateGlyphOrientationAngle(m
_isVerticalText, svgStyle, currentCharacter); | 492 float orientationAngle = baselineLayout.calculateGlyphOrientationAngle(m
_isVerticalText, svgStyle, currentCharacter); |
493 | 493 |
494 // Calculate glyph advance & x/y orientation shifts. | 494 // Calculate glyph advance & x/y orientation shifts. |
495 float xOrientationShift = 0; | 495 float xOrientationShift = 0; |
496 float yOrientationShift = 0; | 496 float yOrientationShift = 0; |
497 float glyphAdvance = baselineLayout.calculateGlyphAdvanceAndOrientation(
m_isVerticalText, visualMetrics, orientationAngle, xOrientationShift, yOrientati
onShift); | 497 float glyphAdvance = baselineLayout.calculateGlyphAdvanceAndOrientation(
m_isVerticalText, visualMetrics, orientationAngle, xOrientationShift, yOrientati
onShift); |
498 | 498 |
499 // Assign current text position to x/y values, if needed. | 499 // Assign current text position to x/y values, if needed. |
500 updateCharacterPositionIfNeeded(x, y); | 500 updateCharacterPositionIfNeeded(x, y); |
501 | 501 |
502 // Apply dx/dy value adjustments to current text position, if needed. | 502 // Apply dx/dy value adjustments to current text position, if needed. |
503 updateRelativePositionAdjustmentsIfNeeded(data.dx, data.dy); | 503 updateRelativePositionAdjustmentsIfNeeded(data.dx, data.dy); |
504 | 504 |
505 // Calculate CSS 'letter-spacing' and 'word-spacing' for next character,
if needed. | 505 // Calculate CSS 'letter-spacing' and 'word-spacing' for next character,
if needed. |
506 float spacing = spacingLayout.calculateCSSSpacing(currentCharacter); | 506 float spacing = spacingLayout.calculateCSSSpacing(currentCharacter); |
507 | 507 |
508 float textPathOffset = 0; | 508 float textPathOffset = 0; |
509 if (m_inPathLayout) { | 509 if (m_inPathLayout) { |
510 float scaledGlyphAdvance = glyphAdvance * m_textPathScaling; | 510 float scaledGlyphAdvance = glyphAdvance * m_textPathScaling; |
511 if (m_isVerticalText) { | 511 if (m_isVerticalText) { |
512 // If there's an absolute y position available, it marks the beg
inning of a new position along the path. | 512 // If there's an absolute y position available, it marks the beg
inning of a new position along the path. |
513 if (y != SVGTextLayoutAttributes::emptyValue()) | 513 if (!SVGTextLayoutAttributes::isEmptyValue(y)) |
514 m_textPathCurrentOffset = y + m_textPathStartOffset; | 514 m_textPathCurrentOffset = y + m_textPathStartOffset; |
515 | 515 |
516 m_textPathCurrentOffset += m_dy; | 516 m_textPathCurrentOffset += m_dy; |
517 m_dy = 0; | 517 m_dy = 0; |
518 | 518 |
519 // Apply dx/dy correction and setup translations that move to th
e glyph midpoint. | 519 // Apply dx/dy correction and setup translations that move to th
e glyph midpoint. |
520 xOrientationShift += m_dx + baselineShift; | 520 xOrientationShift += m_dx + baselineShift; |
521 yOrientationShift -= scaledGlyphAdvance / 2; | 521 yOrientationShift -= scaledGlyphAdvance / 2; |
522 } else { | 522 } else { |
523 // If there's an absolute x position available, it marks the beg
inning of a new position along the path. | 523 // If there's an absolute x position available, it marks the beg
inning of a new position along the path. |
524 if (x != SVGTextLayoutAttributes::emptyValue()) | 524 if (!SVGTextLayoutAttributes::isEmptyValue(x)) |
525 m_textPathCurrentOffset = x + m_textPathStartOffset; | 525 m_textPathCurrentOffset = x + m_textPathStartOffset; |
526 | 526 |
527 m_textPathCurrentOffset += m_dx; | 527 m_textPathCurrentOffset += m_dx; |
528 m_dx = 0; | 528 m_dx = 0; |
529 | 529 |
530 // Apply dx/dy correction and setup translations that move to th
e glyph midpoint. | 530 // Apply dx/dy correction and setup translations that move to th
e glyph midpoint. |
531 xOrientationShift -= scaledGlyphAdvance / 2; | 531 xOrientationShift -= scaledGlyphAdvance / 2; |
532 yOrientationShift += m_dy - baselineShift; | 532 yOrientationShift += m_dy - baselineShift; |
533 } | 533 } |
534 | 534 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 } | 634 } |
635 | 635 |
636 if (!didStartTextFragment) | 636 if (!didStartTextFragment) |
637 return; | 637 return; |
638 | 638 |
639 // Close last open fragment, if needed. | 639 // Close last open fragment, if needed. |
640 recordTextFragment(textBox, visualMetricsValues); | 640 recordTextFragment(textBox, visualMetricsValues); |
641 } | 641 } |
642 | 642 |
643 } | 643 } |
OLD | NEW |