diff options
Diffstat (limited to 'WebCore/platform/graphics/win/FontCacheWin.cpp')
-rw-r--r-- | WebCore/platform/graphics/win/FontCacheWin.cpp | 73 |
1 files changed, 57 insertions, 16 deletions
diff --git a/WebCore/platform/graphics/win/FontCacheWin.cpp b/WebCore/platform/graphics/win/FontCacheWin.cpp index 8869a90..d050243 100644 --- a/WebCore/platform/graphics/win/FontCacheWin.cpp +++ b/WebCore/platform/graphics/win/FontCacheWin.cpp @@ -301,22 +301,68 @@ SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font) return 0; } +static SimpleFontData* fontDataFromDescriptionAndLogFont(FontCache* fontCache, const FontDescription& fontDescription, const LOGFONT& font, AtomicString& outFontFamilyName) +{ + AtomicString familyName = String(font.lfFaceName, wcsnlen(font.lfFaceName, LF_FACESIZE)); + SimpleFontData* fontData = fontCache->getCachedFontData(fontDescription, familyName); + if (fontData) + outFontFamilyName = familyName; + return fontData; +} + SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription) { + DEFINE_STATIC_LOCAL(AtomicString, fallbackFontName, ()); + if (!fallbackFontName.isEmpty()) + return getCachedFontData(fontDescription, fallbackFontName); + // FIXME: Would be even better to somehow get the user's default font here. For now we'll pick // the default that the user would get without changing any prefs. - static AtomicString timesStr("Times New Roman"); - if (SimpleFontData* simpleFont = getCachedFontData(fontDescription, timesStr)) - return simpleFont; - DEFINE_STATIC_LOCAL(String, defaultGUIFontFamily, ()); - if (defaultGUIFontFamily.isEmpty()) { - HFONT defaultGUIFont = static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)); - LOGFONT logFont; - GetObject(defaultGUIFont, sizeof(logFont), &logFont); - defaultGUIFontFamily = String(logFont.lfFaceName, wcsnlen(logFont.lfFaceName, LF_FACESIZE)); + // Search all typical Windows-installed full Unicode fonts. + // Sorted by most to least glyphs according to http://en.wikipedia.org/wiki/Unicode_typefaces + // Start with Times New Roman also since it is the default if the user doesn't change prefs. + static AtomicString fallbackFonts[] = { + AtomicString("Times New Roman"), + AtomicString("Microsoft Sans Serif"), + AtomicString("Tahoma"), + AtomicString("Lucida Sans Unicode"), + AtomicString("Arial") + }; + SimpleFontData* simpleFont; + for (int i = 0; i < ARRAYSIZE(fallbackFonts); ++i) { + if (simpleFont = getCachedFontData(fontDescription, fallbackFonts[i])) { + fallbackFontName = fallbackFonts[i]; + return simpleFont; + } } - return getCachedFontData(fontDescription, defaultGUIFontFamily); + + // Fall back to the DEFAULT_GUI_FONT if no known Unicode fonts are available. + if (HFONT defaultGUIFont = static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT))) { + LOGFONT defaultGUILogFont; + GetObject(defaultGUIFont, sizeof(defaultGUILogFont), &defaultGUILogFont); + if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, defaultGUILogFont, fallbackFontName)) + return simpleFont; + } + + // Fall back to Non-client metrics fonts. + NONCLIENTMETRICS nonClientMetrics = {0}; + nonClientMetrics.cbSize = sizeof(nonClientMetrics); + if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(nonClientMetrics), &nonClientMetrics, 0)) { + if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfMessageFont, fallbackFontName)) + return simpleFont; + if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfMenuFont, fallbackFontName)) + return simpleFont; + if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfStatusFont, fallbackFontName)) + return simpleFont; + if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfCaptionFont, fallbackFontName)) + return simpleFont; + if (simpleFont = fontDataFromDescriptionAndLogFont(this, fontDescription, nonClientMetrics.lfSmCaptionFont, fallbackFontName)) + return simpleFont; + } + + ASSERT_NOT_REACHED(); + return 0; } static LONG toGDIFontWeight(FontWeight fontWeight) @@ -517,14 +563,9 @@ FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD // This masks rounding errors related to the HFONT metrics being different from the CGFont metrics. // FIXME: We will eventually want subpixel precision for GDI mode, but the scaled rendering doesn't // look as nice. That may be solvable though. -#if PLATFORM(CG) - bool canCreateCGFontWithLOGFONT = wkCanCreateCGFontWithLOGFONT(); -#else - bool canCreateCGFontWithLOGFONT = true; -#endif LONG weight = adjustedGDIFontWeight(toGDIFontWeight(fontDescription.weight()), family); HFONT hfont = createGDIFont(family, weight, fontDescription.italic(), - fontDescription.computedPixelSize() * (useGDI ? 1 : 32), useGDI && canCreateCGFontWithLOGFONT); + fontDescription.computedPixelSize() * (useGDI ? 1 : 32), useGDI); if (!hfont) return 0; |