+
+ if ( m_hFont )
+ {
+ ::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(fm.szFamilyname, "Times New Roman") == 0)
+ nFamily = wxROMAN;
+ else if (strcmp(fm.szFamilyname, "Times New Roman MT 30") == 0)
+ nFamily = wxROMAN;
+ else if (strcmp(fm.szFamilyname, "@Times New Roman MT 30") == 0)
+ nFamily = wxROMAN;
+ else if (strcmp(fm.szFamilyname, "Tms Rmn") == 0)
+ nFamily = wxROMAN;
+ else if (strcmp(fm.szFamilyname, "WarpSans") == 0)
+ nFamily = wxDECORATIVE;
+ else if (strcmp(fm.szFamilyname, "Helvetica") == 0)
+ nFamily = wxSWISS;
+ else if (strcmp(fm.szFamilyname, "Helv") == 0)
+ nFamily = wxSWISS;
+ else if (strcmp(fm.szFamilyname, "Script") == 0)
+ nFamily = wxSCRIPT;
+ else if (strcmp(fm.szFamilyname, "Courier New") == 0)
+ nFamily = wxTELETYPE;
+ else if (strcmp(fm.szFamilyname, "Courier") == 0)
+ nFamily = wxTELETYPE;
+ else if (strcmp(fm.szFamilyname, "System Monospaced") == 0)
+ nFamily = wxTELETYPE;
+ else if (strcmp(fm.szFamilyname, "System VIO") == 0)
+ nFamily = wxMODERN;
+ else if (strcmp(fm.szFamilyname, "System Proportional") == 0)
+ nFamily = wxMODERN;
+ else if (strcmp(fm.szFamilyname, "Arial") == 0)
+ nFamily = wxSWISS;
+ else if (strcmp(fm.szFamilyname, "Swiss") == 0)
+ nFamily = wxSWISS;
+ 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 = wxT("Tms Rmn");
+ break;
+
+ case wxDECORATIVE:
+ sFacename = wxT("WarpSans");
+ break;
+
+ case wxROMAN:
+ sFacename = wxT("Tms Rmn");
+ break;
+
+ case wxTELETYPE:
+ sFacename = wxT("Courier") ;
+ break;
+
+ case wxMODERN:
+ sFacename = wxT("System VIO") ;
+ break;
+
+ case wxSWISS:
+ sFacename = wxT("Helv") ;
+ break;
+
+ case wxDEFAULT:
+ default:
+ sFacename = wxT("System VIO") ;
+ }
+
+ if (!wxStrlen(fa.szFacename) )
+ {
+ SetFaceName(sFacename);
+ }
+} // end of wxNativeFontInfo::SetFamily
+
+void wxNativeFontInfo::SetEncoding(
+ wxFontEncoding eEncoding
+)
+{
+ wxNativeEncodingInfo vInfo;
+
+ if ( !wxGetNativeFontEncoding( eEncoding
+ ,&vInfo
+ ))
+ {
+ if (wxFontMapper::Get()->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
+ {
+ // 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