COMMIT_MESSAGE (01/19)

 1GlyphBase
 2

Source/WebCore/ChangeLog

 12016-04-22 Frederic Wang <fred.wang@free.fr>
 2
 3 RenderMathMLOperator refactoring: introduce getBaseGlyph and remove parameter from getDisplayStyleLargeOperator
 4 https://bugs.webkit.org/show_bug.cgi?id=156910
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 No new tests, the behavior is not changed.
 9
 10 * rendering/mathml/RenderMathMLOperator.cpp:
 11 (WebCore::RenderMathMLOperator::italicCorrection): We do not need to pass m_textContent to getDisplayStyleLargeOperator.
 12 (WebCore::RenderMathMLOperator::computePreferredLogicalWidths): We use getBaseGlyph and do not pass m_textContent to getDisplayStyleLargeOperator or findStretchyData.
 13 (WebCore::RenderMathMLOperator::getBaseGlyph): Introduce a helper function to retrieve the base glyph and do some validity checks.
 14 (WebCore::RenderMathMLOperator::getDisplayStyleLargeOperator): We remove the character parameter as it is always m_textContent.
 15 We use getBaseGlyph and replace primaryFont with baseGlyph.font.
 16 (WebCore::RenderMathMLOperator::findStretchyData): Ditto.
 17 (WebCore::RenderMathMLOperator::updateStyle): We do not pass m_textContent to getDisplayStyleLargeOperator or findStretchyData.
 18 * rendering/mathml/RenderMathMLOperator.h: Declare getBaseGlyph and remove the parameter from getDisplayStyleLargeOperator and findStretchyData.
 19
1202016-04-25 Ryosuke Niwa <rniwa@webkit.org>
221
322 Remove the build flag for template elements

Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp

@@LayoutUnit RenderMathMLOperator::italicCorrection() const
207207 if (isLargeOperatorInDisplayStyle()) {
208208 const auto& primaryFont = style().fontCascade().primaryFont();
209209 if (auto* mathData = primaryFont.mathData()) {
210  StretchyData largeOperator = getDisplayStyleLargeOperator(m_textContent);
 210 StretchyData largeOperator = getDisplayStyleLargeOperator();
211211 return mathData->getItalicCorrection(primaryFont, largeOperator.variant().glyph);
212212 }
213213 }

@@void RenderMathMLOperator::computePreferredLogicalWidths()
306306 return;
307307 }
308308
309  GlyphData data = style().fontCascade().glyphDataForCharacter(m_textContent, !style().isLeftToRightDirection());
310  float maximumGlyphWidth = advanceWidthForGlyph(data);
 309 GlyphData baseGlyph;
 310 float maximumGlyphWidth = getBaseGlyph(style(), baseGlyph) ? advanceWidthForGlyph(baseGlyph) : 0;
311311 if (!m_isVertical) {
312312 if (maximumGlyphWidth < stretchSize())
313313 maximumGlyphWidth = stretchSize();

@@void RenderMathMLOperator::computePreferredLogicalWidths()
317317 }
318318 if (isLargeOperatorInDisplayStyle()) {
319319 // 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/).
320  StretchyData largeOperator = getDisplayStyleLargeOperator(m_textContent);
 320 StretchyData largeOperator = getDisplayStyleLargeOperator();
321321 if (largeOperator.mode() == DrawSizeVariant)
322322 maximumGlyphWidth = boundsForGlyph(largeOperator.variant()).width();
323323 } else {
324324 // 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).
325  findStretchyData(m_textContent, &maximumGlyphWidth);
 325 findStretchyData(&maximumGlyphWidth);
326326 }
327327 m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth = m_leadingSpace + maximumGlyphWidth + m_trailingSpace;
328328}

@@void RenderMathMLOperator::styleDidChange(StyleDifference diff, const RenderStyl
386386 updateOperatorProperties();
387387}
388388
 389bool RenderMathMLOperator::getBaseGlyph(const RenderStyle& style, GlyphData& baseGlyph) const
 390{
 391 baseGlyph = style.fontCascade().glyphDataForCharacter(m_textContent, !style.isLeftToRightDirection());
 392 return baseGlyph.isValid() && baseGlyph.font == &style.fontCascade().primaryFont();
 393}
 394
389395bool RenderMathMLOperator::getGlyphAssemblyFallBack(Vector<OpenTypeMathData::AssemblyPart> assemblyParts, StretchyData& stretchyData) const
390396{
391397 GlyphData top;

@@bool RenderMathMLOperator::getGlyphAssemblyFallBack(Vector<OpenTypeMathData::Ass
496502 return true;
497503}
498504
499 RenderMathMLOperator::StretchyData RenderMathMLOperator::getDisplayStyleLargeOperator(UChar character) const
 505RenderMathMLOperator::StretchyData RenderMathMLOperator::getDisplayStyleLargeOperator() const
500506{
501507 StretchyData data;
502508
503509 ASSERT(m_isVertical && isLargeOperatorInDisplayStyle());
504510
505  const auto& primaryFont = style().fontCascade().primaryFont();
506  GlyphData baseGlyph = style().fontCascade().glyphDataForCharacter(character, !style().isLeftToRightDirection());
507  if (!primaryFont.mathData() || baseGlyph.font != &primaryFont || !baseGlyph.font || !baseGlyph.glyph)
 511 GlyphData baseGlyph;
 512 if (!getBaseGlyph(style(), baseGlyph) || !baseGlyph.font->mathData())
508513 return data;
509514
510515 Vector<Glyph> sizeVariants;
511516 Vector<OpenTypeMathData::AssemblyPart> assemblyParts;
512517
513518 // The value of displayOperatorMinHeight is sometimes too small, so we ensure that it is at least \sqrt{2} times the size of the base glyph.
514  float displayOperatorMinHeight = std::max(baseGlyph.font->boundsForGlyph(baseGlyph.glyph).height() * sqrtOfTwoFloat, primaryFont.mathData()->getMathConstant(primaryFont, OpenTypeMathData::DisplayOperatorMinHeight));
 519 float displayOperatorMinHeight = std::max(baseGlyph.font->boundsForGlyph(baseGlyph.glyph).height() * sqrtOfTwoFloat, baseGlyph.font->mathData()->getMathConstant(*baseGlyph.font, OpenTypeMathData::DisplayOperatorMinHeight));
515520
516  primaryFont.mathData()->getMathVariants(baseGlyph.glyph, true, sizeVariants, assemblyParts);
 521 baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, true, sizeVariants, assemblyParts);
517522
518523 // We choose the first size variant that is larger than the expected displayOperatorMinHeight and otherwise fallback to the largest variant.
519524 for (auto& variant : sizeVariants) {
520525 GlyphData sizeVariant;
521526 sizeVariant.glyph = variant;
522  sizeVariant.font = &primaryFont;
 527 sizeVariant.font = baseGlyph.font;
523528 data.setSizeVariantMode(sizeVariant);
524529 if (boundsForGlyph(sizeVariant).height() >= displayOperatorMinHeight)
525530 return data;

@@RenderMathMLOperator::StretchyData RenderMathMLOperator::getDisplayStyleLargeOpe
527532 return data;
528533}
529534
530 RenderMathMLOperator::StretchyData RenderMathMLOperator::findStretchyData(UChar character, float* maximumGlyphWidth)
 535RenderMathMLOperator::StretchyData RenderMathMLOperator::findStretchyData(float* maximumGlyphWidth)
531536{
532537 ASSERT(!maximumGlyphWidth || m_isVertical);
533538
534539 StretchyData data;
535540 StretchyData assemblyData;
536541
537  const auto& primaryFont = style().fontCascade().primaryFont();
538  GlyphData baseGlyph = style().fontCascade().glyphDataForCharacter(character, !style().isLeftToRightDirection());
 542 GlyphData baseGlyph;
 543 if (!getBaseGlyph(style(), baseGlyph))
 544 return data;
539545
540  if (primaryFont.mathData() && baseGlyph.font == &primaryFont) {
 546 if (baseGlyph.font->mathData()) {
541547 Vector<Glyph> sizeVariants;
542548 Vector<OpenTypeMathData::AssemblyPart> assemblyParts;
543  primaryFont.mathData()->getMathVariants(baseGlyph.glyph, m_isVertical, sizeVariants, assemblyParts);
 549 baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, m_isVertical, sizeVariants, assemblyParts);
544550 // We verify the size variants.
545551 for (auto& variant : sizeVariants) {
546552 GlyphData sizeVariant;
547553 sizeVariant.glyph = variant;
548  sizeVariant.font = &primaryFont;
 554 sizeVariant.font = baseGlyph.font;
549555 if (maximumGlyphWidth)
550556 *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(sizeVariant));
551557 else {

@@RenderMathMLOperator::StretchyData RenderMathMLOperator::findStretchyData(UChar
567573 const StretchyCharacter* stretchyCharacter = nullptr;
568574 const unsigned maxIndex = WTF_ARRAY_LENGTH(stretchyCharacters);
569575 for (unsigned index = 0; index < maxIndex; ++index) {
570  if (stretchyCharacters[index].character == character) {
 576 if (stretchyCharacters[index].character == m_textContent) {
571577 stretchyCharacter = &stretchyCharacters[index];
572578 if (!style().isLeftToRightDirection() && index < leftRightPairsCount * 2) {
573579 // If we are in right-to-left direction we select the mirrored form by adding -1 or +1 according to the parity of index.

@@void RenderMathMLOperator::updateStyle()
641647 return;
642648
643649 if (m_isVertical && isLargeOperatorInDisplayStyle())
644  m_stretchyData = getDisplayStyleLargeOperator(m_textContent);
 650 m_stretchyData = getDisplayStyleLargeOperator();
645651 else {
646652 // We do not stretch if the base glyph is large enough.
647653 GlyphData baseGlyph = style().fontCascade().glyphDataForCharacter(m_textContent, !style().isLeftToRightDirection());
648654 float baseSize = m_isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
649655 if (stretchSize() <= baseSize)
650656 return;
651  m_stretchyData = findStretchyData(m_textContent, nullptr);
 657 m_stretchyData = findStretchyData(nullptr);
652658 }
653659
654660 if (m_isVertical && m_stretchyData.mode() == DrawSizeVariant) {

Source/WebCore/rendering/mathml/RenderMathMLOperator.h

@@private:
141141
142142 bool shouldAllowStretching() const;
143143
 144 bool getBaseGlyph(const RenderStyle&, GlyphData&) const;
144145 bool getGlyphAssemblyFallBack(Vector<OpenTypeMathData::AssemblyPart>, StretchyData&) const;
145  StretchyData getDisplayStyleLargeOperator(UChar) const;
146  StretchyData findStretchyData(UChar, float* maximumGlyphWidth);
 146 StretchyData getDisplayStyleLargeOperator() const;
 147 StretchyData findStretchyData(float* maximumGlyphWidth);
147148
148149 enum GlyphPaintTrimming {
149150 TrimTop,