+ 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;
+}
+
+bool wxNativeFontInfo::SetFaceName(const wxString& facename)
+{
+ size_t len = WXSIZEOF(lf.lfFaceName);
+ wxStrncpy(lf.lfFaceName, facename, len);
+ lf.lfFaceName[len - 1] = '\0'; // truncate the face name
+ return true;
+}
+
+void wxNativeFontInfo::SetFamily(wxFontFamily family)
+{
+ BYTE ff_family;
+ wxArrayString facename;
+
+ // the list of fonts associated with a family was partially
+ // taken from http://www.codestyle.org/css/font-family
+
+ switch ( family )
+ {
+ case wxSCRIPT:
+ ff_family = FF_SCRIPT;
+ facename.Add(_T("Script"));
+ facename.Add(_T("Brush Script MT"));
+ facename.Add(_T("Comic Sans MS"));
+ facename.Add(_T("Lucida Handwriting"));
+ break;
+
+ case wxDECORATIVE:
+ ff_family = FF_DECORATIVE;
+ facename.Add(_T("Old English Text MT"));
+ facename.Add(_T("Comic Sans MS"));
+ facename.Add(_T("Lucida Handwriting"));
+ break;
+
+ case wxROMAN:
+ ff_family = FF_ROMAN;
+ facename.Add(_T("Times New Roman"));
+ facename.Add(_T("Georgia"));
+ facename.Add(_T("Garamond"));
+ facename.Add(_T("Bookman Old Style"));
+ facename.Add(_T("Book Antiqua"));
+ break;
+
+ case wxTELETYPE:
+ case wxMODERN:
+ ff_family = FF_MODERN;
+ facename.Add(_T("Courier New"));
+ facename.Add(_T("Lucida Console"));
+ facename.Add(_T("Andale Mono"));
+ facename.Add(_T("OCR A Extended"));
+ facename.Add(_T("Terminal"));
+ break;
+
+ case wxSWISS:
+ ff_family = FF_SWISS;
+ facename.Add(_T("Arial"));
+ facename.Add(_T("Century Gothic"));
+ facename.Add(_T("Lucida Sans Unicode"));
+ facename.Add(_T("Tahoma"));
+ facename.Add(_T("Trebuchet MS"));
+ facename.Add(_T("Verdana"));
+ 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) == wxOS_WINDOWS_NT && verMaj >= 5)
+ facename.Add(_T("MS Shell Dlg 2"));
+ else
+ facename.Add(_T("MS Shell Dlg"));
+
+ // Quoting the MSDN:
+ // "MS Shell Dlg is a mapping mechanism that enables
+ // U.S. English Microsoft Windows NT, and Microsoft Windows 2000 to
+ // support locales that have characters that are not contained in code
+ // page 1252. It is not a font but a face name for a nonexistent font."
+ }
+ }
+
+ 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,
+ (const wxChar*)lf.lfFaceName);
+
+ return s;
+}
+
+// ----------------------------------------------------------------------------
+// wxFont
+// ----------------------------------------------------------------------------
+
+bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
+{
+ UnRef();
+
+ m_refData = new wxFontRefData(info, hFont);
+
+ return RealizeResource();
+}
+
+wxFont::wxFont(const wxString& fontdesc)
+{
+ wxNativeFontInfo info;
+ if ( info.FromString(fontdesc) )
+ (void)Create(info);
+}
+
+bool wxFont::DoCreate(int pointSize,
+ const wxSize& pixelSize,
+ bool sizeUsingPixels,
+ int family,
+ int style,
+ int 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
+// ----------------------------------------------------------------------------
+
+wxObjectRefData *wxFont::CreateRefData() const
+{
+ return new wxFontRefData();
+}
+
+wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
+{
+ return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data));
+}
+
+bool wxFont::RealizeResource()
+{
+ // don't do anything if we already have a valid font
+ if ( GetHFONT() )
+ return true;
+
+ return M_FONTDATA->Alloc(this);
+}
+
+bool wxFont::FreeResource(bool WXUNUSED(force))
+{
+ if ( !GetHFONT() )
+ return false;
+
+ M_FONTDATA->Free();
+
+ return true;
+}
+
+WXHANDLE wxFont::GetResourceHandle() const
+{
+ return (WXHANDLE)GetHFONT();
+}
+
+WXHFONT wxFont::GetHFONT() const
+{
+ return M_FONTDATA ? M_FONTDATA->GetHFONT(this) : 0;
+}
+
+bool wxFont::IsFree() const
+{
+ return M_FONTDATA && !M_FONTDATA->HasHFONT();