+
+ if ( m_hFont )
+ {
+ if (!::GpiSetCharSet(m_hPS, LCID_DEFAULT))
+ {
+ wxLogLastError(wxT("DeleteObject(font)"));
+ }
+ ::GpiDeleteSetId(m_hPS, 1L); /* delete the logical font */
+ m_nFontId = 0;
+ m_hFont = 0;
+ }
+ if (m_bInternalPS)
+ ::WinReleasePS(m_hPS);
+ m_hPS = NULLHANDLE;
+} // end of wxFontRefData::Free
+
+// ----------------------------------------------------------------------------
+// wxNativeFontInfo
+// ----------------------------------------------------------------------------
+
+void wxNativeFontInfo::Init()
+{
+ memset(&fa, '\0', sizeof(FATTRS));
+} // end of wxNativeFontInfo::Init
+
+int wxNativeFontInfo::GetPointSize() const
+{
+ return fm.lEmHeight;
+} // end of wxNativeFontInfo::GetPointSize
+
+wxFontStyle wxNativeFontInfo::GetStyle() const
+{
+ return fa.fsSelection & FATTR_SEL_ITALIC ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL;
+} // end of wxNativeFontInfo::GetStyle
+
+wxFontWeight wxNativeFontInfo::GetWeight() const
+{
+ switch(fn.usWeightClass)
+ {
+ case FWEIGHT_DONT_CARE:
+ return wxFONTWEIGHT_NORMAL;
+
+ case FWEIGHT_NORMAL:
+ return wxFONTWEIGHT_NORMAL;
+
+ case FWEIGHT_LIGHT:
+ return wxFONTWEIGHT_LIGHT;
+
+ case FWEIGHT_BOLD:
+ return wxFONTWEIGHT_BOLD;
+
+ case FWEIGHT_ULTRA_BOLD:
+ return wxFONTWEIGHT_MAX;
+ }
+ return wxFONTWEIGHT_NORMAL;
+} // end of wxNativeFontInfo::GetWeight
+
+bool wxNativeFontInfo::GetUnderlined() const
+{
+ return ((fa.fsSelection & FATTR_SEL_UNDERSCORE) != 0);
+} // end of wxNativeFontInfo::GetUnderlined
+
+wxString wxNativeFontInfo::GetFaceName() const
+{
+ return fm.szFacename;
+} // end of wxNativeFontInfo::GetFaceName
+
+wxFontFamily wxNativeFontInfo::GetFamily() const
+{
+ int nFamily;
+
+ //
+ // Extract family from facename
+ //
+ if (strcmp(fa.szFacename, "Times New Roman") == 0)
+ nFamily = wxROMAN;
+ else if (strcmp(fa.szFacename, "WarpSans") == 0)
+ nFamily = wxSWISS;
+ else if (strcmp(fa.szFacename, "Script") == 0)
+ nFamily = wxSCRIPT;
+ else if (strcmp(fa.szFacename, "Courier New") == 0)
+ nFamily = wxMODERN;
+ else
+ nFamily = wxSWISS;
+ return (wxFontFamily)nFamily;
+} // end of wxNativeFontInfo::GetFamily
+
+wxFontEncoding wxNativeFontInfo::GetEncoding() const
+{
+ return wxGetFontEncFromCharSet(fa.usCodePage);
+} // end of wxNativeFontInfo::GetEncoding
+
+void wxNativeFontInfo::SetPointSize(
+ int nPointsize
+)
+{
+ fm.lEmHeight = (LONG)nPointsize;
+} // end of wxNativeFontInfo::SetPointSize
+
+void wxNativeFontInfo::SetStyle(
+ wxFontStyle eStyle
+)
+{
+ switch (eStyle)
+ {
+ default:
+ wxFAIL_MSG( _T("unknown font style") );
+ // fall through
+
+ case wxFONTSTYLE_NORMAL:
+ break;
+
+ case wxFONTSTYLE_ITALIC:
+ case wxFONTSTYLE_SLANT:
+ fa.fsSelection |= FATTR_SEL_ITALIC;
+ break;
+ }
+} // end of wxNativeFontInfo::SetStyle
+
+void wxNativeFontInfo::SetWeight(
+ wxFontWeight eWeight
+)
+{
+ switch (eWeight)
+ {
+ default:
+ wxFAIL_MSG( _T("unknown font weight") );
+ // fall through
+
+ case wxFONTWEIGHT_NORMAL:
+ fn.usWeightClass = FWEIGHT_NORMAL;
+ break;
+
+ case wxFONTWEIGHT_LIGHT:
+ fn.usWeightClass = FWEIGHT_LIGHT;
+ break;
+
+ case wxFONTWEIGHT_BOLD:
+ fn.usWeightClass = FWEIGHT_BOLD;
+ break;
+ }
+} // end of wxNativeFontInfo::SetWeight
+
+void wxNativeFontInfo::SetUnderlined(
+ bool bUnderlined
+)
+{
+ if(bUnderlined)
+ fa.fsSelection |= FATTR_SEL_UNDERSCORE;
+} // end of wxNativeFontInfo::SetUnderlined
+
+void wxNativeFontInfo::SetFaceName(
+ wxString sFacename
+)
+{
+ wxStrncpy(fa.szFacename, sFacename, WXSIZEOF(fa.szFacename));
+} // end of wxNativeFontInfo::SetFaceName
+
+void wxNativeFontInfo::SetFamily(
+ wxFontFamily eFamily
+)
+{
+ wxString sFacename;
+
+ switch (eFamily)
+ {
+ case wxSCRIPT:
+ sFacename = _T("Script");
+ break;
+
+ case wxDECORATIVE:
+ sFacename = _T("Times New Roman");
+ break;
+
+ case wxROMAN:
+ sFacename = _T("Times New Roman");
+ break;
+
+ case wxTELETYPE:
+ case wxMODERN:
+ sFacename = _T("Courier New");
+ break;
+
+ case wxSWISS:
+ sFacename = _T("WarpSans");
+ break;
+
+ case wxDEFAULT:
+ default:
+ sFacename = _T("Helv");
+ }
+
+ if (!wxStrlen(fa.szFacename) )
+ {
+ SetFaceName(sFacename);
+ }
+} // end of wxNativeFontInfo::SetFamily
+
+void wxNativeFontInfo::SetEncoding(
+ wxFontEncoding eEncoding
+)
+{
+ wxNativeEncodingInfo vInfo;
+
+ if ( !wxGetNativeFontEncoding( eEncoding
+ ,&vInfo
+ ))
+ {
+#if wxUSE_FONTMAP
+ if (wxTheFontMapper->GetAltForEncoding( eEncoding
+ ,&vInfo
+ ))
+ {
+ if (!vInfo.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(vInfo.facename);
+ }
+ }
+ else
+#endif // wxUSE_FONTMAP
+ {
+ // unsupported encoding, replace with the default
+ vInfo.charset = 850;
+ }
+ }
+ fa.usCodePage = vInfo.charset;
+} // end of wxNativeFontInfo::SetFaceName
+
+bool wxNativeFontInfo::FromString(
+ const wxString& rsStr
+)
+{
+ long lVal;
+
+ wxStringTokenizer vTokenizer(rsStr, _T(";"));
+
+ //
+ // First the version
+ //
+ wxString sToken = vTokenizer.GetNextToken();
+
+ if (sToken != _T('0'))
+ return FALSE;
+
+ sToken = vTokenizer.GetNextToken();
+ if (!sToken.ToLong(&lVal))
+ return FALSE;
+ fm.lEmHeight = lVal;
+
+ sToken = vTokenizer.GetNextToken();
+ if (!sToken.ToLong(&lVal))
+ return FALSE;
+ fa.lAveCharWidth = lVal;
+
+ sToken = vTokenizer.GetNextToken();
+ if (!sToken.ToLong(&lVal))
+ return FALSE;
+ fa.fsSelection = (USHORT)lVal;
+
+ sToken = vTokenizer.GetNextToken();
+ if (!sToken.ToLong(&lVal))
+ return FALSE;
+ fa.fsType = (USHORT)lVal;
+
+ sToken = vTokenizer.GetNextToken();
+ if (!sToken.ToLong(&lVal))
+ return FALSE;
+ fa.fsFontUse = (USHORT)lVal;
+
+ sToken = vTokenizer.GetNextToken();
+ if (!sToken.ToLong(&lVal))
+ return FALSE;
+ fa.idRegistry = (USHORT)lVal;
+
+ sToken = vTokenizer.GetNextToken();
+ if (!sToken.ToLong(&lVal))
+ return FALSE;
+ fa.usCodePage = (USHORT)lVal;
+
+ sToken = vTokenizer.GetNextToken();
+ if (!sToken.ToLong(&lVal))
+ return FALSE;
+ fa.lMatch = lVal;
+
+ sToken = vTokenizer.GetNextToken();
+ if (!sToken.ToLong(&lVal))
+ return FALSE;
+ fn.usWeightClass = (USHORT)lVal;
+
+ sToken = vTokenizer.GetNextToken();
+ if(!sToken)
+ return FALSE;
+ wxStrcpy(fa.szFacename, sToken.c_str());
+ return TRUE;
+} // end of wxNativeFontInfo::FromString
+
+wxString wxNativeFontInfo::ToString() const
+{
+ wxString sStr;
+
+ sStr.Printf(_T("%d;%ld;%ld;%ld;%d;%d;%d;%d;%d;%ld;%d;%s"),
+ 0, // version, in case we want to change the format later
+ fm.lEmHeight,
+ fa.lAveCharWidth,
+ fa.lMaxBaselineExt,
+ fa.fsSelection,
+ fa.fsType,
+ fa.fsFontUse,
+ fa.idRegistry,
+ fa.usCodePage,
+ fa.lMatch,
+ fn.usWeightClass,
+ fa.szFacename);
+ return sStr;
+} // end of wxNativeFontInfo::ToString