Add static GetLogFontHeightAtPPI() overload taking point size
This will be useful elsewhere too and makes SetFractionalPointSize() implementation less fragile as we don't have to be careful about changing pointSize member before setting lf.lfHeight any more.
This commit is contained in:
@@ -122,7 +122,16 @@ public:
|
|||||||
|
|
||||||
// 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.
|
||||||
int GetLogFontHeightAtPPI(int ppi) const;
|
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;
|
||||||
|
|
||||||
|
@@ -509,32 +509,15 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return wxGetFontEncFromCharSet(lf.lfCharSet);
|
return wxGetFontEncFromCharSet(lf.lfCharSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetLogFontHeightAtPPI(int ppi) const
|
|
||||||
{
|
|
||||||
return -wxRound(pointSize * ppi / 72.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxNativeFontInfo::SetFractionalPointSize(float pointSizeNew)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointSizeNew)
|
||||||
{
|
{
|
||||||
if ( pointSize == 0.0f )
|
|
||||||
{
|
|
||||||
// Do this before calling GetLogFontHeightAtPPI() below.
|
|
||||||
pointSize = pointSizeNew;
|
|
||||||
|
|
||||||
// We don't have the correct DPI to use here, so use that of the
|
// We don't have the correct DPI to use here, so use that of the
|
||||||
// primary screen.
|
// primary screen.
|
||||||
const int ppi = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
const int ppi = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
||||||
lf.lfHeight = GetLogFontHeightAtPPI(ppi);
|
lf.lfHeight = GetLogFontHeightAtPPI(pointSizeNew, ppi);
|
||||||
}
|
|
||||||
else // Changing the size of a valid font.
|
|
||||||
{
|
|
||||||
// Scale the font using the ratio of sizes, to ensure that we use the
|
|
||||||
// same DPI as before.
|
|
||||||
lf.lfHeight = -wxRound(abs(lf.lfHeight) * pointSizeNew / pointSize);
|
|
||||||
|
|
||||||
pointSize = pointSizeNew;
|
pointSize = pointSizeNew;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
|
void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user