code clean up, avoid duplicating the same code in font.cpp and fontutil.cpp

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13176 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-12-24 01:06:15 +00:00
parent bff67a6a81
commit 7936354da7
4 changed files with 91 additions and 133 deletions

View File

@@ -366,6 +366,8 @@ void wxNativeFontInfo::Init()
int wxNativeFontInfo::GetPointSize() const
{
// FIXME: using the screen here results in incorrect font size calculation
// for printing!
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
return (int) (((72.0*(double)abs(lf.lfHeight)) / (double) ppInch) + 0.5);
@@ -404,9 +406,16 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
void wxNativeFontInfo::SetPointSize(int pointsize)
{
#if wxFONT_SIZE_COMPATIBILITY
// Incorrect, but compatible with old wxWindows behaviour
lf.lfHeight = (pointSize*ppInch)/72;
#else // wxFONT_SIZE_COMPATIBILITY
// FIXME: using the screen here results in incorrect font size calculation
// for printing!
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
lf.lfHeight = -(int)((pointsize*((double)ppInch)/72.0) + 0.5);
#endif // wxFONT_SIZE_COMPATIBILITY/!wxFONT_SIZE_COMPATIBILITY
}
void wxNativeFontInfo::SetStyle(wxFontStyle style)
@@ -459,6 +468,53 @@ void wxNativeFontInfo::SetFaceName(wxString facename)
wxStrncpy(lf.lfFaceName, facename, sizeof(lf.lfFaceName));
}
void wxNativeFontInfo::SetFamily(wxFontFamily family)
{
int ff_family;
wxString facename;
switch ( family )
{
case wxSCRIPT:
ff_family = FF_SCRIPT;
facename = _T("Script");
break;
case wxDECORATIVE:
ff_family = FF_DECORATIVE;
facename = _T("Wingdings");
break;
case wxROMAN:
ff_family = FF_ROMAN;
facename = _T("Times New Roman");
break;
case wxTELETYPE:
case wxMODERN:
ff_family = FF_MODERN;
facename = _T("Courier New");
break;
case wxSWISS:
ff_family = FF_SWISS;
facename = _T("Arial");
break;
case wxDEFAULT:
default:
ff_family = FF_SWISS;
facename = _T("MS Sans Serif");
}
lf.lfPitchAndFamily = DEFAULT_PITCH | ff_family;
if ( !wxStrlen(lf.lfFaceName) )
{
SetFaceName(facename);
}
}
void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding)
{
wxNativeEncodingInfo info;