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