Changeset 57490 in webkit


Ignore:
Timestamp:
Apr 12, 2010 5:47:10 PM (14 years ago)
Author:
sfalken@apple.com
Message:

2010-04-12 Steve Falkenburg <sfalken@apple.com>

Reviewed by Dan Bernstein.

WebKit should have more robust last-chance font fallback on Windows
https://bugs.webkit.org/show_bug.cgi?id=37473
<rdar://problem/7789438> Crash in FontFallbackList::determinePitch
<rdar://problem/7233762> Crash in FontFallbackList::fontDataAt


Look harder for a suitable last-resort font. Previously, we checked for
"Times New Roman" followed by DEFAULT_GUI_FONT.


We now look for:

  • Typically installed Unicode-capable fonts, in order of coverage
  • DEFAULT_GUI_FONT
  • SPI_GETNONCLIENTMETRICS fonts


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

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r57482 r57490  
     12010-04-12  Steve Falkenburg  <sfalken@apple.com>
     2
     3        Reviewed by Dan Bernstein.
     4
     5        WebKit should have more robust last-chance font fallback on Windows
     6        https://bugs.webkit.org/show_bug.cgi?id=37473
     7        <rdar://problem/7789438> Crash in FontFallbackList::determinePitch
     8        <rdar://problem/7233762> Crash in FontFallbackList::fontDataAt
     9       
     10        Look harder for a suitable last-resort font. Previously, we checked for
     11        "Times New Roman" followed by DEFAULT_GUI_FONT.
     12       
     13        We now look for:
     14        - Typically installed Unicode-capable fonts, in order of coverage
     15        - DEFAULT_GUI_FONT
     16        - SPI_GETNONCLIENTMETRICS fonts
     17       
     18        * platform/graphics/win/FontCacheWin.cpp:
     19        (WebCore::FontCache::fontDataFromDescriptionAndLogFont):
     20        (WebCore::FontCache::getLastResortFallbackFont):
     21
    1222010-04-12  David Hyatt  <hyatt@apple.com>
    223
  • trunk/WebCore/platform/graphics/win/FontCacheWin.cpp

    r55975 r57490  
    302302}
    303303
     304static SimpleFontData* fontDataFromDescriptionAndLogFont(FontCache* fontCache, const FontDescription& fontDescription, const LOGFONT& font)
     305{
     306    String fontFamily = String(font.lfFaceName, wcsnlen(font.lfFaceName, LF_FACESIZE));
     307    return fontCache->getCachedFontData(fontDescription, fontFamily);
     308}
     309
    304310SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
    305311{
     312    DEFINE_STATIC_LOCAL(SimpleFontData*, simpleFont, ());
     313    if (simpleFont)
     314        return simpleFont;
     315
    306316    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
    307317    // the default that the user would get without changing any prefs.
    308     static AtomicString timesStr("Times New Roman");
    309     if (SimpleFontData* simpleFont = getCachedFontData(fontDescription, timesStr))
    310         return simpleFont;
    311 
    312     DEFINE_STATIC_LOCAL(String, defaultGUIFontFamily, ());
    313     if (defaultGUIFontFamily.isEmpty()) {
    314         HFONT defaultGUIFont = static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
    315         LOGFONT logFont;
    316         GetObject(defaultGUIFont, sizeof(logFont), &logFont);
    317         defaultGUIFontFamily = String(logFont.lfFaceName, wcsnlen(logFont.lfFaceName, LF_FACESIZE));
    318     }
    319     return getCachedFontData(fontDescription, defaultGUIFontFamily);
     318
     319    // Search all typical Windows-installed full Unicode fonts.
     320    // Sorted by most to least glyphs according to http://en.wikipedia.org/wiki/Unicode_typefaces
     321    // Start with Times New Roman also since it is the default if the user doesn't change prefs.
     322    static AtomicString fallbackFonts[] = {
     323        AtomicString("Times New Roman"),
     324        AtomicString("Microsoft Sans Serif"),
     325        AtomicString("Tahoma"),
     326        AtomicString("Lucida Sans Unicode"),
     327        AtomicString("Arial")
     328    };
     329    for (int i = 0; i < ARRAYSIZE(fallbackFonts); ++i) {
     330        if (simpleFont = getCachedFontData(fontDescription, fallbackFonts[i]))
     331            return simpleFont;
     332    }
     333
     334    // Fall back to the DEFAULT_GUI_FONT if no known Unicode fonts are available.
     335    if (HFONT defaultGUIFont = static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT))) {
     336        LOGFONT defaultGUILogFont;
     337        GetObject(defaultGUIFont, sizeof(defaultGUILogFont), &defaultGUILogFont);
     338        if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, defaultGUILogFont))
     339            return simpleFont;
     340    }
     341
     342    // Fall back to Non-client metrics fonts.
     343    NONCLIENTMETRICS nonClientMetrics = {0};
     344    nonClientMetrics.cbSize = sizeof(nonClientMetrics);
     345    if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(nonClientMetrics), &nonClientMetrics, 0)) {
     346        if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfMessageFont))
     347            return simpleFont;
     348        if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfMenuFont))
     349            return simpleFont;
     350        if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfStatusFont))
     351            return simpleFont;
     352        if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfCaptionFont))
     353            return simpleFont;
     354        if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfSmCaptionFont))
     355            return simpleFont;
     356    }
     357   
     358    ASSERT_NOT_REACHED();
     359    return 0;
    320360}
    321361
Note: See TracChangeset for help on using the changeset viewer.