- Revision
- 203280
- Author
- commit-qu...@webkit.org
- Date
- 2016-07-15 10:03:45 -0700 (Fri, 15 Jul 2016)
Log Message
Check whether font is nonnull for GlyphData instead of calling GlyphData::isValid()
https://bugs.webkit.org/show_bug.cgi?id=159783
Patch by Frederic Wang <fw...@igalia.com> on 2016-07-15
Reviewed by Brent Fulgham.
GlyphData::isValid() returns true for GlyphData with null 'font' pointer when the 'glyph'
index is nonzero. This behavior is not expected by the MathML code and we have had crashes
in our test suite in the past on Windows (e.g. bug 140653). We thus replace the call to
GlyphData::isValid() with a stronger verification: Whether the 'font' pointer is nonzero.
No new tests, this only makes null pointer checks stronger.
* rendering/mathml/MathOperator.cpp:
(WebCore::boundsForGlyph):
(WebCore::advanceWidthForGlyph):
(WebCore::MathOperator::getBaseGlyph):
(WebCore::MathOperator::setSizeVariant):
(WebCore::MathOperator::fillWithVerticalExtensionGlyph):
(WebCore::MathOperator::fillWithHorizontalExtensionGlyph):
(WebCore::MathOperator::paintVerticalGlyphAssembly):
(WebCore::MathOperator::paintHorizontalGlyphAssembly):
(WebCore::MathOperator::paint):
* rendering/mathml/RenderMathMLOperator.cpp:
(WebCore::RenderMathMLOperator::computePreferredLogicalWidths):
* rendering/mathml/RenderMathMLToken.cpp:
(WebCore::RenderMathMLToken::computePreferredLogicalWidths):
(WebCore::RenderMathMLToken::firstLineBaseline):
(WebCore::RenderMathMLToken::layoutBlock):
(WebCore::RenderMathMLToken::paint):
(WebCore::RenderMathMLToken::paintChildren):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (203279 => 203280)
--- trunk/Source/WebCore/ChangeLog 2016-07-15 16:51:56 UTC (rev 203279)
+++ trunk/Source/WebCore/ChangeLog 2016-07-15 17:03:45 UTC (rev 203280)
@@ -1,5 +1,38 @@
2016-07-15 Frederic Wang <fw...@igalia.com>
+ Check whether font is nonnull for GlyphData instead of calling GlyphData::isValid()
+ https://bugs.webkit.org/show_bug.cgi?id=159783
+
+ Reviewed by Brent Fulgham.
+
+ GlyphData::isValid() returns true for GlyphData with null 'font' pointer when the 'glyph'
+ index is nonzero. This behavior is not expected by the MathML code and we have had crashes
+ in our test suite in the past on Windows (e.g. bug 140653). We thus replace the call to
+ GlyphData::isValid() with a stronger verification: Whether the 'font' pointer is nonzero.
+
+ No new tests, this only makes null pointer checks stronger.
+
+ * rendering/mathml/MathOperator.cpp:
+ (WebCore::boundsForGlyph):
+ (WebCore::advanceWidthForGlyph):
+ (WebCore::MathOperator::getBaseGlyph):
+ (WebCore::MathOperator::setSizeVariant):
+ (WebCore::MathOperator::fillWithVerticalExtensionGlyph):
+ (WebCore::MathOperator::fillWithHorizontalExtensionGlyph):
+ (WebCore::MathOperator::paintVerticalGlyphAssembly):
+ (WebCore::MathOperator::paintHorizontalGlyphAssembly):
+ (WebCore::MathOperator::paint):
+ * rendering/mathml/RenderMathMLOperator.cpp:
+ (WebCore::RenderMathMLOperator::computePreferredLogicalWidths):
+ * rendering/mathml/RenderMathMLToken.cpp:
+ (WebCore::RenderMathMLToken::computePreferredLogicalWidths):
+ (WebCore::RenderMathMLToken::firstLineBaseline):
+ (WebCore::RenderMathMLToken::layoutBlock):
+ (WebCore::RenderMathMLToken::paint):
+ (WebCore::RenderMathMLToken::paintChildren):
+
+2016-07-15 Frederic Wang <fw...@igalia.com>
+
Add DejaVu Math TeX Gyre to the list of math fonts.
https://bugs.webkit.org/show_bug.cgi?id=159805
Modified: trunk/Source/WebCore/rendering/mathml/MathOperator.cpp (203279 => 203280)
--- trunk/Source/WebCore/rendering/mathml/MathOperator.cpp 2016-07-15 16:51:56 UTC (rev 203279)
+++ trunk/Source/WebCore/rendering/mathml/MathOperator.cpp 2016-07-15 17:03:45 UTC (rev 203280)
@@ -38,7 +38,7 @@
static inline FloatRect boundsForGlyph(const GlyphData& data)
{
- return data.isValid() ? data.font->boundsForGlyph(data.glyph) : FloatRect();
+ return data.font ? data.font->boundsForGlyph(data.glyph) : FloatRect();
}
static inline float heightForGlyph(const GlyphData& data)
@@ -55,7 +55,7 @@
static inline float advanceWidthForGlyph(const GlyphData& data)
{
- return data.isValid() ? data.font->widthForGlyph(data.glyph) : 0;
+ return data.font ? data.font->widthForGlyph(data.glyph) : 0;
}
// FIXME: This hardcoded data can be removed when OpenType MATH font are widely available (http://wkbug/156837).
@@ -124,12 +124,12 @@
bool MathOperator::getBaseGlyph(const RenderStyle& style, GlyphData& baseGlyph) const
{
baseGlyph = style.fontCascade().glyphDataForCharacter(m_baseCharacter, !style.isLeftToRightDirection());
- return baseGlyph.isValid() && baseGlyph.font == &style.fontCascade().primaryFont();
+ return baseGlyph.font && baseGlyph.font == &style.fontCascade().primaryFont();
}
void MathOperator::setSizeVariant(const GlyphData& sizeVariant)
{
- ASSERT(sizeVariant.isValid());
+ ASSERT(sizeVariant.font);
ASSERT(sizeVariant.font->mathData());
m_stretchType = StretchType::SizeVariant;
m_variant = sizeVariant;
@@ -468,7 +468,7 @@
{
ASSERT(m_operatorType == Type::VerticalOperator);
ASSERT(m_stretchType == StretchType::GlyphAssembly);
- ASSERT(m_assembly.extension.isValid());
+ ASSERT(m_assembly.extension.font);
ASSERT(from.y() <= to.y());
// If there is no space for the extension glyph, we don't need to do anything.
@@ -507,7 +507,7 @@
{
ASSERT(m_operatorType == Type::HorizontalOperator);
ASSERT(m_stretchType == StretchType::GlyphAssembly);
- ASSERT(m_assembly.extension.isValid());
+ ASSERT(m_assembly.extension.font);
ASSERT(from.x() <= to.x());
ASSERT(from.y() == to.y());
@@ -545,8 +545,8 @@
{
ASSERT(m_operatorType == Type::VerticalOperator);
ASSERT(m_stretchType == StretchType::GlyphAssembly);
- ASSERT(m_assembly.topOrRight.isValid());
- ASSERT(m_assembly.bottomOrLeft.isValid());
+ ASSERT(m_assembly.topOrRight.font);
+ ASSERT(m_assembly.bottomOrLeft.font);
// We are positioning the glyphs so that the edge of the tight glyph bounds line up exactly with the edges of our paint box.
LayoutPoint operatorTopLeft = paintOffset;
@@ -558,7 +558,7 @@
LayoutPoint bottomGlyphOrigin(operatorTopLeft.x(), operatorTopLeft.y() + stretchSize() - (bottomGlyphBounds.height() + bottomGlyphBounds.y()));
LayoutRect bottomGlyphPaintRect = paintGlyph(style, info, m_assembly.bottomOrLeft, bottomGlyphOrigin, TrimTop);
- if (m_assembly.middle.isValid()) {
+ if (m_assembly.middle.font) {
// Center the glyph origin between the start and end glyph paint extents. Then shift it half the paint height toward the bottom glyph.
FloatRect middleGlyphBounds = boundsForGlyph(m_assembly.middle);
LayoutPoint middleGlyphOrigin(operatorTopLeft.x(), topGlyphOrigin.y());
@@ -576,8 +576,8 @@
{
ASSERT(m_operatorType == Type::HorizontalOperator);
ASSERT(m_stretchType == StretchType::GlyphAssembly);
- ASSERT(m_assembly.bottomOrLeft.isValid());
- ASSERT(m_assembly.topOrRight.isValid());
+ ASSERT(m_assembly.bottomOrLeft.font);
+ ASSERT(m_assembly.topOrRight.font);
// We are positioning the glyphs so that the edge of the tight glyph bounds line up exactly with the edges of our paint box.
LayoutPoint operatorTopLeft = paintOffset;
@@ -589,7 +589,7 @@
LayoutPoint rightGlyphOrigin(operatorTopLeft.x() + stretchSize() - rightGlyphBounds.width(), baselineY);
LayoutRect rightGlyphPaintRect = paintGlyph(style, info, m_assembly.topOrRight, rightGlyphOrigin, TrimLeft);
- if (m_assembly.middle.isValid()) {
+ if (m_assembly.middle.font) {
// Center the glyph origin between the start and end glyph paint extents.
LayoutPoint middleGlyphOrigin(operatorTopLeft.x(), baselineY);
middleGlyphOrigin.moveBy(LayoutPoint((rightGlyphPaintRect.x() - leftGlyphPaintRect.maxX()) / 2.0, 0));
@@ -632,7 +632,7 @@
if (!getBaseGlyph(style, glyphData))
return;
} else if (m_stretchType == StretchType::SizeVariant) {
- ASSERT(m_variant.isValid());
+ ASSERT(m_variant.font);
glyphData = m_variant;
}
GlyphBuffer buffer;
Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp (203279 => 203280)
--- trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp 2016-07-15 16:51:56 UTC (rev 203279)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp 2016-07-15 17:03:45 UTC (rev 203280)
@@ -246,7 +246,7 @@
if (isInvisibleOperator()) {
// In some fonts, glyphs for invisible operators have nonzero width. Consequently, we subtract that width here to avoid wide gaps.
GlyphData data = "" false);
- float glyphWidth = data.isValid() ? data.font->widthForGlyph(data.glyph) : 0;
+ float glyphWidth = data.font ? data.font->widthForGlyph(data.glyph) : 0;
ASSERT(glyphWidth <= preferredWidth);
preferredWidth -= glyphWidth;
}
Modified: trunk/Source/WebCore/rendering/mathml/RenderMathMLToken.cpp (203279 => 203280)
--- trunk/Source/WebCore/rendering/mathml/RenderMathMLToken.cpp 2016-07-15 16:51:56 UTC (rev 203279)
+++ trunk/Source/WebCore/rendering/mathml/RenderMathMLToken.cpp 2016-07-15 17:03:45 UTC (rev 203280)
@@ -496,7 +496,7 @@
if (m_mathVariantGlyphDirty)
updateMathVariantGlyph();
- if (m_mathVariantGlyph.isValid()) {
+ if (m_mathVariantGlyph.font) {
m_maxPreferredLogicalWidth = m_minPreferredLogicalWidth = m_mathVariantGlyph.font->widthForGlyph(m_mathVariantGlyph.glyph);
setPreferredLogicalWidthsDirty(false);
return;
@@ -546,7 +546,7 @@
Optional<int> RenderMathMLToken::firstLineBaseline() const
{
- if (m_mathVariantGlyph.isValid())
+ if (m_mathVariantGlyph.font)
return Optional<int>(static_cast<int>(lroundf(-m_mathVariantGlyph.font->boundsForGlyph(m_mathVariantGlyph.glyph).y())));
return RenderMathMLBlock::firstLineBaseline();
}
@@ -558,7 +558,7 @@
if (!relayoutChildren && simplifiedLayout())
return;
- if (!m_mathVariantGlyph.isValid()) {
+ if (!m_mathVariantGlyph.font) {
RenderMathMLBlock::layoutBlock(relayoutChildren, pageLogicalHeight);
return;
}
@@ -577,7 +577,7 @@
RenderMathMLBlock::paint(info, paintOffset);
// FIXME: Instead of using DrawGlyph, we may consider using the more general TextPainter so that we can apply mathvariant to strings with an arbitrary number of characters and preserve advanced CSS effects (text-shadow, etc).
- if (info.context().paintingDisabled() || info.phase != PaintPhaseForeground || style().visibility() != VISIBLE || !m_mathVariantGlyph.isValid())
+ if (info.context().paintingDisabled() || info.phase != PaintPhaseForeground || style().visibility() != VISIBLE || !m_mathVariantGlyph.font)
return;
GraphicsContextStateSaver stateSaver(info.context());
@@ -591,7 +591,7 @@
void RenderMathMLToken::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOffset, PaintInfo& paintInfoForChild, bool usePrintRect)
{
- if (m_mathVariantGlyph.isValid())
+ if (m_mathVariantGlyph.font)
return;
RenderMathMLBlock::paintChildren(paintInfo, paintOffset, paintInfoForChild, usePrintRect);
}