diff --git a/gfx/thebes/gfxDWriteFontList.cpp b/gfx/thebes/gfxDWriteFontList.cpp index 8484d876247..e47c3e7f553 100644 --- a/gfx/thebes/gfxDWriteFontList.cpp +++ b/gfx/thebes/gfxDWriteFontList.cpp @@ -891,6 +891,13 @@ gfxDWriteFontList::DelayedInitFontList() mOtherFamilyNamesInitialized = PR_TRUE; GetFontSubstitutes(); + // bug 642093 - DirectWrite does not support old bitmap (.fon) + // font files, but a few of these such as "Courier" and "MS Sans Serif" + // are frequently specified in shoddy CSS, without appropriate fallbacks. + // By mapping these to TrueType equivalents, we provide better consistency + // with both pre-DW systems and with IE9, which appears to do the same. + GetDirectWriteSubstitutes(); + // bug 551313 - DirectWrite creates a Gill Sans family out of // poorly named members of the Gill Sans MT family containing // only Ultra Bold weights. This causes big problems for pages @@ -1035,6 +1042,43 @@ gfxDWriteFontList::GetFontSubstitutes() return NS_OK; } +struct FontSubstitution { + const WCHAR* aliasName; + const WCHAR* actualName; +}; + +static const FontSubstitution sDirectWriteSubs[] = { + { L"MS Sans Serif", L"Microsoft Sans Serif" }, + { L"MS Serif", L"Times New Roman" }, + { L"Courier", L"Courier New" }, + { L"Small Fonts", L"Arial" }, + { L"Roman", L"Times New Roman" }, + { L"Script", L"Mistral" } +}; + +void +gfxDWriteFontList::GetDirectWriteSubstitutes() +{ + for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(sDirectWriteSubs); ++i) { + const FontSubstitution& sub(sDirectWriteSubs[i]); + nsAutoString substituteName((PRUnichar*)sub.aliasName); + BuildKeyNameFromFontName(substituteName); + if (nsnull != mFontFamilies.GetWeak(substituteName)) { + // don't do the substitution if user actually has a usable font + // with this name installed + continue; + } + nsAutoString actualFontName((PRUnichar*)sub.actualName); + BuildKeyNameFromFontName(actualFontName); + gfxFontFamily *ff; + if (nsnull != (ff = mFontFamilies.GetWeak(actualFontName))) { + mFontSubstitutes.Put(substituteName, ff); + } else { + mNonExistingFonts.AppendElement(substituteName); + } + } +} + PRBool gfxDWriteFontList::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) diff --git a/gfx/thebes/gfxDWriteFontList.h b/gfx/thebes/gfxDWriteFontList.h index ad2ae5362c8..fa9cb0609ac 100644 --- a/gfx/thebes/gfxDWriteFontList.h +++ b/gfx/thebes/gfxDWriteFontList.h @@ -230,6 +230,8 @@ private: nsresult GetFontSubstitutes(); + void GetDirectWriteSubstitutes(); + /** * Fonts listed in the registry as substitutes but for which no actual * font family is found.