Changeset 73116 in webkit


Ignore:
Timestamp:
Dec 2, 2010 1:54:24 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2010-12-02 Hironori Bono <hbono@chromium.org>

Reviewed by Darin Fisher.

[Chromium] Fix possible crashes in FontFallbackFont::determinePitch().
https://bugs.webkit.org/show_bug.cgi?id=25770

When all of "Arial", "Courier New", and "Times New Roman" fonts are corrupted,
FontCache::getLastResortFallbackFont() returns 0 and it causes this crash. To
avoid this crash, this change falls back to system fonts (Windows ensures they
are sane) as Win Safari does. Unfortunately, I don't have any ideas how I can
write a layout test for this issue because this crash happens on a PC some of
its system fonts are corrupted.

  • platform/graphics/chromium/FontCacheChromiumWin.cpp: (WebCore::fontDataFromDescriptionAndLogFont): (WebCore::FontCache::getLastResortFallbackFont):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r73114 r73116  
     12010-12-02  Hironori Bono  <hbono@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        [Chromium] Fix possible crashes in FontFallbackFont::determinePitch().
     6        https://bugs.webkit.org/show_bug.cgi?id=25770
     7
     8        When all of "Arial", "Courier New", and "Times New Roman" fonts are corrupted,
     9        FontCache::getLastResortFallbackFont() returns 0 and it causes this crash. To
     10        avoid this crash, this change falls back to system fonts (Windows ensures they
     11        are sane) as Win Safari does. Unfortunately, I don't have any ideas how I can
     12        write a layout test for this issue because this crash happens on a PC some of
     13        its system fonts are corrupted.
     14
     15        * platform/graphics/chromium/FontCacheChromiumWin.cpp:
     16        (WebCore::fontDataFromDescriptionAndLogFont):
     17        (WebCore::FontCache::getLastResortFallbackFont):
     18
    1192010-12-02  Dimitri Glazkov  <dglazkov@chromium.org>
    220
  • trunk/WebCore/platform/graphics/chromium/FontCacheChromiumWin.cpp

    r72498 r73116  
    422422}
    423423
     424// Tries the given font and save it |outFontFamilyName| if it succeeds.
     425static SimpleFontData* fontDataFromDescriptionAndLogFont(FontCache* fontCache, const FontDescription& fontDescription, const LOGFONT& font, wchar_t* outFontFamilyName)
     426{
     427    SimpleFontData* fontData = fontCache->getCachedFontData(fontDescription, font.lfFaceName);
     428    if (fontData)
     429        memcpy(outFontFamilyName, font.lfFaceName, sizeof(font.lfFaceName));
     430    return fontData;
     431}
     432
    424433SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& description)
    425434{
     
    439448        fontStr = courierStr;
    440449
    441     return getCachedFontData(description, fontStr);
     450    SimpleFontData* simpleFont = getCachedFontData(description, fontStr);
     451    if (simpleFont)
     452        return simpleFont;
     453
     454    // Fall back to system fonts as Win Safari does because this function must
     455    // return a valid font. Once we find a valid system font, we save its name
     456    // to a static variable and use it to prevent trying system fonts again.
     457    static wchar_t fallbackFontName[LF_FACESIZE] = {0};
     458    if (fallbackFontName[0])
     459        return getCachedFontData(description, fallbackFontName);
     460
     461    // Fall back to the DEFAULT_GUI_FONT if no known Unicode fonts are available.
     462    if (HFONT defaultGUIFont = static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT))) {
     463        LOGFONT defaultGUILogFont;
     464        GetObject(defaultGUIFont, sizeof(defaultGUILogFont), &defaultGUILogFont);
     465        if (simpleFont = fontDataFromDescriptionAndLogFont(this, description, defaultGUILogFont, fallbackFontName))
     466            return simpleFont;
     467    }
     468
     469    // Fall back to Non-client metrics fonts.
     470    NONCLIENTMETRICS nonClientMetrics = {0};
     471    nonClientMetrics.cbSize = sizeof(nonClientMetrics);
     472    if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(nonClientMetrics), &nonClientMetrics, 0)) {
     473        if (simpleFont = fontDataFromDescriptionAndLogFont(this, description, nonClientMetrics.lfMessageFont, fallbackFontName))
     474            return simpleFont;
     475        if (simpleFont = fontDataFromDescriptionAndLogFont(this, description, nonClientMetrics.lfMenuFont, fallbackFontName))
     476            return simpleFont;
     477        if (simpleFont = fontDataFromDescriptionAndLogFont(this, description, nonClientMetrics.lfStatusFont, fallbackFontName))
     478            return simpleFont;
     479        if (simpleFont = fontDataFromDescriptionAndLogFont(this, description, nonClientMetrics.lfCaptionFont, fallbackFontName))
     480            return simpleFont;
     481        if (simpleFont = fontDataFromDescriptionAndLogFont(this, description, nonClientMetrics.lfSmCaptionFont, fallbackFontName))
     482            return simpleFont;
     483    }
     484
     485    ASSERT_NOT_REACHED();
     486    return 0;
    442487}
    443488
Note: See TracChangeset for help on using the changeset viewer.