+ return lf.lfFaceName;
+}
+
+wxFontFamily wxNativeFontInfo::GetFamily() const
+{
+ wxFontFamily family;
+
+ // extract family from pitch-and-family
+ switch ( lf.lfPitchAndFamily & ~PITCH_MASK )
+ {
+ case FF_ROMAN:
+ family = wxFONTFAMILY_ROMAN;
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unknown LOGFONT::lfFamily value") );
+ // fall through
+
+ case FF_SWISS:
+ family = wxFONTFAMILY_SWISS;
+ break;
+
+ case FF_SCRIPT:
+ family = wxFONTFAMILY_SCRIPT;
+ break;
+
+ case FF_MODERN:
+ family = wxFONTFAMILY_MODERN;
+ break;
+
+ case FF_DECORATIVE:
+ family = wxFONTFAMILY_DECORATIVE;
+ break;
+ }
+
+ return family;
+}
+
+wxFontEncoding wxNativeFontInfo::GetEncoding() const
+{
+ return wxGetFontEncFromCharSet(lf.lfCharSet);
+}
+
+void wxNativeFontInfo::SetPointSize(int pointsize)
+{
+ // 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);
+}
+
+void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
+{
+ lf.lfHeight = pixelSize.GetHeight();
+ lf.lfWidth = pixelSize.GetWidth();
+}
+
+
+void wxNativeFontInfo::SetStyle(wxFontStyle style)
+{
+ switch ( style )
+ {
+ default:
+ wxFAIL_MSG( _T("unknown font style") );
+ // fall through
+
+ case wxFONTSTYLE_NORMAL:
+ lf.lfItalic = FALSE;
+ break;
+
+ case wxFONTSTYLE_ITALIC:
+ case wxFONTSTYLE_SLANT:
+ lf.lfItalic = TRUE;
+ break;
+ }
+}
+
+void wxNativeFontInfo::SetWeight(wxFontWeight weight)
+{
+ switch ( weight )
+ {
+ default:
+ wxFAIL_MSG( _T("unknown font weight") );
+ // fall through
+
+ case wxFONTWEIGHT_NORMAL:
+ lf.lfWeight = FW_NORMAL;
+ break;
+
+ case wxFONTWEIGHT_LIGHT:
+ lf.lfWeight = FW_LIGHT;
+ break;
+
+ case wxFONTWEIGHT_BOLD:
+ lf.lfWeight = FW_BOLD;
+ break;
+ }
+}
+
+void wxNativeFontInfo::SetUnderlined(bool underlined)
+{
+ lf.lfUnderline = underlined;
+}
+
+void wxNativeFontInfo::SetFaceName(const wxString& facename)
+{
+ wxStrncpy(lf.lfFaceName, facename, WXSIZEOF(lf.lfFaceName));
+}
+
+void wxNativeFontInfo::SetFamily(wxFontFamily family)
+{
+ BYTE ff_family;
+ wxString facename;
+
+ switch ( family )
+ {
+ case wxSCRIPT:
+ ff_family = FF_SCRIPT;
+ facename = _T("Script");
+ break;
+
+ case wxDECORATIVE:
+ ff_family = FF_DECORATIVE;
+ facename = _T("Old English Text MT");
+ 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:
+ {
+ // We want Windows 2000 or later to have new fonts even MS Shell Dlg
+ // is returned as default GUI font for compatibility
+ int verMaj;
+ ff_family = FF_SWISS;
+ if(wxGetOsVersion(&verMaj) == wxWINDOWS_NT && verMaj >= 5)
+ facename = _T("MS Shell Dlg 2");
+ else
+ facename = _T("MS Shell Dlg");
+ }
+ }
+
+ lf.lfPitchAndFamily = (BYTE)(DEFAULT_PITCH) | ff_family;
+
+ if ( !wxStrlen(lf.lfFaceName) )
+ {
+ SetFaceName(facename);
+ }
+}
+
+void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding)
+{
+ wxNativeEncodingInfo info;
+ if ( !wxGetNativeFontEncoding(encoding, &info) )
+ {
+#if wxUSE_FONTMAP
+ if ( wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
+ {
+ if ( !info.facename.empty() )
+ {
+ // if we have this encoding only in some particular facename, use
+ // the facename - it is better to show the correct characters in a
+ // wrong facename than unreadable text in a correct one
+ SetFaceName(info.facename);
+ }
+ }
+ else
+#endif // wxUSE_FONTMAP
+ {
+ // unsupported encoding, replace with the default
+ info.charset = DEFAULT_CHARSET;
+ }
+ }
+
+ lf.lfCharSet = (BYTE)info.charset;
+}
+
+bool wxNativeFontInfo::FromString(const wxString& s)
+{
+ long l;
+
+ wxStringTokenizer tokenizer(s, _T(";"));
+
+ // first the version
+ wxString token = tokenizer.GetNextToken();
+ if ( token != _T('0') )
+ return false;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfHeight = l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfWidth = l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfEscapement = l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfOrientation = l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfWeight = l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfItalic = (BYTE)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfUnderline = (BYTE)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfStrikeOut = (BYTE)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfCharSet = (BYTE)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfOutPrecision = (BYTE)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfClipPrecision = (BYTE)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfQuality = (BYTE)l;
+
+ token = tokenizer.GetNextToken();
+ if ( !token.ToLong(&l) )
+ return false;
+ lf.lfPitchAndFamily = (BYTE)l;
+
+ token = tokenizer.GetNextToken();
+ if(!token)
+ return false;
+ wxStrcpy(lf.lfFaceName, token.c_str());
+
+ return true;
+}
+
+wxString wxNativeFontInfo::ToString() const
+{
+ wxString s;
+
+ s.Printf(_T("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
+ 0, // version, in case we want to change the format later
+ lf.lfHeight,
+ lf.lfWidth,
+ lf.lfEscapement,
+ lf.lfOrientation,
+ lf.lfWeight,
+ lf.lfItalic,
+ lf.lfUnderline,
+ lf.lfStrikeOut,
+ lf.lfCharSet,
+ lf.lfOutPrecision,
+ lf.lfClipPrecision,
+ lf.lfQuality,
+ lf.lfPitchAndFamily,
+ lf.lfFaceName);
+
+ return s;
+}
+
+// ----------------------------------------------------------------------------
+// wxFont
+// ----------------------------------------------------------------------------
+
+bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
+{
+ UnRef();
+
+ m_refData = new wxFontRefData(info, hFont);
+
+ RealizeResource();
+
+ return true;