Adjust the font size when DPI of window changes
This commit is contained in:
committed by
Maarten Bent
parent
e3d3a0b7e8
commit
e563d4858a
@@ -1726,6 +1726,8 @@ wxFont wxWindowBase::GetFont() const
|
||||
if ( !font.IsOk() )
|
||||
font = GetClassDefaultAttributes().font;
|
||||
|
||||
font.WXAdjustToPPI(GetDPI());
|
||||
|
||||
return font;
|
||||
}
|
||||
else
|
||||
@@ -1744,6 +1746,9 @@ bool wxWindowBase::SetFont(const wxFont& font)
|
||||
m_hasFont = font.IsOk();
|
||||
m_inheritFont = m_hasFont;
|
||||
|
||||
if ( m_hasFont )
|
||||
m_font.WXAdjustToPPI(GetDPI());
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
return true;
|
||||
|
||||
@@ -512,7 +512,8 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
||||
void wxNativeFontInfo::SetFractionalPointSize(float pointSizeNew)
|
||||
{
|
||||
// We don't have the correct DPI to use here, so use that of the
|
||||
// primary screen.
|
||||
// primary screen and rely on WXAdjustToPPI() changing it later if
|
||||
// necessary.
|
||||
const int ppi = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
||||
lf.lfHeight = GetLogFontHeightAtPPI(pointSizeNew, ppi);
|
||||
|
||||
@@ -899,6 +900,19 @@ void wxFont::SetPixelSize(const wxSize& pixelSize)
|
||||
M_FONTDATA->SetPixelSize(pixelSize);
|
||||
}
|
||||
|
||||
void wxFont::WXAdjustToPPI(const wxSize& ppi)
|
||||
{
|
||||
// We only use vertical component here as we only adjust LOGFONT::lfHeight.
|
||||
const int heightNew = M_FONTDATA->GetLogFontHeightAtPPI(ppi.y);
|
||||
|
||||
if ( heightNew != M_FONTDATA->GetLogFontHeight() )
|
||||
{
|
||||
AllocExclusive();
|
||||
|
||||
M_FONTDATA->SetLogFontHeight(heightNew);
|
||||
}
|
||||
}
|
||||
|
||||
void wxFont::SetFamily(wxFontFamily family)
|
||||
{
|
||||
AllocExclusive();
|
||||
|
||||
@@ -4837,6 +4837,17 @@ wxSize wxWindowMSW::GetDPI() const
|
||||
return dpi;
|
||||
}
|
||||
|
||||
void wxWindowMSW::MSWUpdateFontOnDPIChange(const wxSize& newDPI)
|
||||
{
|
||||
if ( m_font.IsOk() )
|
||||
{
|
||||
m_font.WXAdjustToPPI(newDPI);
|
||||
|
||||
// WXAdjustToPPI() changes the HFONT, so reassociate it with the window.
|
||||
wxSetWindowFont(GetHwnd(), m_font);
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to update the given coordinate by the scaling factor if it
|
||||
// is set, i.e. different from wxDefaultCoord.
|
||||
static void ScaleCoordIfSet(int& coord, float scaleFactor)
|
||||
@@ -4861,6 +4872,9 @@ wxWindowMSW::MSWUpdateOnDPIChange(const wxSize& oldDPI, const wxSize& newDPI)
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
// update font if necessary
|
||||
MSWUpdateFontOnDPIChange(newDPI);
|
||||
|
||||
// update children
|
||||
wxWindowList::compatibility_iterator current = GetChildren().GetFirst();
|
||||
while ( current )
|
||||
|
||||
Reference in New Issue
Block a user