+ case wxFONTWEIGHT_LIGHT:
+ lf.lfWeight = FW_LIGHT;
+ break;
+
+ case wxFONTWEIGHT_BOLD:
+ lf.lfWeight = FW_BOLD;
+ break;
+ }
+}
+
+void wxNativeFontInfo::SetUnderlined(bool underlined)
+{
+ lf.lfUnderline = underlined;
+}
+
+bool wxNativeFontInfo::SetFaceName(const wxString& facename)
+{
+ wxStrlcpy(lf.lfFaceName, facename.c_str(), WXSIZEOF(lf.lfFaceName));
+ return true;
+}
+
+void wxNativeFontInfo::SetFamily(wxFontFamily family)
+{
+ BYTE ff_family = FF_DONTCARE;
+
+ switch ( family )
+ {
+ case wxFONTFAMILY_SCRIPT:
+ ff_family = FF_SCRIPT;
+ break;
+
+ case wxFONTFAMILY_DECORATIVE:
+ ff_family = FF_DECORATIVE;
+ break;
+
+ case wxFONTFAMILY_ROMAN:
+ ff_family = FF_ROMAN;
+ break;
+
+ case wxFONTFAMILY_TELETYPE:
+ case wxFONTFAMILY_MODERN:
+ ff_family = FF_MODERN;
+ break;
+
+ case wxFONTFAMILY_SWISS:
+ case wxFONTFAMILY_DEFAULT:
+ ff_family = FF_SWISS;
+ break;
+
+ case wxFONTFAMILY_UNKNOWN:
+ wxFAIL_MSG( "invalid font family" );
+ return;
+ }
+
+ wxCHECK_RET( ff_family != FF_DONTCARE, "unknown wxFontFamily" );
+
+ lf.lfPitchAndFamily = (BYTE)(DEFAULT_PITCH) | ff_family;
+
+ // reset the facename so that CreateFontIndirect() will automatically choose a
+ // face name based only on the font family.
+ lf.lfFaceName[0] = '\0';
+}
+
+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, wxS(";"), wxTOKEN_RET_EMPTY_ALL);
+
+ // first the version
+ wxString token = tokenizer.GetNextToken();
+ if ( token != wxS('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;
+
+ if ( !tokenizer.HasMoreTokens() )
+ return false;
+
+ // the face name may be empty
+ SetFaceName(tokenizer.GetNextToken());
+
+ return true;
+}
+
+wxString wxNativeFontInfo::ToString() const
+{
+ wxString s;
+
+ s.Printf(wxS("%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
+// ----------------------------------------------------------------------------
+
+wxFont::wxFont(const wxString& fontdesc)
+{
+ wxNativeFontInfo info;
+ if ( info.FromString(fontdesc) )
+ (void)Create(info);
+}
+
+bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
+{
+ UnRef();
+
+ m_refData = new wxFontRefData(info, hFont);
+
+ return RealizeResource();
+}
+
+bool wxFont::DoCreate(int pointSize,
+ const wxSize& pixelSize,
+ bool sizeUsingPixels,
+ wxFontFamily family,
+ wxFontStyle style,
+ wxFontWeight weight,
+ bool underlined,
+ const wxString& faceName,
+ wxFontEncoding encoding)
+{
+ UnRef();
+
+ // wxDEFAULT is a valid value for the font size too so we must treat it
+ // specially here (otherwise the size would be 70 == wxDEFAULT value)
+ if ( pointSize == wxDEFAULT )
+ {
+ pointSize = wxNORMAL_FONT->GetPointSize();
+ }
+
+ m_refData = new wxFontRefData(pointSize, pixelSize, sizeUsingPixels,
+ family, style, weight,
+ underlined, faceName, encoding);
+
+ return RealizeResource();
+}
+
+wxFont::~wxFont()
+{
+}
+
+// ----------------------------------------------------------------------------
+// real implementation
+// ----------------------------------------------------------------------------
+
+wxGDIRefData *wxFont::CreateGDIRefData() const
+{
+ return new wxFontRefData();
+}
+
+wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
+{
+ return new wxFontRefData(*static_cast<const wxFontRefData *>(data));
+}
+
+bool wxFont::RealizeResource()
+{
+ // NOTE: the GetHFONT() call automatically triggers a reallocation of
+ // the HFONT if necessary (will do nothing if we already have the resource);
+ // it returns NULL only if there is a failure in wxFontRefData::Alloc()...
+ return GetHFONT() != NULL;
+}
+
+bool wxFont::FreeResource(bool WXUNUSED(force))
+{
+ if ( !M_FONTDATA )
+ return false;
+
+ M_FONTDATA->Free();
+
+ return true;
+}
+
+WXHANDLE wxFont::GetResourceHandle() const
+{
+ return (WXHANDLE)GetHFONT();
+}
+
+WXHFONT wxFont::GetHFONT() const
+{
+ // NOTE: wxFontRefData::GetHFONT() will automatically call
+ // wxFontRefData::Alloc() if necessary
+ return M_FONTDATA ? M_FONTDATA->GetHFONT() : 0;
+}
+
+bool wxFont::IsFree() const
+{
+ return M_FONTDATA && !M_FONTDATA->HasHFONT();
+}
+
+// ----------------------------------------------------------------------------
+// change font attribute: we recreate font when doing it
+// ----------------------------------------------------------------------------
+
+void wxFont::SetPointSize(int pointSize)
+{
+ AllocExclusive();
+
+ M_FONTDATA->Free();
+ M_FONTDATA->SetPointSize(pointSize);
+}
+
+void wxFont::SetPixelSize(const wxSize& pixelSize)
+{
+ AllocExclusive();
+
+ M_FONTDATA->SetPixelSize(pixelSize);
+}
+
+void wxFont::SetFamily(wxFontFamily family)
+{
+ AllocExclusive();
+
+ M_FONTDATA->SetFamily(family);
+}
+
+void wxFont::SetStyle(wxFontStyle style)
+{
+ AllocExclusive();
+
+ M_FONTDATA->SetStyle(style);