Chromium Code Reviews| 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 void computeGlyphOverflow(SVGInlineTextBox* textBox, SVGTextFragment& textFragme nt) | |
|
fs
2015/12/14 09:59:31
Nit: static?
pdr.
2015/12/16 04:27:45
Done
| |
| 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 // TODO(pdr): The glyph overflow bounds can be wrong for runs with spaces. | |
|
pdr.
2015/12/16 04:27:45
I have a fix for this in https://codereview.chromi
fs
2015/12/16 10:12:21
Roger Rogers.
| |
| 126 float width = scaledFont.width(run, nullptr, &glyphOverflowBounds); | |
| 127 float ascent = scaledFont.fontMetrics().floatAscent(); | |
| 128 float descent = scaledFont.fontMetrics().floatDescent(); | |
| 129 | |
| 130 textFragment.glyphOverflowTop = GlyphOverflow::topOverflow(glyphOverflowBoun ds, ascent) / scalingFactor; | |
| 131 textFragment.glyphOverflowBottom = GlyphOverflow::bottomOverflow(glyphOverfl owBounds, descent) / scalingFactor; | |
| 132 textFragment.glyphOverflowLeft = GlyphOverflow::leftOverflow(glyphOverflowBo unds) / scalingFactor; | |
| 133 textFragment.glyphOverflowRight = GlyphOverflow::rightOverflow(glyphOverflow Bounds, width) / scalingFactor; | |
| 134 } | |
| 135 | |
| 113 void SVGTextLayoutEngine::recordTextFragment(SVGInlineTextBox* textBox) | 136 void SVGTextLayoutEngine::recordTextFragment(SVGInlineTextBox* textBox) |
| 114 { | 137 { |
| 115 ASSERT(!m_currentTextFragment.length); | 138 ASSERT(!m_currentTextFragment.length); |
| 116 | 139 |
| 117 // Figure out length of fragment. | 140 // Figure out length of fragment. |
| 118 m_currentTextFragment.length = m_visualMetricsIterator.characterOffset() - m _currentTextFragment.characterOffset; | 141 m_currentTextFragment.length = m_visualMetricsIterator.characterOffset() - m _currentTextFragment.characterOffset; |
| 119 | 142 |
| 120 // Figure out fragment metrics. | 143 // Figure out fragment metrics. |
| 121 const unsigned visualMetricsListOffset = m_visualMetricsIterator.metricsList Offset(); | 144 const unsigned visualMetricsListOffset = m_visualMetricsIterator.metricsList Offset(); |
| 122 const Vector<SVGTextMetrics>& textMetricsValues = m_visualMetricsIterator.me tricsList(); | 145 const Vector<SVGTextMetrics>& textMetricsValues = m_visualMetricsIterator.me tricsList(); |
| 123 const SVGTextMetrics& lastCharacterMetrics = textMetricsValues.at(visualMetr icsListOffset - 1); | 146 const SVGTextMetrics& lastCharacterMetrics = textMetricsValues.at(visualMetr icsListOffset - 1); |
| 124 m_currentTextFragment.width = lastCharacterMetrics.width(); | 147 m_currentTextFragment.width = lastCharacterMetrics.width(); |
| 125 m_currentTextFragment.height = lastCharacterMetrics.height(); | 148 m_currentTextFragment.height = lastCharacterMetrics.height(); |
| 126 | 149 |
| 127 if (m_currentTextFragment.length > 1) { | 150 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. | 151 // 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; | 152 float length = 0; |
| 130 if (m_isVerticalText) { | 153 if (m_isVerticalText) { |
| 131 for (unsigned i = m_currentTextFragment.metricsListOffset; i < visua lMetricsListOffset; ++i) | 154 for (unsigned i = m_currentTextFragment.metricsListOffset; i < visua lMetricsListOffset; ++i) |
| 132 length += textMetricsValues.at(i).height(); | 155 length += textMetricsValues.at(i).height(); |
| 133 m_currentTextFragment.height = length; | 156 m_currentTextFragment.height = length; |
| 134 } else { | 157 } else { |
| 135 for (unsigned i = m_currentTextFragment.metricsListOffset; i < visua lMetricsListOffset; ++i) | 158 for (unsigned i = m_currentTextFragment.metricsListOffset; i < visua lMetricsListOffset; ++i) |
| 136 length += textMetricsValues.at(i).width(); | 159 length += textMetricsValues.at(i).width(); |
| 137 m_currentTextFragment.width = length; | 160 m_currentTextFragment.width = length; |
| 138 } | 161 } |
| 139 } | 162 } |
| 140 | 163 |
| 164 computeGlyphOverflow(textBox, m_currentTextFragment); | |
| 141 textBox->textFragments().append(m_currentTextFragment); | 165 textBox->textFragments().append(m_currentTextFragment); |
| 142 m_currentTextFragment = SVGTextFragment(); | 166 m_currentTextFragment = SVGTextFragment(); |
| 143 } | 167 } |
| 144 | 168 |
| 145 void SVGTextLayoutEngine::beginTextPathLayout(SVGInlineFlowBox* flowBox) | 169 void SVGTextLayoutEngine::beginTextPathLayout(SVGInlineFlowBox* flowBox) |
| 146 { | 170 { |
| 147 // Build text chunks for all <textPath> children, using the line layout algo rithm. | 171 // 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. | 172 // This is needeed as text-anchor is just an additional startOffset for text paths. |
| 149 SVGTextLayoutEngine lineLayout(m_layoutAttributes); | 173 SVGTextLayoutEngine lineLayout(m_layoutAttributes); |
| 150 lineLayout.m_textLengthSpacingInEffect = m_textLengthSpacingInEffect; | 174 lineLayout.m_textLengthSpacingInEffect = m_textLengthSpacingInEffect; |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 } | 559 } |
| 536 | 560 |
| 537 if (!didStartTextFragment) | 561 if (!didStartTextFragment) |
| 538 return; | 562 return; |
| 539 | 563 |
| 540 // Close last open fragment, if needed. | 564 // Close last open fragment, if needed. |
| 541 recordTextFragment(textBox); | 565 recordTextFragment(textBox); |
| 542 } | 566 } |
| 543 | 567 |
| 544 } | 568 } |
| OLD | NEW |