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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "config.h" | 20 #include "config.h" |
21 #include "core/layout/svg/SVGTextLayoutEngine.h" | 21 #include "core/layout/svg/SVGTextLayoutEngine.h" |
22 | 22 |
| 23 #include "core/layout/line/GlyphOverflow.h" |
23 #include "core/layout/svg/LayoutSVGInlineText.h" | 24 #include "core/layout/svg/LayoutSVGInlineText.h" |
24 #include "core/layout/svg/LayoutSVGTextPath.h" | 25 #include "core/layout/svg/LayoutSVGTextPath.h" |
25 #include "core/layout/svg/SVGTextChunkBuilder.h" | 26 #include "core/layout/svg/SVGTextChunkBuilder.h" |
26 #include "core/layout/svg/SVGTextLayoutEngineBaseline.h" | 27 #include "core/layout/svg/SVGTextLayoutEngineBaseline.h" |
27 #include "core/layout/svg/SVGTextLayoutEngineSpacing.h" | 28 #include "core/layout/svg/SVGTextLayoutEngineSpacing.h" |
28 #include "core/layout/svg/line/SVGInlineFlowBox.h" | 29 #include "core/layout/svg/line/SVGInlineFlowBox.h" |
29 #include "core/layout/svg/line/SVGInlineTextBox.h" | 30 #include "core/layout/svg/line/SVGInlineTextBox.h" |
30 #include "core/svg/SVGElement.h" | 31 #include "core/svg/SVGElement.h" |
31 #include "core/svg/SVGLengthContext.h" | 32 #include "core/svg/SVGLengthContext.h" |
32 #include "core/svg/SVGTextContentElement.h" | 33 #include "core/svg/SVGTextContentElement.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 m_dy += dy; | 104 m_dy += dy; |
104 } | 105 } |
105 | 106 |
106 return; | 107 return; |
107 } | 108 } |
108 | 109 |
109 m_dx = dx; | 110 m_dx = dx; |
110 m_dy = dy; | 111 m_dy = dy; |
111 } | 112 } |
112 | 113 |
| 114 // Computes the glyph overflow without integer clamping (see: GlyphOverflow.h). |
| 115 static void computeGlyphOverflow(SVGInlineTextBox* textBox, SVGTextFragment& tex
tFragment) |
| 116 { |
| 117 LineLayoutSVGInlineText textLineLayout = LineLayoutSVGInlineText(textBox->li
neLayoutItem()); |
| 118 TextRun run = SVGTextMetrics::constructTextRun(textLineLayout, textFragment.
characterOffset, textFragment.length, textLineLayout.styleRef().direction()); |
| 119 |
| 120 float scalingFactor = textLineLayout.scalingFactor(); |
| 121 ASSERT(scalingFactor); |
| 122 const Font& scaledFont = textLineLayout.scaledFont(); |
| 123 FloatRect glyphOverflowBounds; |
| 124 |
| 125 float width = scaledFont.width(run, nullptr, &glyphOverflowBounds); |
| 126 float ascent = scaledFont.fontMetrics().floatAscent(); |
| 127 float descent = scaledFont.fontMetrics().floatDescent(); |
| 128 |
| 129 textFragment.glyphOverflowTop = GlyphOverflow::topOverflow(glyphOverflowBoun
ds, ascent) / scalingFactor; |
| 130 textFragment.glyphOverflowBottom = GlyphOverflow::bottomOverflow(glyphOverfl
owBounds, descent) / scalingFactor; |
| 131 textFragment.glyphOverflowLeft = GlyphOverflow::leftOverflow(glyphOverflowBo
unds) / scalingFactor; |
| 132 textFragment.glyphOverflowRight = GlyphOverflow::rightOverflow(glyphOverflow
Bounds, width) / scalingFactor; |
| 133 } |
| 134 |
113 void SVGTextLayoutEngine::recordTextFragment(SVGInlineTextBox* textBox) | 135 void SVGTextLayoutEngine::recordTextFragment(SVGInlineTextBox* textBox) |
114 { | 136 { |
115 ASSERT(!m_currentTextFragment.length); | 137 ASSERT(!m_currentTextFragment.length); |
116 | 138 |
117 // Figure out length of fragment. | 139 // Figure out length of fragment. |
118 m_currentTextFragment.length = m_visualMetricsIterator.characterOffset() - m
_currentTextFragment.characterOffset; | 140 m_currentTextFragment.length = m_visualMetricsIterator.characterOffset() - m
_currentTextFragment.characterOffset; |
119 | 141 |
120 // Figure out fragment metrics. | 142 // Figure out fragment metrics. |
121 const unsigned visualMetricsListOffset = m_visualMetricsIterator.metricsList
Offset(); | 143 const unsigned visualMetricsListOffset = m_visualMetricsIterator.metricsList
Offset(); |
122 const Vector<SVGTextMetrics>& textMetricsValues = m_visualMetricsIterator.me
tricsList(); | 144 const Vector<SVGTextMetrics>& textMetricsValues = m_visualMetricsIterator.me
tricsList(); |
123 const SVGTextMetrics& lastCharacterMetrics = textMetricsValues.at(visualMetr
icsListOffset - 1); | 145 const SVGTextMetrics& lastCharacterMetrics = textMetricsValues.at(visualMetr
icsListOffset - 1); |
124 m_currentTextFragment.width = lastCharacterMetrics.width(); | 146 m_currentTextFragment.width = lastCharacterMetrics.width(); |
125 m_currentTextFragment.height = lastCharacterMetrics.height(); | 147 m_currentTextFragment.height = lastCharacterMetrics.height(); |
126 | 148 |
127 if (m_currentTextFragment.length > 1) { | 149 if (m_currentTextFragment.length > 1) { |
128 // SVGTextLayoutAttributesBuilder assures that the length of the range i
s equal to the sum of the individual lengths of the glyphs. | 150 // SVGTextLayoutAttributesBuilder assures that the length of the range i
s equal to the sum of the individual lengths of the glyphs. |
129 float length = 0; | 151 float length = 0; |
130 if (m_isVerticalText) { | 152 if (m_isVerticalText) { |
131 for (unsigned i = m_currentTextFragment.metricsListOffset; i < visua
lMetricsListOffset; ++i) | 153 for (unsigned i = m_currentTextFragment.metricsListOffset; i < visua
lMetricsListOffset; ++i) |
132 length += textMetricsValues.at(i).height(); | 154 length += textMetricsValues.at(i).height(); |
133 m_currentTextFragment.height = length; | 155 m_currentTextFragment.height = length; |
134 } else { | 156 } else { |
135 for (unsigned i = m_currentTextFragment.metricsListOffset; i < visua
lMetricsListOffset; ++i) | 157 for (unsigned i = m_currentTextFragment.metricsListOffset; i < visua
lMetricsListOffset; ++i) |
136 length += textMetricsValues.at(i).width(); | 158 length += textMetricsValues.at(i).width(); |
137 m_currentTextFragment.width = length; | 159 m_currentTextFragment.width = length; |
138 } | 160 } |
139 } | 161 } |
140 | 162 |
| 163 computeGlyphOverflow(textBox, m_currentTextFragment); |
141 textBox->textFragments().append(m_currentTextFragment); | 164 textBox->textFragments().append(m_currentTextFragment); |
142 m_currentTextFragment = SVGTextFragment(); | 165 m_currentTextFragment = SVGTextFragment(); |
143 } | 166 } |
144 | 167 |
145 void SVGTextLayoutEngine::beginTextPathLayout(SVGInlineFlowBox* flowBox) | 168 void SVGTextLayoutEngine::beginTextPathLayout(SVGInlineFlowBox* flowBox) |
146 { | 169 { |
147 // Build text chunks for all <textPath> children, using the line layout algo
rithm. | 170 // Build text chunks for all <textPath> children, using the line layout algo
rithm. |
148 // This is needeed as text-anchor is just an additional startOffset for text
paths. | 171 // This is needeed as text-anchor is just an additional startOffset for text
paths. |
149 SVGTextLayoutEngine lineLayout(m_layoutAttributes); | 172 SVGTextLayoutEngine lineLayout(m_layoutAttributes); |
150 lineLayout.m_textLengthSpacingInEffect = m_textLengthSpacingInEffect; | 173 lineLayout.m_textLengthSpacingInEffect = m_textLengthSpacingInEffect; |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 } | 558 } |
536 | 559 |
537 if (!didStartTextFragment) | 560 if (!didStartTextFragment) |
538 return; | 561 return; |
539 | 562 |
540 // Close last open fragment, if needed. | 563 // Close last open fragment, if needed. |
541 recordTextFragment(textBox); | 564 recordTextFragment(textBox); |
542 } | 565 } |
543 | 566 |
544 } | 567 } |
OLD | NEW |