Changeset 117788 in webkit


Ignore:
Timestamp:
May 21, 2012 9:06:50 AM (12 years ago)
Author:
schenney@chromium.org
Message:

SVGTextRunRenderingContext can return null font, calling code asserts not null
https://bugs.webkit.org/show_bug.cgi?id=86738

Reviewed by Nikolas Zimmermann.

SVGTextRunRenderingContext::glyphDataForCharacter was returning a glyph with
null font data for numerous code paths. It seems that it was doing so
whenever it detected null fontData, rather than try to continue.
Calling code would then immediately assert on this null fontData.

This patch refactors SVGTextRunRenderingContext::glyphDataForCharacter
so that it never returns null font data, adding an assertion to that
effect. In particular, when the font data is null the code will reach
the fallback glyph calculations.

Refactoring covered by existing tests. A previously crashing test, svg/custom/acid3-test-77.html, no longer crashes.

  • rendering/svg/SVGTextRunRenderingContext.cpp:

(WebCore::SVGTextRunRenderingContext::glyphDataForCharacter):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117786 r117788  
     12012-05-21  Stephen Chenney  <schenney@chromium.org>
     2
     3        SVGTextRunRenderingContext can return null font, calling code asserts not null
     4        https://bugs.webkit.org/show_bug.cgi?id=86738
     5
     6        Reviewed by Nikolas Zimmermann.
     7
     8        SVGTextRunRenderingContext::glyphDataForCharacter was returning a glyph with
     9        null font data for numerous code paths. It seems that it was doing so
     10        whenever it detected null fontData, rather than try to continue.
     11        Calling code would then immediately assert on this null fontData.
     12
     13        This patch refactors SVGTextRunRenderingContext::glyphDataForCharacter
     14        so that it never returns null font data, adding an assertion to that
     15        effect. In particular, when the font data is null the code will reach
     16        the fallback glyph calculations.
     17
     18        Refactoring covered by existing tests. A previously crashing test, svg/custom/acid3-test-77.html, no longer crashes.
     19
     20        * rendering/svg/SVGTextRunRenderingContext.cpp:
     21        (WebCore::SVGTextRunRenderingContext::glyphDataForCharacter):
     22
    1232012-05-21  Ilya Tikhonovsky  <loislo@chromium.org>
    224
  • trunk/Source/WebCore/rendering/svg/SVGTextRunRenderingContext.cpp

    r101517 r117788  
    180180    pair<GlyphData, GlyphPage*> pair = font.glyphDataAndPageForCharacter(character, mirror);
    181181    GlyphData glyphData = pair.first;
    182     if (!glyphData.fontData)
     182
     183    // Check if we have the missing glyph data, in which case we can just return.
     184    GlyphData missingGlyphData = primaryFont->missingGlyphData();
     185    if (glyphData.glyph == missingGlyphData.glyph && glyphData.fontData == missingGlyphData.fontData) {
     186        ASSERT(glyphData.fontData);
    183187        return glyphData;
    184 
    185     GlyphData missingGlyphData = primaryFont->missingGlyphData();
    186     if (glyphData.glyph == missingGlyphData.glyph && glyphData.fontData == missingGlyphData.fontData)
    187         return glyphData;
     188    }
    188189
    189190    // Characters enclosed by an <altGlyph> element, may not be registered in the GlyphPage.
    190     if (!glyphData.fontData->isSVGFont()) {
     191    if (glyphData.fontData && !glyphData.fontData->isSVGFont()) {
    191192        if (TextRun::RenderingContext* renderingContext = run.renderingContext()) {
    192193            RenderObject* renderObject = static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer();
     
    200201    }
    201202
    202     if (!glyphData.fontData || !glyphData.fontData->isSVGFont())
    203         return glyphData;
    204 
    205203    const SimpleFontData* fontData = glyphData.fontData;
    206 
    207     SVGFontElement* fontElement = 0;
    208     SVGFontFaceElement* fontFaceElement = 0;
    209 
    210     const SVGFontData* svgFontData = svgFontAndFontFaceElementForFontData(fontData, fontFaceElement, fontElement);
    211     if (!fontElement || !fontFaceElement)
    212         return glyphData;
    213 
    214     // If we got here, we're dealing with a glyph defined in a SVG Font.
    215     // The returned glyph by glyphDataAndPageForCharacter() is a glyph stored in the SVG Font glyph table.
    216     // This doesn't necessarily mean the glyph is suitable for rendering/measuring in this context, its
    217     // arabic-form/orientation/... may not match, we have to apply SVG Glyph selection to discover that.
    218     if (svgFontData->applySVGGlyphSelection(iterator, glyphData, mirror, currentCharacter, advanceLength))
    219         return glyphData;
     204    if (fontData) {
     205        if (!fontData->isSVGFont())
     206            return glyphData;
     207
     208        SVGFontElement* fontElement = 0;
     209        SVGFontFaceElement* fontFaceElement = 0;
     210
     211        const SVGFontData* svgFontData = svgFontAndFontFaceElementForFontData(fontData, fontFaceElement, fontElement);
     212        if (!fontElement || !fontFaceElement)
     213            return glyphData;
     214
     215        // If we got here, we're dealing with a glyph defined in a SVG Font.
     216        // The returned glyph by glyphDataAndPageForCharacter() is a glyph stored in the SVG Font glyph table.
     217        // This doesn't necessarily mean the glyph is suitable for rendering/measuring in this context, its
     218        // arabic-form/orientation/... may not match, we have to apply SVG Glyph selection to discover that.
     219        if (svgFontData->applySVGGlyphSelection(iterator, glyphData, mirror, currentCharacter, advanceLength))
     220            return glyphData;
     221    }
    220222
    221223    GlyphPage* page = pair.second;
     
    241243    fontList->setGlyphPageZero(originalGlyphPageZero);
    242244    fontList->setGlyphPages(originalGlyphPages);
     245    ASSERT(fallbackGlyphData.fontData);
    243246    return fallbackGlyphData;
    244247}
Note: See TracChangeset for help on using the changeset viewer.