Changeset 201881 in webkit
- Timestamp:
- Jun 9, 2016 1:50:44 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r201880 r201881 1 2016-06-09 Frederic Wang <fred.wang@free.fr> 2 3 RenderMathOperator: Move calculation of preferred width into MathOperator 4 https://bugs.webkit.org/show_bug.cgi?id=157071 5 6 Reviewed by Brent Fulgham. 7 8 No new tests, behavior is not change. 9 10 * rendering/mathml/MathOperator.cpp: 11 (WebCore::MathOperator::setOperator): Introduce a style parameter and call reset. 12 (WebCore::MathOperator::reset): New helper function to reset the operator. 13 For now we only set the width of the base glyph and the preferred max width. 14 (WebCore::MathOperator::calculateDisplayStyleLargeOperator): Calculate the m_maxPreferredWidth. 15 (WebCore::MathOperator::calculateStretchyData): Change the signature of the function and directly set m_maxPreferredWidth. 16 * rendering/mathml/MathOperator.h: Add m_maxPreferredWidth member and update some declarations. 17 (WebCore::MathOperator::width): New helper function. 18 (WebCore::MathOperator::maxPreferredWidth): New helper function. 19 * rendering/mathml/RenderMathMLOperator.cpp: 20 (WebCore::RenderMathMLOperator::computePreferredLogicalWidths): This function performs wrong 21 operations that will be fixed in bug 152244 when we update the tests. 22 For now, let's just use maxPreferredWidth() for non-horizontal operators. 23 (WebCore::RenderMathMLOperator::updateStyle): Use the new signature of the functions. 24 1 25 2016-06-09 Alex Christensen <achristensen@webkit.org> 2 26 -
trunk/Source/WebCore/rendering/mathml/MathOperator.cpp
r201862 r201881 76 76 }; 77 77 78 void MathOperator::setOperator( UChar baseCharacter, Type operatorType)78 void MathOperator::setOperator(const RenderStyle& style, UChar baseCharacter, Type operatorType) 79 79 { 80 80 m_baseCharacter = baseCharacter; 81 81 m_operatorType = operatorType; 82 reset(style); 83 } 84 85 void MathOperator::reset(const RenderStyle& style) 86 { 87 m_maxPreferredWidth = 0; 88 m_width = 0; 89 90 // We use the base size for the calculation of the preferred width. 91 GlyphData baseGlyph; 92 if (!getBaseGlyph(style, baseGlyph)) 93 return; 94 m_maxPreferredWidth = m_width = advanceWidthForGlyph(baseGlyph); 95 96 if (m_operatorType == Type::VerticalOperator) 97 calculateStretchyData(style, true); // We also take into account the width of larger sizes for the calculation of the preferred width. 98 else if (m_operatorType == Type::DisplayOperator) 99 calculateDisplayStyleLargeOperator(style); // We can directly select the size variant and determine the final metrics. 82 100 } 83 101 … … 128 146 GlyphData glyphData(sizeVariant, baseGlyph.font); 129 147 setSizeVariant(glyphData); 148 // Large operators in STIX Word have incorrect advance width, causing misplacement of superscript, so we use the glyph bound instead (http://sourceforge.net/p/stixfonts/tracking/49/). 149 m_maxPreferredWidth = boundsForGlyph(glyphData).width(); 130 150 m_italicCorrection = glyphData.font->mathData()->getItalicCorrection(*glyphData.font, glyphData.glyph); 131 151 if (heightForGlyph(glyphData) >= displayOperatorMinHeight) … … 236 256 } 237 257 238 void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximumGlyphWidth, LayoutUnit targetSize)258 void MathOperator::calculateStretchyData(const RenderStyle& style, bool calculateMaxPreferredWidth, LayoutUnit targetSize) 239 259 { 240 260 ASSERT(m_operatorType == Type::VerticalOperator || m_operatorType == Type::HorizontalOperator); 241 ASSERT(! maximumGlyphWidth || m_operatorType == Type::VerticalOperator);261 ASSERT(!calculateMaxPreferredWidth || m_operatorType == Type::VerticalOperator); 242 262 bool isVertical = m_operatorType == Type::VerticalOperator; 243 263 … … 246 266 return; 247 267 248 if (! maximumGlyphWidth) {268 if (!calculateMaxPreferredWidth) { 249 269 // We do not stretch if the base glyph is large enough. 250 270 float baseSize = isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph); … … 253 273 } 254 274 255 MathOperator::GlyphAssemblyData assemblyData;275 GlyphAssemblyData assemblyData; 256 276 if (baseGlyph.font->mathData()) { 257 277 Vector<Glyph> sizeVariants; … … 261 281 for (auto& sizeVariant : sizeVariants) { 262 282 GlyphData glyphData(sizeVariant, baseGlyph.font); 263 if ( maximumGlyphWidth)264 *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(glyphData));283 if (calculateMaxPreferredWidth) 284 m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(glyphData)); 265 285 else { 266 286 setSizeVariant(glyphData); 267 float size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);287 LayoutUnit size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData); 268 288 if (size >= targetSize) 269 289 return; … … 304 324 305 325 // If we are measuring the maximum width, verify each component. 306 if ( maximumGlyphWidth) {307 *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.topOrRight));308 *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.extension));309 *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.middle));310 *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(assemblyData.bottomOrLeft));326 if (calculateMaxPreferredWidth) { 327 m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.topOrRight)); 328 m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.extension)); 329 m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.middle)); 330 m_maxPreferredWidth = std::max<LayoutUnit>(m_maxPreferredWidth, advanceWidthForGlyph(assemblyData.bottomOrLeft)); 311 331 return; 312 332 } -
trunk/Source/WebCore/rendering/mathml/MathOperator.h
r201862 r201881 42 42 MathOperator() { } 43 43 enum class Type { UndefinedOperator, DisplayOperator, VerticalOperator, HorizontalOperator }; 44 void setOperator(UChar baseCharacter, Type); 44 void setOperator(const RenderStyle&, UChar baseCharacter, Type); 45 void reset(const RenderStyle&); 45 46 47 LayoutUnit width() const { return m_width; } 48 LayoutUnit maxPreferredWidth() const { return m_maxPreferredWidth; } 46 49 LayoutUnit italicCorrection() const { return m_italicCorrection; } 47 50 … … 72 75 void setGlyphAssembly(const GlyphAssemblyData&); 73 76 void calculateDisplayStyleLargeOperator(const RenderStyle&); 74 void calculateStretchyData(const RenderStyle&, float* maximumGlyphWidth, LayoutUnit targetSize = 0);77 void calculateStretchyData(const RenderStyle&, bool calculateMaxPreferredWidth, LayoutUnit targetSize = 0); 75 78 bool calculateGlyphAssemblyFallback(const RenderStyle&, const Vector<OpenTypeMathData::AssemblyPart>&, GlyphAssemblyData&) const; 76 79 … … 81 84 void paintHorizontalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&); 82 85 83 UChar m_baseCharacter = 0;86 UChar m_baseCharacter { 0 }; 84 87 Type m_operatorType { Type::UndefinedOperator }; 85 StretchType m_stretchType = StretchType::Unstretched;88 StretchType m_stretchType { StretchType::Unstretched }; 86 89 union { 87 90 GlyphData m_variant; 88 91 GlyphAssemblyData m_assembly; 89 92 }; 90 LayoutUnit m_width = 0; 91 LayoutUnit m_ascent = 0; 92 LayoutUnit m_descent = 0; 93 LayoutUnit m_italicCorrection = 0; 93 LayoutUnit m_maxPreferredWidth { 0 }; 94 LayoutUnit m_width { 0 }; 95 LayoutUnit m_ascent { 0 }; 96 LayoutUnit m_descent { 0 }; 97 LayoutUnit m_italicCorrection { 0 }; 94 98 }; 95 99 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp
r201862 r201881 268 268 } 269 269 270 // FIXME: We should not use stretchSize during the preferred width calculation nor should we leave logical width dirty (http://webkit.org/b/152244). 270 271 MathOperator::Type type; 271 272 if (isLargeOperatorInDisplayStyle()) … … 273 274 else 274 275 type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator; 275 m_mathOperator.setOperator(m_textContent, type); 276 GlyphData baseGlyph; 277 float maximumGlyphWidth = m_mathOperator.getBaseGlyph(style(), baseGlyph) ? advanceWidthForGlyph(baseGlyph) : 0; 276 m_mathOperator.setOperator(style(), m_textContent, type); 277 float maximumGlyphWidth; 278 278 if (!m_isVertical) { 279 maximumGlyphWidth = m_mathOperator.width(); 279 280 if (maximumGlyphWidth < stretchSize()) 280 281 maximumGlyphWidth = stretchSize(); 281 m_maxPreferredLogicalWidth = m_leadingSpace + maximumGlyphWidth + m_trailingSpace; 282 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth; 283 return; 284 } 285 if (isLargeOperatorInDisplayStyle()) { 286 // Large operators in STIX Word have incorrect advance width, causing misplacement of superscript, so we use the glyph bound instead (http://sourceforge.net/p/stixfonts/tracking/49/). 287 m_mathOperator.calculateDisplayStyleLargeOperator(style()); 288 if (m_mathOperator.m_stretchType == MathOperator::StretchType::SizeVariant) 289 maximumGlyphWidth = boundsForGlyph(m_mathOperator.m_variant).width(); 290 } else { 291 // FIXME: some glyphs (e.g. the one for "FRACTION SLASH" in the STIX Math font or large operators) have a width that depends on the height, resulting in large gaps (https://bugs.webkit.org/show_bug.cgi?id=130326). 292 m_mathOperator.calculateStretchyData(style(), &maximumGlyphWidth); 293 } 282 } else 283 maximumGlyphWidth = m_mathOperator.maxPreferredWidth(); 294 284 m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth = m_leadingSpace + maximumGlyphWidth + m_trailingSpace; 295 285 } … … 380 370 else 381 371 type = m_isVertical ? MathOperator::Type::VerticalOperator : MathOperator::Type::HorizontalOperator; 382 m_mathOperator.setOperator( m_textContent, type);372 m_mathOperator.setOperator(style(), m_textContent, type); 383 373 if (m_isVertical && isLargeOperatorInDisplayStyle()) 384 374 m_mathOperator.calculateDisplayStyleLargeOperator(style()); 385 375 else { 386 m_mathOperator.calculateStretchyData(style(), nullptr, stretchSize());376 m_mathOperator.calculateStretchyData(style(), false, stretchSize()); 387 377 if (!m_mathOperator.isStretched()) 388 378 return;
Note: See TracChangeset
for help on using the changeset viewer.