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 29 matching lines...) Expand all Loading... |
40 , m_logicalCharacterOffset(0) | 40 , m_logicalCharacterOffset(0) |
41 , m_logicalMetricsListOffset(0) | 41 , m_logicalMetricsListOffset(0) |
42 , m_visualCharacterOffset(0) | 42 , m_visualCharacterOffset(0) |
43 , m_visualMetricsListOffset(0) | 43 , m_visualMetricsListOffset(0) |
44 , m_x(0) | 44 , m_x(0) |
45 , m_y(0) | 45 , m_y(0) |
46 , m_dx(0) | 46 , m_dx(0) |
47 , m_dy(0) | 47 , m_dy(0) |
48 , m_isVerticalText(false) | 48 , m_isVerticalText(false) |
49 , m_inPathLayout(false) | 49 , m_inPathLayout(false) |
| 50 , m_textPathCalculator(0) |
50 , m_textPathLength(0) | 51 , m_textPathLength(0) |
51 , m_textPathCurrentOffset(0) | 52 , m_textPathCurrentOffset(0) |
52 , m_textPathSpacing(0) | 53 , m_textPathSpacing(0) |
53 , m_textPathScaling(1) | 54 , m_textPathScaling(1) |
54 { | 55 { |
55 ASSERT(!m_layoutAttributes.isEmpty()); | 56 ASSERT(!m_layoutAttributes.isEmpty()); |
56 } | 57 } |
57 | 58 |
58 void SVGTextLayoutEngine::updateCharacerPositionIfNeeded(float& x, float& y) | 59 void SVGTextLayoutEngine::updateCharacerPositionIfNeeded(float& x, float& y) |
59 { | 60 { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 return false; | 163 return false; |
163 } | 164 } |
164 | 165 |
165 void SVGTextLayoutEngine::beginTextPathLayout(RenderObject* object, SVGTextLayou
tEngine& lineLayout) | 166 void SVGTextLayoutEngine::beginTextPathLayout(RenderObject* object, SVGTextLayou
tEngine& lineLayout) |
166 { | 167 { |
167 ASSERT(object); | 168 ASSERT(object); |
168 | 169 |
169 m_inPathLayout = true; | 170 m_inPathLayout = true; |
170 RenderSVGTextPath* textPath = toRenderSVGTextPath(object); | 171 RenderSVGTextPath* textPath = toRenderSVGTextPath(object); |
171 | 172 |
172 m_textPath = textPath->layoutPath(); | 173 Path path = textPath->layoutPath(); |
173 if (m_textPath.isEmpty()) | 174 if (path.isEmpty()) |
174 return; | 175 return; |
| 176 m_textPathCalculator = new Path::PositionCalculator(path); |
175 m_textPathStartOffset = textPath->startOffset(); | 177 m_textPathStartOffset = textPath->startOffset(); |
176 m_textPathLength = m_textPath.length(); | 178 m_textPathLength = path.length(); |
177 if (m_textPathStartOffset > 0 && m_textPathStartOffset <= 1) | 179 if (m_textPathStartOffset > 0 && m_textPathStartOffset <= 1) |
178 m_textPathStartOffset *= m_textPathLength; | 180 m_textPathStartOffset *= m_textPathLength; |
179 | 181 |
180 float totalLength = 0; | 182 float totalLength = 0; |
181 unsigned totalCharacters = 0; | 183 unsigned totalCharacters = 0; |
182 | 184 |
183 lineLayout.m_chunkLayoutBuilder.buildTextChunks(lineLayout.m_lineLayoutBoxes
); | 185 lineLayout.m_chunkLayoutBuilder.buildTextChunks(lineLayout.m_lineLayoutBoxes
); |
184 const Vector<SVGTextChunk>& textChunks = lineLayout.m_chunkLayoutBuilder.tex
tChunks(); | 186 const Vector<SVGTextChunk>& textChunks = lineLayout.m_chunkLayoutBuilder.tex
tChunks(); |
185 | 187 |
186 unsigned size = textChunks.size(); | 188 unsigned size = textChunks.size(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 220 |
219 if (lengthAdjust == SVGLengthAdjustSpacing) | 221 if (lengthAdjust == SVGLengthAdjustSpacing) |
220 m_textPathSpacing = (desiredTextLength - totalLength) / totalCharacters; | 222 m_textPathSpacing = (desiredTextLength - totalLength) / totalCharacters; |
221 else | 223 else |
222 m_textPathScaling = desiredTextLength / totalLength; | 224 m_textPathScaling = desiredTextLength / totalLength; |
223 } | 225 } |
224 | 226 |
225 void SVGTextLayoutEngine::endTextPathLayout() | 227 void SVGTextLayoutEngine::endTextPathLayout() |
226 { | 228 { |
227 m_inPathLayout = false; | 229 m_inPathLayout = false; |
228 m_textPath = Path(); | 230 delete m_textPathCalculator; |
| 231 m_textPathCalculator = 0; |
229 m_textPathLength = 0; | 232 m_textPathLength = 0; |
230 m_textPathStartOffset = 0; | 233 m_textPathStartOffset = 0; |
231 m_textPathCurrentOffset = 0; | 234 m_textPathCurrentOffset = 0; |
232 m_textPathSpacing = 0; | 235 m_textPathSpacing = 0; |
233 m_textPathScaling = 1; | 236 m_textPathScaling = 1; |
234 } | 237 } |
235 | 238 |
236 void SVGTextLayoutEngine::layoutInlineTextBox(SVGInlineTextBox* textBox) | 239 void SVGTextLayoutEngine::layoutInlineTextBox(SVGInlineTextBox* textBox) |
237 { | 240 { |
238 ASSERT(textBox); | 241 ASSERT(textBox); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 420 } |
418 | 421 |
419 void SVGTextLayoutEngine::advanceToNextVisualCharacter(const SVGTextMetrics& vis
ualMetrics) | 422 void SVGTextLayoutEngine::advanceToNextVisualCharacter(const SVGTextMetrics& vis
ualMetrics) |
420 { | 423 { |
421 ++m_visualMetricsListOffset; | 424 ++m_visualMetricsListOffset; |
422 m_visualCharacterOffset += visualMetrics.length(); | 425 m_visualCharacterOffset += visualMetrics.length(); |
423 } | 426 } |
424 | 427 |
425 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Rend
erSVGInlineText* text, const RenderStyle* style) | 428 void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Rend
erSVGInlineText* text, const RenderStyle* style) |
426 { | 429 { |
427 if (m_inPathLayout && m_textPath.isEmpty()) | 430 if (m_inPathLayout && !m_textPathCalculator) |
428 return; | 431 return; |
429 | 432 |
430 SVGElement* lengthContext = toSVGElement(text->parent()->node()); | 433 SVGElement* lengthContext = toSVGElement(text->parent()->node()); |
431 | 434 |
432 RenderObject* textParent = text->parent(); | 435 RenderObject* textParent = text->parent(); |
433 bool definesTextLength = textParent ? parentDefinesTextLength(textParent) :
false; | 436 bool definesTextLength = textParent ? parentDefinesTextLength(textParent) :
false; |
434 | 437 |
435 const SVGRenderStyle* svgStyle = style->svgStyle(); | 438 const SVGRenderStyle* svgStyle = style->svgStyle(); |
436 ASSERT(svgStyle); | 439 ASSERT(svgStyle); |
437 | 440 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 advanceToNextLogicalCharacter(logicalMetrics); | 552 advanceToNextLogicalCharacter(logicalMetrics); |
550 advanceToNextVisualCharacter(visualMetrics); | 553 advanceToNextVisualCharacter(visualMetrics); |
551 continue; | 554 continue; |
552 } | 555 } |
553 | 556 |
554 // Stop processing, if the next character lies behind the path. | 557 // Stop processing, if the next character lies behind the path. |
555 if (textPathOffset > m_textPathLength) | 558 if (textPathOffset > m_textPathLength) |
556 break; | 559 break; |
557 | 560 |
558 FloatPoint point; | 561 FloatPoint point; |
559 bool ok = m_textPath.pointAndNormalAtLength(textPathOffset, point, a
ngle); | 562 bool ok = m_textPathCalculator->pointAndNormalAtLength(textPathOffse
t, point, angle); |
560 ASSERT_UNUSED(ok, ok); | 563 ASSERT_UNUSED(ok, ok); |
561 x = point.x(); | 564 x = point.x(); |
562 y = point.y(); | 565 y = point.y(); |
563 | 566 |
564 // For vertical text on path, the actual angle has to be rotated 90
degrees anti-clockwise, not the orientation angle! | 567 // For vertical text on path, the actual angle has to be rotated 90
degrees anti-clockwise, not the orientation angle! |
565 if (m_isVerticalText) | 568 if (m_isVerticalText) |
566 angle -= 90; | 569 angle -= 90; |
567 } else { | 570 } else { |
568 // Apply all previously calculated shift values. | 571 // Apply all previously calculated shift values. |
569 if (m_isVerticalText) { | 572 if (m_isVerticalText) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 } | 646 } |
644 | 647 |
645 if (!didStartTextFragment) | 648 if (!didStartTextFragment) |
646 return; | 649 return; |
647 | 650 |
648 // Close last open fragment, if needed. | 651 // Close last open fragment, if needed. |
649 recordTextFragment(textBox, visualMetricsValues); | 652 recordTextFragment(textBox, visualMetricsValues); |
650 } | 653 } |
651 | 654 |
652 } | 655 } |
OLD | NEW |