From 13082752571d7eb32339aab8e884b72141db334f Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Thu, 22 Jan 2015 22:52:26 +0000 Subject: [PATCH] Bug 1123654 - Replace use of [deprecated] GetStockObject(DEFAULT_GUI_FONT) with newer API; results in use of Tahoma in place of Microsoft Sans Serif in various contexts. r=jimm --- gfx/thebes/gfxGDIFontList.cpp | 20 +++---- layout/reftests/bugs/reftest.list | 4 +- .../reftests/forms/placeholder/reftest.list | 2 +- widget/windows/nsLookAndFeel.cpp | 60 ++++++++----------- 4 files changed, 39 insertions(+), 47 deletions(-) diff --git a/gfx/thebes/gfxGDIFontList.cpp b/gfx/thebes/gfxGDIFontList.cpp index cce880b4501..6550ba7718a 100644 --- a/gfx/thebes/gfxGDIFontList.cpp +++ b/gfx/thebes/gfxGDIFontList.cpp @@ -860,22 +860,22 @@ gfxGDIFontList::GetDefaultFont(const gfxFontStyle* aStyle) gfxFontFamily *ff = nullptr; // this really shouldn't fail to find a font.... - HGDIOBJ hGDI = ::GetStockObject(DEFAULT_GUI_FONT); - LOGFONTW logFont; - if (hGDI && ::GetObjectW(hGDI, sizeof(logFont), &logFont)) { - ff = FindFamily(nsDependentString(logFont.lfFaceName)); - if (ff) { - return ff; - } - } - - // ...but just in case, try another approach as well NONCLIENTMETRICSW ncm; ncm.cbSize = sizeof(ncm); BOOL status = ::SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0); if (status) { ff = FindFamily(nsDependentString(ncm.lfMessageFont.lfFaceName)); + if (ff) { + return ff; + } + } + + // ...but just in case, try another (long-deprecated) approach as well + HGDIOBJ hGDI = ::GetStockObject(DEFAULT_GUI_FONT); + LOGFONTW logFont; + if (hGDI && ::GetObjectW(hGDI, sizeof(logFont), &logFont)) { + ff = FindFamily(nsDependentString(logFont.lfFaceName)); } return ff; diff --git a/layout/reftests/bugs/reftest.list b/layout/reftests/bugs/reftest.list index 0063aa16d5f..a3d96a56c94 100644 --- a/layout/reftests/bugs/reftest.list +++ b/layout/reftests/bugs/reftest.list @@ -557,9 +557,9 @@ skip-if(B2G) == 363858-1.html 363858-1-ref.html skip-if(B2G) == 363858-2.html 363858-2-ref.html skip-if(B2G) == 363858-3.html 363858-3-ref.html skip-if(B2G) == 363858-4.html 363858-4-ref.html -fuzzy-if(OSX>=1008,45,2) == 363858-5a.html 363858-5-ref.html +fuzzy-if(OSX>=1008,45,2) fuzzy-if(winWidget,37,1) == 363858-5a.html 363858-5-ref.html == 363858-5b.html 363858-5-ref.html -fuzzy-if(OSX>=1008,45,2) == 363858-6a.html 363858-6-ref.html +fuzzy-if(OSX>=1008,45,2) fuzzy-if(winWidget,37,1) == 363858-6a.html 363858-6-ref.html == 363858-6b.html 363858-6-ref.html == 363874.html 363874-ref.html == 363874-max-width.html 363874-max-width-ref.html diff --git a/layout/reftests/forms/placeholder/reftest.list b/layout/reftests/forms/placeholder/reftest.list index 75100696095..b86773c8f81 100644 --- a/layout/reftests/forms/placeholder/reftest.list +++ b/layout/reftests/forms/placeholder/reftest.list @@ -16,7 +16,7 @@ == placeholder-3.html placeholder-overridden-ref.html == placeholder-4.html placeholder-overridden-ref.html == placeholder-5.html placeholder-visible-ref.html -fuzzy-if(winWidget,160,6) == placeholder-6.html placeholder-overflow-ref.html +fuzzy-if(winWidget,160,7) == placeholder-6.html placeholder-overflow-ref.html skip-if(B2G) == placeholder-6-textarea.html placeholder-overflow-textarea-ref.html # needs-focus == placeholder-7.html placeholder-focus-ref.html # needs-focus == placeholder-8.html placeholder-focus-ref.html diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index 1b7d7fc7233..d56369fdf3b 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -535,10 +535,10 @@ GetSysFontInfo(HDC aHDC, LookAndFeel::FontID anID, LOGFONTW* ptrLogFont = nullptr; LOGFONTW logFont; NONCLIENTMETRICSW ncm; - HGDIOBJ hGDI; char16_t name[LF_FACESIZE]; + bool useShellDlg = false; - // Depending on which stock font we want, there are three different + // Depending on which stock font we want, there are a couple of // places we might have to look it up. switch (anID) { case LookAndFeel::eFont_Icon: @@ -549,11 +549,7 @@ GetSysFontInfo(HDC aHDC, LookAndFeel::FontID anID, ptrLogFont = &logFont; break; - case LookAndFeel::eFont_Menu: - case LookAndFeel::eFont_MessageBox: - case LookAndFeel::eFont_SmallCaption: - case LookAndFeel::eFont_StatusBar: - case LookAndFeel::eFont_Tooltips: + default: ncm.cbSize = sizeof(NONCLIENTMETRICSW); if (!::SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(ncm), (PVOID)&ncm, 0)) @@ -561,10 +557,11 @@ GetSysFontInfo(HDC aHDC, LookAndFeel::FontID anID, switch (anID) { case LookAndFeel::eFont_Menu: + case LookAndFeel::eFont_PullDownMenu: ptrLogFont = &ncm.lfMenuFont; break; - case LookAndFeel::eFont_MessageBox: - ptrLogFont = &ncm.lfMessageFont; + case LookAndFeel::eFont_Caption: + ptrLogFont = &ncm.lfCaptionFont; break; case LookAndFeel::eFont_SmallCaption: ptrLogFont = &ncm.lfSmCaptionFont; @@ -573,30 +570,22 @@ GetSysFontInfo(HDC aHDC, LookAndFeel::FontID anID, case LookAndFeel::eFont_Tooltips: ptrLogFont = &ncm.lfStatusFont; break; + case LookAndFeel::eFont_Widget: + case LookAndFeel::eFont_Dialog: + case LookAndFeel::eFont_Button: + // XXX It's not clear to me whether this is exactly the right + // set of LookAndFeel values to map to the dialog font; we may + // want to add or remove cases here after reviewing the visual + // results under various Windows versions. + useShellDlg = true; + // Fall through so that we can get size from lfMessageFont; + // but later we'll use the (virtual) "MS Shell Dlg 2" font name + // instead of the LOGFONT's. + default: + ptrLogFont = &ncm.lfMessageFont; + break; } break; - - case LookAndFeel::eFont_Widget: - case LookAndFeel::eFont_Window: // css3 - case LookAndFeel::eFont_Document: - case LookAndFeel::eFont_Workspace: - case LookAndFeel::eFont_Desktop: - case LookAndFeel::eFont_Info: - case LookAndFeel::eFont_Dialog: - case LookAndFeel::eFont_Button: - case LookAndFeel::eFont_PullDownMenu: - case LookAndFeel::eFont_List: - case LookAndFeel::eFont_Field: - case LookAndFeel::eFont_Caption: - hGDI = ::GetStockObject(DEFAULT_GUI_FONT); - if (!hGDI) - return false; - - if (::GetObjectW(hGDI, sizeof(logFont), &logFont) <= 0) - return false; - - ptrLogFont = &logFont; - break; } // Get scaling factor from physical to logical pixels @@ -649,9 +638,12 @@ GetSysFontInfo(HDC aHDC, LookAndFeel::FontID anID, aFontStyle.systemFont = true; - name[0] = 0; - memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*sizeof(char16_t)); - aFontName = name; + if (useShellDlg) { + aFontName = NS_LITERAL_STRING("MS Shell Dlg 2"); + } else { + memcpy(name, ptrLogFont->lfFaceName, LF_FACESIZE*sizeof(char16_t)); + aFontName = name; + } return true; }