Require wxWindow parameter for wxNativeFontInfo constructor in MSW
Use the DPI of the window to determine the correct font pointSize. To not break user code, add a default argument when not building the library.
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#endif
|
||||
|
||||
class WXDLLIMPEXP_FWD_BASE wxArrayString;
|
||||
class WXDLLIMPEXP_FWD_CORE wxWindow;
|
||||
struct WXDLLIMPEXP_FWD_CORE wxNativeEncodingInfo;
|
||||
|
||||
#if defined(_WX_X_FONTLIKE)
|
||||
@@ -118,11 +119,16 @@ public:
|
||||
// set the XFLD
|
||||
void SetXFontName(const wxString& xFontName);
|
||||
#elif defined(__WXMSW__)
|
||||
wxNativeFontInfo(const LOGFONT& lf_)
|
||||
: lf(lf_),
|
||||
pointSize(GetPointSizeAtPPI(lf.lfHeight))
|
||||
{
|
||||
}
|
||||
// Preserve compatibility in the semi-public (i.e. private, but still
|
||||
// unfortunately used by some existing code outside of the library) API
|
||||
// by allowing to create wxNativeFontInfo from just LOGFONT, but ensure
|
||||
// that we always specify the window, to use the correct DPI, when creating
|
||||
// fonts inside the library itself.
|
||||
wxNativeFontInfo(const LOGFONT& lf_, const wxWindow* win
|
||||
#ifndef WXBUILDING
|
||||
= NULL
|
||||
#endif
|
||||
);
|
||||
|
||||
// MSW-specific: get point size from LOGFONT height using specified DPI,
|
||||
// or screen DPI when 0.
|
||||
|
@@ -403,6 +403,11 @@ void wxFontRefData::Free()
|
||||
// wxNativeFontInfo
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxNativeFontInfo::wxNativeFontInfo(const LOGFONT& lf_, const wxWindow* win)
|
||||
: lf(lf_),
|
||||
pointSize(GetPointSizeAtPPI(lf.lfHeight, win ? win->GetDPI().y : 0))
|
||||
{ }
|
||||
|
||||
/* static */
|
||||
float wxNativeFontInfo::GetPointSizeAtPPI(int lfHeight, int ppi)
|
||||
{
|
||||
|
@@ -152,7 +152,7 @@ int wxFontDialog::ShowModal()
|
||||
if ( ChooseFont(&chooseFontStruct) != 0 )
|
||||
{
|
||||
wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors);
|
||||
m_fontData.m_chosenFont = wxFont(wxNativeFontInfo(logFont));
|
||||
m_fontData.m_chosenFont = wxFont(wxNativeFontInfo(logFont, this));
|
||||
m_fontData.EncodingInfo().facename = logFont.lfFaceName;
|
||||
m_fontData.EncodingInfo().charset = logFont.lfCharSet;
|
||||
|
||||
|
@@ -278,7 +278,7 @@ void wxFillLogFont(LOGFONT *logFont, const wxFont *font)
|
||||
|
||||
wxFont wxCreateFontFromLogFont(const LOGFONT *logFont)
|
||||
{
|
||||
return wxFont(wxNativeFontInfo(*logFont));
|
||||
return wxFont(wxNativeFontInfo(*logFont, NULL));
|
||||
}
|
||||
|
||||
#endif // WXWIN_COMPATIBILITY_3_0
|
||||
|
@@ -348,7 +348,7 @@ void MenuDrawData::Init()
|
||||
|
||||
wxUxThemeFont themeFont;
|
||||
::GetThemeSysFont(hTheme, TMT_MENUFONT, themeFont.GetPtr());
|
||||
Font = wxFont(themeFont.GetLOGFONT());
|
||||
Font = wxFont(wxNativeFontInfo(themeFont.GetLOGFONT(), window));
|
||||
|
||||
Theme = true;
|
||||
|
||||
@@ -392,15 +392,7 @@ void MenuDrawData::Init()
|
||||
|
||||
Offset = -12;
|
||||
|
||||
wxNativeFontInfo info(metrics.lfMenuFont);
|
||||
// wxNativeFontInfo constructor calculates the pointSize using the
|
||||
// main screen DPI. But lfHeight is based on the window DPI.
|
||||
if ( window )
|
||||
{
|
||||
info.pointSize = wxNativeFontInfo::GetPointSizeAtPPI(
|
||||
info.lf.lfHeight, window->GetDPI().y);
|
||||
}
|
||||
Font = wxFont(info);
|
||||
Font = wxFont(wxNativeFontInfo(metrics.lfMenuFont, window));
|
||||
|
||||
Theme = false;
|
||||
}
|
||||
|
@@ -397,15 +397,8 @@ void wxMessageDialog::AdjustButtonLabels()
|
||||
wxFont wxMessageDialog::GetMessageFont()
|
||||
{
|
||||
const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
|
||||
wxNativeFontInfo info(wxMSWImpl::GetNonClientMetrics(win).lfMessageFont);
|
||||
|
||||
// wxNativeFontInfo constructor calculates the pointSize using the
|
||||
// main screen DPI. But lfHeight is based on the window DPI.
|
||||
if ( win )
|
||||
{
|
||||
info.pointSize = wxNativeFontInfo::GetPointSizeAtPPI(
|
||||
info.lf.lfHeight, win->GetDPI().y);
|
||||
}
|
||||
const wxNativeFontInfo
|
||||
info(wxMSWImpl::GetNonClientMetrics(win).lfMessageFont, win);
|
||||
|
||||
return info;
|
||||
}
|
||||
|
@@ -150,7 +150,7 @@ wxFont wxCreateFontFromStockObject(int index)
|
||||
LOGFONT lf;
|
||||
if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
|
||||
{
|
||||
wxNativeFontInfo info(lf);
|
||||
wxNativeFontInfo info(lf, NULL);
|
||||
font.Create(info);
|
||||
}
|
||||
else
|
||||
@@ -183,16 +183,8 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
|
||||
// controls may prefer to use lfStatusFont or lfCaptionFont if it
|
||||
// is more appropriate for them
|
||||
const wxWindow* win = wxTheApp ? wxTheApp->GetTopWindow() : NULL;
|
||||
wxNativeFontInfo
|
||||
info(wxMSWImpl::GetNonClientMetrics(win).lfMessageFont);
|
||||
|
||||
// wxNativeFontInfo constructor calculates the pointSize using the
|
||||
// main screen DPI. But lfHeight is based on the window DPI.
|
||||
if ( win )
|
||||
{
|
||||
info.pointSize = wxNativeFontInfo::GetPointSizeAtPPI(
|
||||
info.lf.lfHeight, win->GetDPI().y);
|
||||
}
|
||||
const wxNativeFontInfo
|
||||
info(wxMSWImpl::GetNonClientMetrics(win).lfMessageFont, win);
|
||||
|
||||
gs_fontDefault = new wxFont(info);
|
||||
}
|
||||
@@ -358,7 +350,7 @@ extern wxFont wxGetCCDefaultFont()
|
||||
win
|
||||
) )
|
||||
{
|
||||
return wxFont(lf);
|
||||
return wxFont(wxNativeFontInfo(lf, win));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -3207,7 +3207,8 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
|
||||
// CHARFORMAT stores it to pixel-based units used by LOGFONT.
|
||||
// Note that RichEdit seems to always use standard DPI of 96, even when the
|
||||
// window is a monitor using a higher DPI.
|
||||
lf.lfHeight = wxNativeFontInfo::GetLogFontHeightAtPPI(cf.yHeight/20.0f, 96);
|
||||
lf.lfHeight = wxNativeFontInfo::GetLogFontHeightAtPPI(cf.yHeight/20.0f,
|
||||
GetDPI().y);
|
||||
lf.lfWidth = 0;
|
||||
lf.lfCharSet = ANSI_CHARSET; // FIXME: how to get correct charset?
|
||||
lf.lfClipPrecision = 0;
|
||||
@@ -3240,7 +3241,7 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style)
|
||||
else
|
||||
lf.lfWeight = FW_NORMAL;
|
||||
|
||||
wxFont font(lf);
|
||||
wxFont font(wxNativeFontInfo(lf, this));
|
||||
if (font.IsOk())
|
||||
{
|
||||
style.SetFont(font);
|
||||
|
Reference in New Issue
Block a user