Add function to get font pointSize from lfHeight at specific DPI
This commit is contained in:
@@ -120,25 +120,17 @@ public:
|
||||
#elif defined(__WXMSW__)
|
||||
wxNativeFontInfo(const LOGFONT& lf_)
|
||||
: lf(lf_),
|
||||
pointSize(GetPointSizeFromLogFontHeight(lf.lfHeight))
|
||||
pointSize(GetPointSizeAtPPI(lf.lfHeight))
|
||||
{
|
||||
}
|
||||
|
||||
// MSW-specific: get point size from LOGFONT height using the default DPI.
|
||||
static float GetPointSizeFromLogFontHeight(int height);
|
||||
// MSW-specific: get point size from LOGFONT height using specified DPI,
|
||||
// or screen DPI when 0.
|
||||
static float GetPointSizeAtPPI(int lfHeight, int ppi = 0);
|
||||
|
||||
// MSW-specific: get the height value in pixels using LOGFONT convention
|
||||
// (i.e. negative) corresponding to the given size in points and DPI.
|
||||
static int GetLogFontHeightAtPPI(float size, int ppi)
|
||||
{
|
||||
return -wxRound(size * ppi / 72.0);
|
||||
}
|
||||
|
||||
// And the same thing for the size of this font.
|
||||
int GetLogFontHeightAtPPI(int ppi) const
|
||||
{
|
||||
return GetLogFontHeightAtPPI(pointSize, ppi);
|
||||
}
|
||||
static int GetLogFontHeightAtPPI(float size, int ppi);
|
||||
|
||||
LOGFONT lf;
|
||||
|
||||
|
@@ -159,7 +159,8 @@ public:
|
||||
|
||||
int GetLogFontHeightAtPPI(int ppi) const
|
||||
{
|
||||
return m_nativeFontInfo.GetLogFontHeightAtPPI(ppi);
|
||||
return m_nativeFontInfo.GetLogFontHeightAtPPI(
|
||||
m_nativeFontInfo.pointSize, ppi);
|
||||
}
|
||||
|
||||
// ... and setters: notice that all of them invalidate the currently
|
||||
@@ -403,12 +404,18 @@ void wxFontRefData::Free()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/* static */
|
||||
float wxNativeFontInfo::GetPointSizeFromLogFontHeight(int height)
|
||||
float wxNativeFontInfo::GetPointSizeAtPPI(int lfHeight, int ppi)
|
||||
{
|
||||
// Determine the size in points using the primary screen DPI as we don't
|
||||
// have anything else here.
|
||||
const float ppi = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
||||
return 72.0f * abs(height) / ppi;
|
||||
if ( ppi == 0 )
|
||||
ppi = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
||||
|
||||
return abs(lfHeight) * 72.0f / ppi;
|
||||
}
|
||||
|
||||
/* static */
|
||||
int wxNativeFontInfo::GetLogFontHeightAtPPI(float size, int ppi)
|
||||
{
|
||||
return -wxRound(size * ppi / 72.0f);
|
||||
}
|
||||
|
||||
void wxNativeFontInfo::Init()
|
||||
@@ -536,7 +543,7 @@ void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
|
||||
|
||||
// We don't have the right DPI to use here neither, but we need to update
|
||||
// the point size too, so fall back to the default.
|
||||
pointSize = GetPointSizeFromLogFontHeight(lf.lfHeight);
|
||||
pointSize = GetPointSizeAtPPI(lf.lfHeight);
|
||||
}
|
||||
|
||||
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
||||
@@ -699,7 +706,7 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
||||
return false;
|
||||
lf.lfHeight = l;
|
||||
if ( setPointSizeFromHeight )
|
||||
pointSize = GetPointSizeFromLogFontHeight(l);
|
||||
pointSize = GetPointSizeAtPPI(l);
|
||||
|
||||
token = tokenizer.GetNextToken();
|
||||
if ( !token.ToLong(&l) )
|
||||
|
Reference in New Issue
Block a user