]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/font.cpp
corrected path splitting for mac relative paths
[wxWidgets.git] / src / os2 / font.cpp
index b443496b6a6303033f27738d86ea8419e1e58e1c..c1839db1ca66c6da98c592b64c6cf92373e28954 100644 (file)
@@ -17,6 +17,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
+ #include <malloc.h>
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 
 #include "wx/os2/private.h"
 
 
 #include "wx/os2/private.h"
 
-    IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
+#include "wx/fontutil.h"
+#include "wx/fontmap.h"
 
 
-    #if wxUSE_PORTABLE_FONTS_IN_MSW
-        IMPLEMENT_DYNAMIC_CLASS(wxFontNameDirectory, wxObject)
-    #endif
+#include "wx/tokenzr.h"
+
+IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
 
 // ----------------------------------------------------------------------------
 // wxFontRefData - the internal description of the font
 
 // ----------------------------------------------------------------------------
 // wxFontRefData - the internal description of the font
 
 class WXDLLEXPORT wxFontRefData: public wxGDIRefData
 {
 
 class WXDLLEXPORT wxFontRefData: public wxGDIRefData
 {
-friend class WXDLLEXPORT wxFont;
-
 public:
     wxFontRefData()
     {
 public:
     wxFontRefData()
     {
-        Init(12, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE,
+        Init(-1, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, FALSE,
              "", wxFONTENCODING_DEFAULT);
     }
 
              "", wxFONTENCODING_DEFAULT);
     }
 
-    wxFontRefData(const wxFontRefData& data)
+    wxFontRefData( int             nSize
+                  ,int             nFamily
+                  ,int             nStyle
+                  ,int             nWeight
+                  ,bool            bUnderlined
+                  ,const wxString& sFaceName
+                  ,wxFontEncoding  vEncoding
+                 )
     {
     {
-        Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
-             data.m_underlined, data.m_faceName, data.m_encoding);
+        Init( nSize
+             ,nFamily
+             ,nStyle
+             ,nWeight
+             ,bUnderlined
+             ,sFaceName
+             ,vEncoding
+            );
+    }
 
 
-        m_fontId = data.m_fontId;
+    wxFontRefData( const wxNativeFontInfo& rInfo
+                  ,WXHFONT                 hFont = 0
+                  ,WXHANDLE                hPS   = 0
+                 )
+    {
+        Init( rInfo
+             ,hFont
+             ,hPS
+            );
     }
 
     }
 
-    wxFontRefData(int size,
-                  int family,
-                  int style,
-                  int weight,
-                  bool underlined,
-                  const wxString& faceName,
-                  wxFontEncoding encoding)
+    wxFontRefData(const wxFontRefData& rData)
     {
     {
-        Init(size, family, style, weight, underlined, faceName, encoding);
+        Init( rData.m_nPointSize
+             ,rData.m_nFamily
+             ,rData.m_nStyle
+             ,rData.m_nWeight
+             ,rData.m_bUnderlined
+             ,rData.m_sFaceName
+             ,rData.m_vEncoding
+            );
+        m_nFontId = rData.m_nFontId;
     }
 
     virtual ~wxFontRefData();
 
     }
 
     virtual ~wxFontRefData();
 
-protected:
-    // common part of all ctors
-    void Init(int size,
-              int family,
-              int style,
-              int weight,
-              bool underlined,
-              const wxString& faceName,
-              wxFontEncoding encoding);
+    //
+    // Operations
+    //
+    bool Alloc(wxFont* pFont);
+    void Free(void);
 
 
-    // If TRUE, the pointer to the actual font is temporary and SHOULD NOT BE
-    // DELETED by destructor
-    bool          m_temporary;
+    //
+    // All wxFont accessors
+    //
+    inline int GetPointSize(void) const
+    {
+        //
+        // We don't use the actual native font point size since it is
+        // the chosen physical font, which is usually only and approximation
+        // of the desired outline font.  The actual displayable point size
+        // is the one stored in the refData
+        //
+        return m_nPointSize;
+    }
+
+    inline int GetFamily(void) const
+    {
+        return m_nFamily;
+    }
+
+    inline int GetStyle(void) const
+    {
+        return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetStyle()
+                                   : m_nStyle;
+    }
+
+    inline int GetWeight(void) const
+    {
+        return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetWeight()
+                                   : m_nWeight;
+    }
+
+    inline bool GetUnderlined(void) const
+    {
+        return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetUnderlined()
+                                   : m_bUnderlined;
+    }
+
+    inline wxString GetFaceName(void) const
+    {
+        wxString                    sFaceName;
+
+        if (m_bNativeFontInfoOk)
+            sFaceName = m_vNativeFontInfo.GetFaceName();
+        else
+            sFaceName = m_sFaceName;
+
+        return sFaceName;
+    }
+
+    inline wxFontEncoding GetEncoding(void) const
+    {
+        return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetEncoding()
+                                   : m_vEncoding;
+    }
+
+    inline WXHFONT      GetHFONT(void) const { return m_hFont; }
+    inline HPS          GetPS(void) const { return m_hPS; }
+    inline PFONTMETRICS GetFM(void) const { return m_pFM; }
+    inline int          GetNumFonts(void) const { return m_nNumFonts; }
+
+    // ... and setters
+    inline void SetPointSize(int nPointSize)
+    {
+        if (m_bNativeFontInfoOk)
+            m_vNativeFontInfo.SetPointSize(nPointSize);
+        else
+            m_nPointSize = nPointSize;
+    }
 
 
-    int           m_fontId;
+    inline void SetFamily(int nFamily)
+    {
+        m_nFamily = nFamily;
+    }
 
 
-    // font characterstics
-    int           m_pointSize;
-    int           m_family;
-    int           m_style;
-    int           m_weight;
-    bool          m_underlined;
-    wxString      m_faceName;
-    wxFontEncoding m_encoding;
+    inline void SetStyle(int nStyle)
+    {
+        if (m_bNativeFontInfoOk)
+            m_vNativeFontInfo.SetStyle((wxFontStyle)nStyle);
+        else
+            m_nStyle = nStyle;
+    }
 
 
-    // Windows font handle
-    WXHFONT       m_hFont;
-};
+    inline void SetWeight(int nWeight)
+    {
+        if (m_bNativeFontInfoOk)
+            m_vNativeFontInfo.SetWeight((wxFontWeight)nWeight);
+        else
+            m_nWeight = nWeight;
+    }
+
+    inline void SetFaceName(const wxString& sFaceName)
+    {
+        if (m_bNativeFontInfoOk)
+            m_vNativeFontInfo.SetFaceName(sFaceName);
+        else
+            m_sFaceName = sFaceName;
+    }
+
+    inline void SetUnderlined(bool bUnderlined)
+    {
+        if (m_bNativeFontInfoOk)
+            m_vNativeFontInfo.SetUnderlined(bUnderlined);
+        else
+            m_bUnderlined = bUnderlined;
+    }
+
+    inline void SetEncoding(wxFontEncoding vEncoding)
+    {
+        if (m_bNativeFontInfoOk)
+            m_vNativeFontInfo.SetEncoding(vEncoding);
+        else
+            m_vEncoding = vEncoding;
+    }
+
+    inline void SetPS(HPS hPS)
+    {
+        m_hPS = hPS;
+    }
+
+    inline void SetFM(PFONTMETRICS pFM)
+    {
+        m_pFM = pFM;
+    }
+
+    inline void SetNumFonts(int nNumFonts)
+    {
+        m_nNumFonts = nNumFonts;
+    }
+
+    //
+    // Native font info tests
+    //
+    bool HasNativeFontInfo() const { return m_bNativeFontInfoOk; }
+
+    const wxNativeFontInfo& GetNativeFontInfo() const
+        { return m_vNativeFontInfo; }
+
+protected:
+    //
+    // Common part of all ctors
+    //
+    void Init( int             nSize
+              ,int             nFamily
+              ,int             nStyle
+              ,int             nWeight
+              ,bool            bUnderlined
+              ,const wxString& rsFaceName
+              ,wxFontEncoding  vEncoding
+             );
+
+    void Init( const wxNativeFontInfo& rInfo
+              ,WXHFONT                 hFont = 0
+              ,WXHANDLE                hPS   = 0
+             );
+    //
+    // If TRUE, the pointer to the actual font is temporary and SHOULD NOT BE
+    // DELETED by destructor
+    //
+    bool                            m_bTemporary;
+    int                             m_nFontId;
+
+    //
+    // Font characterstics
+    //
+    int                             m_nPointSize;
+    int                             m_nFamily;
+    int                             m_nStyle;
+    int                             m_nWeight;
+    bool                            m_bUnderlined;
+    wxString                        m_sFaceName;
+    wxFontEncoding                  m_vEncoding;
+    WXHFONT                         m_hFont;
+
+    //
+    // Native font info
+    //
+    wxNativeFontInfo                m_vNativeFontInfo;
+    bool                            m_bNativeFontInfoOk;
+
+    //
+    // Some PM specific stuff
+    //
+    PFONTMETRICS                    m_pFM;         // array of FONTMETRICS structs
+    int                             m_nNumFonts;   // number of fonts in array
+    HPS                             m_hPS;         // PS handle this font belongs to
+    FATTRS                          m_vFattrs;     // Current fattrs struct
+    FACENAMEDESC                    m_vFname;      // Current facename struct
+    bool                            m_bInternalPS; // Internally generated PS?
+}; // end of CLASS wxFontRefData
 
 // ============================================================================
 // implementation
 
 // ============================================================================
 // implementation
@@ -110,320 +301,632 @@ protected:
 // wxFontRefData
 // ----------------------------------------------------------------------------
 
 // wxFontRefData
 // ----------------------------------------------------------------------------
 
-void wxFontRefData::Init(int pointSize,
-                         int family,
-                         int style,
-                         int weight,
-                         bool underlined,
-                         const wxString& faceName,
-                         wxFontEncoding encoding)
-{
-    m_style = style;
-    m_pointSize = pointSize;
-    m_family = family;
-    m_style = style;
-    m_weight = weight;
-    m_underlined = underlined;
-    m_faceName = faceName;
-    m_encoding = encoding;
-
-    m_fontId = 0;
-    m_temporary = FALSE;
-
-    m_hFont = 0;
+void wxFontRefData::Init(
+  int                               nPointSize
+, int                               nFamily
+, int                               nStyle
+, int                               nWeight
+, bool                              bUnderlined
+, const wxString&                   rsFaceName
+, wxFontEncoding                    vEncoding
+)
+{
+    m_nStyle      = nStyle;
+    m_nPointSize  = nPointSize;
+    m_nFamily     = nFamily;
+    m_nStyle      = nStyle;
+    m_nWeight     = nWeight;
+    m_bUnderlined = bUnderlined;
+    m_sFaceName   = rsFaceName;
+    m_vEncoding   = vEncoding;
+    m_hFont       = 0;
+
+    m_bNativeFontInfoOk = FALSE;
+
+    m_nFontId     = 0;
+    m_bTemporary  = FALSE;
+    m_pFM         = (PFONTMETRICS)NULL;
+    m_hPS         = NULLHANDLE;
+    m_nNumFonts   = 0;
+} // end of wxFontRefData::Init
+
+void wxFontRefData::Init(
+  const wxNativeFontInfo&           rInfo
+, WXHFONT                           hFont //this is the FontId -- functions as the hFont for OS/2
+, WXHANDLE                          hPS   // Presentation Space we are using
+)
+{
+    //
+    // hFont may be zero, or it be passed in case we really want to
+    // use the exact font created in the underlying system
+    // (for example where we can't guarantee conversion from HFONT
+    // to LOGFONT back to HFONT)
+    //
+    m_hFont = hFont;
+    m_nFontId = (int)hFont;
+
+    m_bNativeFontInfoOk = TRUE;
+    m_vNativeFontInfo = rInfo;
+
+    if (m_hPS == NULLHANDLE)
+    {
+        m_hPS = ::WinGetPS(HWND_DESKTOP);
+        m_bInternalPS;
+    }
+    else
+        m_hPS = (HPS)hPS;
 }
 
 wxFontRefData::~wxFontRefData()
 {
 }
 
 wxFontRefData::~wxFontRefData()
 {
-// TODO:
-//    if ( m_hFont )
-//    {
-//        if ( !::DeleteObject((HFONT) m_hFont) )
-//        {
-//            wxLogLastError("DeleteObject(font)");
-//        }
-//    }
+    Free();
 }
 
 }
 
-// ----------------------------------------------------------------------------
-// wxFont
-// ----------------------------------------------------------------------------
-
-void wxFont::Init()
+bool wxFontRefData::Alloc(
+  wxFont*                           pFont
+)
 {
 {
-    if ( wxTheFontList )
-        wxTheFontList->Append(this);
-}
+    wxString                        sFaceName;
+    long                            flId = m_hFont;
+    long                            lRc;
+    short                           nIndex = 0;
+    PFONTMETRICS                    pFM = NULL;
 
 
-/* Constructor for a font. Note that the real construction is done
- * in wxDC::SetFont, when information is available about scaling etc.
- */
-bool wxFont::Create(int pointSize,
-                    int family,
-                    int style,
-                    int weight,
-                    bool underlined,
-                    const wxString& faceName,
-                    wxFontEncoding encoding)
-{
-    UnRef();
-    m_refData = new wxFontRefData(pointSize, family, style, weight,
-                                  underlined, faceName, encoding);
+    if (!m_bNativeFontInfoOk)
+    {
+        wxFillLogFont( &m_vNativeFontInfo.fa
+                      ,&m_vNativeFontInfo.fn
+                      ,&m_hPS
+                      ,&m_bInternalPS
+                      ,&flId
+                      ,sFaceName
+                      ,pFont
+                     );
+        m_bNativeFontInfoOk = TRUE;
+    }
 
 
-    RealizeResource();
+    if((lRc = ::GpiCreateLogFont( m_hPS
+                                 ,NULL
+                                 ,flId
+                                 ,&m_vNativeFontInfo.fa
+                                )) != GPI_ERROR)
+    {
+       m_hFont = (WXHFONT)flId;
+       m_nFontId = flId;
+    }
+    if (!m_hFont)
+    {
+        wxLogLastError("CreateFont");
+    }
+
+    ::GpiSetCharSet(m_hPS, flId); // sets font for presentation space
+    ::GpiQueryFontMetrics(m_hPS, sizeof(FONTMETRICS), &m_vNativeFontInfo.fm);
+
+    //
+    // Set refData members with the results
+    //
+    memcpy(&m_vFattrs, &m_vNativeFontInfo.fa, sizeof(m_vFattrs));
+    memcpy(&m_vFname, &m_vNativeFontInfo.fn, sizeof(m_vFname));
+    //
+    // Going to leave the point size alone.  Mostly we use outline fonts
+    // that can be set to any point size inside of Presentation Parameters,
+    // regardless of whether or not the actual font is registered in the system.
+    // The GpiCreateLogFont will do enough by selecting the right family,
+    // and face name.
+    //
+    if (strcmp(m_vNativeFontInfo.fa.szFacename, "Times New Roman") == 0)
+        m_nFamily = wxROMAN;
+    else if (strcmp(m_vNativeFontInfo.fa.szFacename, "Tms Rmn") == 0)
+        m_nFamily = wxSWISS;
+    else if (strcmp(m_vNativeFontInfo.fa.szFacename, "WarpSans") == 0)
+        m_nFamily = wxSWISS;
+    else if (strcmp(m_vNativeFontInfo.fa.szFacename, "Helvitica") == 0)
+        m_nFamily = wxSWISS;
+    else if (strcmp(m_vNativeFontInfo.fa.szFacename, "Helv") == 0)
+        m_nFamily = wxSWISS;
+    else if (strcmp(m_vNativeFontInfo.fa.szFacename, "Script") == 0)
+        m_nFamily = wxSCRIPT;
+    else if (strcmp(m_vNativeFontInfo.fa.szFacename, "Courier New") == 0)
+        m_nFamily = wxTELETYPE;
+    else if (strcmp(m_vNativeFontInfo.fa.szFacename, "Courier") == 0)
+        m_nFamily = wxTELETYPE;
+    else if (strcmp(m_vNativeFontInfo.fa.szFacename, "System VIO") == 0)
+        m_nFamily = wxMODERN;
+    else
+        m_nFamily = wxSWISS;
+
+    if (m_vNativeFontInfo.fa.fsSelection & FATTR_SEL_ITALIC)
+        m_nStyle = wxFONTSTYLE_ITALIC;
+    else
+        m_nStyle = wxFONTSTYLE_NORMAL;
+    switch(m_vNativeFontInfo.fn.usWeightClass)
+    {
+        case FWEIGHT_DONT_CARE:
+            m_nWeight = wxFONTWEIGHT_NORMAL;
+            break;
+
+        case FWEIGHT_NORMAL:
+            m_nWeight = wxFONTWEIGHT_NORMAL;
+            break;
+
+        case FWEIGHT_LIGHT:
+            m_nWeight = wxFONTWEIGHT_LIGHT;
+            break;
+
+        case FWEIGHT_BOLD:
+            m_nWeight = wxFONTWEIGHT_BOLD;
+            break;
+
+        case FWEIGHT_ULTRA_BOLD:
+            m_nWeight = wxFONTWEIGHT_MAX;
+            break;
 
 
+        default:
+            m_nWeight = wxFONTWEIGHT_NORMAL;
+    }
+    m_bUnderlined = ((m_vNativeFontInfo.fa.fsSelection & FATTR_SEL_UNDERSCORE) != 0);
+    m_sFaceName = m_vNativeFontInfo.fa.szFacename;
+    m_vEncoding = wxGetFontEncFromCharSet(m_vNativeFontInfo.fa.usCodePage);
+
+    //
+    // We don't actuall keep the font around if using a temporary PS
+    //
+    if (m_bInternalPS)
+    {
+        if(m_hFont)
+            ::GpiDeleteSetId( m_hPS
+                             ,flId
+                            );
+
+        ::WinReleasePS(m_hPS);
+    }
+    else
+        //
+        // Select the font into the Presentation space
+        //
+        ::GpiSetCharSet(m_hPS, flId); // sets font for presentation space
     return TRUE;
     return TRUE;
-}
+} // end of wxFontRefData::Alloc
 
 
-wxFont::~wxFont()
+void wxFontRefData::Free()
 {
 {
-    if ( wxTheFontList )
-        wxTheFontList->DeleteObject(this);
-}
+    if (m_pFM)
+        delete [] m_pFM;
+    m_pFM = (PFONTMETRICS)NULL;
+
+    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
 
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
-// real implementation
-// Boris' Kovalenko comments:
-//   Because OS/2 fonts are associated with PS we can not create the font
-//   here, but we may check that font definition is true
+// wxNativeFontInfo
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 
-bool wxFont::RealizeResource()
+void wxNativeFontInfo::Init()
 {
 {
-    if ( GetResourceHandle() )
-    {
-        // VZ: the old code returned FALSE in this case, but it doesn't seem
-        //     to make sense because the font _was_ created
-        wxLogDebug(wxT("Calling wxFont::RealizeResource() twice"));
+    memset(&fa, '\0', sizeof(FATTRS));
+} // end of wxNativeFontInfo::Init
 
 
-       return TRUE;
-    }
+int wxNativeFontInfo::GetPointSize() const
+{
+    return fm.lEmHeight;
+} // end of wxNativeFontInfo::GetPointSize
 
 
-    HPS          hps;
-    FATTRS       fAttrs;
-    FACENAMEDESC fName;
-    LONG         fLid;
+wxFontStyle wxNativeFontInfo::GetStyle() const
+{
+    return fa.fsSelection & FATTR_SEL_ITALIC ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL;
+} // end of wxNativeFontInfo::GetStyle
 
 
-    fAttrs.usRecordLength = sizeof(FATTRS);
-    fAttrs.fsFontUse = FATTR_FONTUSE_OUTLINE |       // only outline fonts allowed
-                       FATTR_FONTUSE_TRANSFORMABLE;  // may be transformed
-    fAttrs.fsType = 0;
-    fAttrs.lMaxBaselineExt = fAttrs.lAveCharWidth = 0;
-    fAttrs.idRegistry = 0;
-    fAttrs.lMatch = 0;
+wxFontWeight wxNativeFontInfo::GetWeight() const
+{
+    switch(fn.usWeightClass)
+    {
+        case FWEIGHT_DONT_CARE:
+            return wxFONTWEIGHT_NORMAL;
 
 
-    fName.usSize = sizeof(FACENAMEDESC);
-    fName.usWidthClass = FWIDTH_NORMAL;
-    fName.usReserved = 0;
-    fName.flOptions = 0;
+        case FWEIGHT_NORMAL:
+            return wxFONTWEIGHT_NORMAL;
 
 
-    wxString ff_face;
+        case FWEIGHT_LIGHT:
+            return wxFONTWEIGHT_LIGHT;
 
 
-// OS/2 combines the family with styles to give a facename
+        case FWEIGHT_BOLD:
+            return wxFONTWEIGHT_BOLD;
 
 
-    switch ( M_FONTDATA->m_family )
-    {
-        case wxSCRIPT:
-        case wxDECORATIVE:
-        case wxROMAN:
-            ff_face = wxT("Times New Roman") ;
-            break;
+        case FWEIGHT_ULTRA_BOLD:
+            return wxFONTWEIGHT_MAX;
+    }
+    return wxFONTWEIGHT_NORMAL;
+} // end of wxNativeFontInfo::GetWeight
 
 
-        case wxTELETYPE:
-        case wxMODERN:
-            ff_face = wxT("Courier") ;
-            break;
+bool wxNativeFontInfo::GetUnderlined() const
+{
+    return ((fa.fsSelection & FATTR_SEL_UNDERSCORE) != 0);
+} // end of wxNativeFontInfo::GetUnderlined
 
 
-        case wxSWISS:
-        case wxDEFAULT:
-        default:
-            ff_face = wxT("Helvetica") ;
-    }
+wxString wxNativeFontInfo::GetFaceName() const
+{
+    return fm.szFacename;
+} // end of wxNativeFontInfo::GetFaceName
 
 
-    switch ( M_FONTDATA->m_style )
-    {
-        case wxITALIC:
-        case wxSLANT:
-            fAttrs.fsSelection = FATTR_SEL_ITALIC;
-            break;
+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
 
 
-        default:
-            wxFAIL_MSG(wxT("unknown font slant"));
-            // fall through
+wxFontEncoding wxNativeFontInfo::GetEncoding() const
+{
+    return wxGetFontEncFromCharSet(fa.usCodePage);
+} // end of wxNativeFontInfo::GetEncoding
 
 
-        case wxNORMAL:
-            fAttrs.fsSelection = 0;
-    }
+void wxNativeFontInfo::SetPointSize(
+  int                               nPointsize
+)
+{
+    fm.lEmHeight = (LONG)nPointsize;
+} // end of wxNativeFontInfo::SetPointSize
 
 
-    switch ( M_FONTDATA->m_weight )
+void wxNativeFontInfo::SetStyle(
+  wxFontStyle                       eStyle
+)
+{
+    switch (eStyle)
     {
         default:
     {
         default:
-            wxFAIL_MSG(wxT("unknown font weight"));
+            wxFAIL_MSG( _T("unknown font style") );
             // fall through
 
             // fall through
 
-        case wxNORMAL:
-            fName.usWeightClass = FWEIGHT_NORMAL;
-            break;
-
-        case wxLIGHT:
-            fName.usWeightClass = FWEIGHT_LIGHT;
+        case wxFONTSTYLE_NORMAL:
             break;
 
             break;
 
-        case wxBOLD:
-            fName.usWeightClass = FWEIGHT_BOLD;
+        case wxFONTSTYLE_ITALIC:
+        case wxFONTSTYLE_SLANT:
+            fa.fsSelection |= FATTR_SEL_ITALIC;
             break;
     }
             break;
     }
-  
-    if( M_FONTDATA->m_underlined )
-        fAttrs.fsSelection |= FATTR_SEL_UNDERSCORE;
+} // end of wxNativeFontInfo::SetStyle
 
 
-    wxFontEncoding encoding = M_FONTDATA->m_encoding;
-    if ( encoding == wxFONTENCODING_DEFAULT )
+void wxNativeFontInfo::SetWeight(
+  wxFontWeight                      eWeight
+)
+{
+    switch (eWeight)
     {
     {
-        encoding = wxFont::GetDefaultEncoding();
-    }
+        default:
+            wxFAIL_MSG( _T("unknown font weight") );
+            // fall through
 
 
-    switch ( encoding )
-    {
-        case wxFONTENCODING_ISO8859_1:
-        case wxFONTENCODING_ISO8859_15:
-        case wxFONTENCODING_CP1250:
-            fAttrs.usCodePage = 1250;
+        case wxFONTWEIGHT_NORMAL:
+            fn.usWeightClass = FWEIGHT_NORMAL;
             break;
 
             break;
 
-        case wxFONTENCODING_ISO8859_2:
-        case wxFONTENCODING_CP1252:
-            fAttrs.usCodePage = 1252;
+        case wxFONTWEIGHT_LIGHT:
+            fn.usWeightClass = FWEIGHT_LIGHT;
             break;
 
             break;
 
-        case wxFONTENCODING_ISO8859_4:
-        case wxFONTENCODING_ISO8859_10:
-            fAttrs.usCodePage = 850; // what is baltic?
+        case wxFONTWEIGHT_BOLD:
+            fn.usWeightClass = FWEIGHT_BOLD;
             break;
             break;
+    }
+} // end of wxNativeFontInfo::SetWeight
 
 
-        case wxFONTENCODING_ISO8859_5:
-        case wxFONTENCODING_CP1251:
-            fAttrs.usCodePage = 1251;
-            break;
+void wxNativeFontInfo::SetUnderlined(
+  bool                              bUnderlined
+)
+{
+    if(bUnderlined)
+        fa.fsSelection |= FATTR_SEL_UNDERSCORE;
+} // end of wxNativeFontInfo::SetUnderlined
 
 
-        case wxFONTENCODING_ISO8859_6:
-            fAttrs.usCodePage = 850;  // what is arabic?
-            break;
+void wxNativeFontInfo::SetFaceName(
+  wxString                          sFacename
+)
+{
+    wxStrncpy(fa.szFacename, sFacename, WXSIZEOF(fa.szFacename));
+} // end of wxNativeFontInfo::SetFaceName
+
+void wxNativeFontInfo::SetFamily(
+  wxFontFamily                      eFamily
+)
+{
+    wxString                        sFacename;
 
 
-        case wxFONTENCODING_ISO8859_7:
-            fAttrs.usCodePage = 850;  // what is greek
+    switch (eFamily)
+    {
+        case wxSCRIPT:
+            sFacename = _T("Script");
             break;
 
             break;
 
-        case wxFONTENCODING_ISO8859_8:
-            fAttrs.usCodePage = 850; // what is hebrew?
+        case wxDECORATIVE:
+            sFacename = _T("Times New Roman");
             break;
 
             break;
 
-        case wxFONTENCODING_ISO8859_9:
-            fAttrs.usCodePage = 857;
+        case wxROMAN:
+            sFacename = _T("Times New Roman");
             break;
 
             break;
 
-        case wxFONTENCODING_ISO8859_11:
-            fAttrs.usCodePage = 850; // what is thai
+        case wxTELETYPE:
+        case wxMODERN:
+            sFacename = _T("Courier New");
             break;
 
             break;
 
-        case wxFONTENCODING_CP437:
-            fAttrs.usCodePage = 437;
+        case wxSWISS:
+            sFacename = _T("WarpSans");
             break;
 
             break;
 
+        case wxDEFAULT:
         default:
         default:
-            wxFAIL_MSG(wxT("unsupported encoding"));
-            // fall through
+            sFacename = _T("Helv");
+    }
 
 
-        case wxFONTENCODING_SYSTEM:
-            fAttrs.usCodePage = 850; // what is ANSI?
-            break;
+    if (!wxStrlen(fa.szFacename) )
+    {
+        SetFaceName(sFacename);
     }
     }
+} // end of wxNativeFontInfo::SetFamily
 
 
-// Now cheking 
-    fLid = 1;
-    hps  = ::WinGetPS( HWND_DESKTOP );
+void wxNativeFontInfo::SetEncoding(
+  wxFontEncoding                    eEncoding
+)
+{
+    wxNativeEncodingInfo            vInfo;
 
 
-    long numLids = ::GpiQueryNumberSetIds( hps );
-    long gpiError;
-    
-    // First we should generate unique id
-    if( numLids )
+    if ( !wxGetNativeFontEncoding( eEncoding
+                                  ,&vInfo
+                                 ))
     {
     {
-        long Types[255];
-        STR8 Names[255];
-        long lIds[255];
-
-        if( !GpiQuerySetIds(hps, numLids, Types, Names, lIds) )
+#if wxUSE_FONTMAP
+        if (wxTheFontMapper->GetAltForEncoding( eEncoding
+                                               ,&vInfo
+                                              ))
         {
         {
-            ::WinReleasePS( hps );
-            return 0;
+            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);
+            }
         }
         }
-      
-        for(unsigned long LCNum = 0; LCNum < numLids; LCNum++)
-            if(lIds[LCNum] == fLid)
-               ++fLid;
-        if(fLid > 254)  // wow, no id available!
+        else
+#endif // wxUSE_FONTMAP
         {
         {
-           ::WinReleasePS( hps );
-           return 0;
+            // unsupported encoding, replace with the default
+            vInfo.charset = 850;
         }
     }
         }
     }
+    fa.usCodePage = vInfo.charset;
+} // end of wxNativeFontInfo::SetFaceName
 
 
-    // now building facestring
-    if(::GpiQueryFaceString(hps, ff_face.c_str(), &fName, FACESIZE, fAttrs.szFacename) == GPI_ERROR)
-    {
-       ::WinReleasePS( hps );
-       return 0;
-    }
+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
 
 
-    // now creating font
-    WXHFONT hFont = (WXHFONT)0;
+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
+
+// ----------------------------------------------------------------------------
+// wxFont
+// ----------------------------------------------------------------------------
+
+void wxFont::Init()
+{
+} // end of wxFont::Init
 
 
-    if(::GpiCreateLogFont(hps, NULL, fLid, &fAttrs) != GPI_ERROR)
-       M_FONTDATA->m_hFont = hFont = (WXHFONT)1;
+bool wxFont::Create(
+  const wxNativeFontInfo&           rInfo
+, WXHFONT                           hFont
+)
+{
+    UnRef();
+    m_refData = new wxFontRefData( rInfo
+                                  ,hFont
+                                 );
+    RealizeResource();
+    return TRUE;
+} // end of wxFont::Create
 
 
-    if( hFont )
-        ::GpiDeleteSetId(hps, fLid);
+wxFont::wxFont(
+  const wxString&                   rsFontdesc
+)
+{
+    wxNativeFontInfo                vInfo;
 
 
-    ::WinReleasePS( hps );
+    if (vInfo.FromString(rsFontdesc))
+        (void)Create(vInfo);
+} // end of wxFont::wxFont
 
 
-    if ( !hFont )
+// ----------------------------------------------------------------------------
+// Constructor for a font. Note that the real construction is done
+// in wxDC::SetFont, when information is available about scaling etc.
+// ----------------------------------------------------------------------------
+bool wxFont::Create(
+  int                               nPointSize
+, int                               nFamily
+, int                               nStyle
+, int                               nWeight
+, bool                              bUnderlined
+, const wxString&                   rsFaceName
+, wxFontEncoding                    vEncoding
+)
+{
+    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 (nPointSize == wxDEFAULT)
     {
     {
-        wxLogLastError("CreateFont");
+        nPointSize = wxNORMAL_FONT->GetPointSize();
     }
     }
+    m_refData = new wxFontRefData( nPointSize
+                                  ,nFamily
+                                  ,nStyle
+                                  ,nWeight
+                                  ,bUnderlined
+                                  ,rsFaceName
+                                  ,vEncoding
+                                 );
+    RealizeResource();
+    return TRUE;
+} // end of wxFont::Create
 
 
-    return hFont != 0;
-}
+wxFont::~wxFont()
+{
+} // end of wxFont::~wxFont
 
 
-bool wxFont::FreeResource(bool force)
+// ----------------------------------------------------------------------------
+// real implementation
+// Boris' Kovalenko comments:
+//   Because OS/2 fonts are associated with PS we can not create the font
+//   here, but we may check that font definition is true
+// ----------------------------------------------------------------------------
+
+bool wxFont::RealizeResource()
 {
     if ( GetResourceHandle() )
     {
 {
     if ( GetResourceHandle() )
     {
-// TODO:
-//        if ( !::DeleteObject((HFONT) M_FONTDATA->m_hFont) )
-//        {
-//            wxLogLastError("DeleteObject(font)");
-//        }
-
-        M_FONTDATA->m_hFont = 0;
+        return TRUE;
+    }
+    return M_FONTDATA->Alloc(this);
+} // end of wxFont::RealizeResource
 
 
+bool wxFont::FreeResource(
+  bool                              bForce
+)
+{
+    if (GetResourceHandle())
+    {
+        M_FONTDATA->Free();
         return TRUE;
     }
     return FALSE;
         return TRUE;
     }
     return FALSE;
-}
+} // end of wxFont::FreeResource
 
 WXHANDLE wxFont::GetResourceHandle()
 {
 
 WXHANDLE wxFont::GetResourceHandle()
 {
-    if ( !M_FONTDATA )
-        return 0;
-    else
-        return (WXHANDLE)M_FONTDATA->m_hFont ;
-}
+    return GetHFONT();
+} // end of wxFont::GetResourceHandle
+
+WXHFONT wxFont::GetHFONT() const
+{
+    return M_FONTDATA ? M_FONTDATA->GetHFONT() : 0;
+} // end of wxFont::GetHFONT
 
 bool wxFont::IsFree() const
 {
 
 bool wxFont::IsFree() const
 {
-    return (M_FONTDATA && (M_FONTDATA->m_hFont == 0));
-}
+    return M_FONTDATA && (M_FONTDATA->GetHFONT() == 0);
+} // end of wxFont::IsFree
 
 void wxFont::Unshare()
 {
 
 void wxFont::Unshare()
 {
@@ -438,71 +941,98 @@ void wxFont::Unshare()
         UnRef();
         m_refData = ref;
     }
         UnRef();
         m_refData = ref;
     }
-}
+} // end of wxFont::Unshare
 
 // ----------------------------------------------------------------------------
 // change font attribute: we recreate font when doing it
 // ----------------------------------------------------------------------------
 
 
 // ----------------------------------------------------------------------------
 // change font attribute: we recreate font when doing it
 // ----------------------------------------------------------------------------
 
-void wxFont::SetPointSize(int pointSize)
+void wxFont::SetPointSize(
+  int                               nPointSize
+)
 {
     Unshare();
 
 {
     Unshare();
 
-    M_FONTDATA->m_pointSize = pointSize;
+    M_FONTDATA->SetPointSize(nPointSize);
 
     RealizeResource();
 
     RealizeResource();
-}
+} // end of wxFont::SetPointSize
 
 
-void wxFont::SetFamily(int family)
+void wxFont::SetFamily(
+  int                               nFamily
+)
 {
     Unshare();
 
 {
     Unshare();
 
-    M_FONTDATA->m_family = family;
+    M_FONTDATA->SetFamily(nFamily);
 
     RealizeResource();
 
     RealizeResource();
-}
+} // end of wxFont::SetFamily
 
 
-void wxFont::SetStyle(int style)
+void wxFont::SetStyle(
+  int                               nStyle
+)
 {
     Unshare();
 
 {
     Unshare();
 
-    M_FONTDATA->m_style = style;
+    M_FONTDATA->SetStyle(nStyle);
 
     RealizeResource();
 
     RealizeResource();
-}
+} // end of wxFont::SetStyle
 
 
-void wxFont::SetWeight(int weight)
+void wxFont::SetWeight(
+  int                               nWeight
+)
 {
     Unshare();
 
 {
     Unshare();
 
-    M_FONTDATA->m_weight = weight;
+    M_FONTDATA->SetWeight(nWeight);
 
     RealizeResource();
 
     RealizeResource();
-}
+} // end of wxFont::SetWeight
 
 
-void wxFont::SetFaceName(const wxString& faceName)
+void wxFont::SetFaceName(
+  const wxString&                   rsFaceName
+)
 {
     Unshare();
 
 {
     Unshare();
 
-    M_FONTDATA->m_faceName = faceName;
+    M_FONTDATA->SetFaceName(rsFaceName);
 
     RealizeResource();
 
     RealizeResource();
-}
+} // end of wxFont::SetFaceName
 
 
-void wxFont::SetUnderlined(bool underlined)
+void wxFont::SetUnderlined(
+  bool                              bUnderlined
+)
 {
     Unshare();
 
 {
     Unshare();
 
-    M_FONTDATA->m_underlined = underlined;
+    M_FONTDATA->SetUnderlined(bUnderlined);
 
     RealizeResource();
 
     RealizeResource();
-}
+} // end of wxFont::SetUnderlined
+
+void wxFont::SetEncoding(
+  wxFontEncoding                    vEncoding
+)
+{
+    Unshare();
 
 
-void wxFont::SetEncoding(wxFontEncoding encoding)
+    M_FONTDATA->SetEncoding(vEncoding);
+
+    RealizeResource();
+} // end of wxFont::SetEncoding
+
+void wxFont::SetNativeFontInfo(
+  const wxNativeFontInfo&           rInfo
+)
 {
     Unshare();
 
 {
     Unshare();
 
-    M_FONTDATA->m_encoding = encoding;
+    FreeResource();
+
+    *M_FONTDATA = wxFontRefData(rInfo);
 
     RealizeResource();
 }
 
     RealizeResource();
 }
@@ -513,44 +1043,81 @@ void wxFont::SetEncoding(wxFontEncoding encoding)
 
 int wxFont::GetPointSize() const
 {
 
 int wxFont::GetPointSize() const
 {
-    return M_FONTDATA->m_pointSize;
-}
+    wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+
+    return M_FONTDATA->GetPointSize();
+} // end of wxFont::GetPointSize
 
 int wxFont::GetFamily() const
 {
 
 int wxFont::GetFamily() const
 {
-    return M_FONTDATA->m_family;
-}
+    wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
 
 
-int wxFont::GetFontId() const
-{
-    return M_FONTDATA->m_fontId;
-}
+    return M_FONTDATA->GetFamily();
+} // end of wxFont::GetFamily
 
 int wxFont::GetStyle() const
 {
 
 int wxFont::GetStyle() const
 {
-    return M_FONTDATA->m_style;
-}
+    wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+
+    return M_FONTDATA->GetStyle();
+} // end of wxFont::GetStyle
 
 int wxFont::GetWeight() const
 {
 
 int wxFont::GetWeight() const
 {
-    return M_FONTDATA->m_weight;
+    wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+
+    return M_FONTDATA->GetWeight();
 }
 
 bool wxFont::GetUnderlined() const
 {
 }
 
 bool wxFont::GetUnderlined() const
 {
-    return M_FONTDATA->m_underlined;
-}
+    wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
+
+    return M_FONTDATA->GetUnderlined();
+} // end of wxFont::GetUnderlined
 
 wxString wxFont::GetFaceName() const
 {
 
 wxString wxFont::GetFaceName() const
 {
-    wxString str;
-    if ( M_FONTDATA )
-        str = M_FONTDATA->m_faceName ;
-    return str;
-}
+    wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
+
+    return M_FONTDATA->GetFaceName();
+} // end of wxFont::GetFaceName
 
 wxFontEncoding wxFont::GetEncoding() const
 {
 
 wxFontEncoding wxFont::GetEncoding() const
 {
-    return M_FONTDATA->m_encoding;
-}
+    wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
+
+    return M_FONTDATA->GetEncoding();
+} // end of wxFont::GetEncoding
+
+wxNativeFontInfo* wxFont::GetNativeFontInfo() const
+{
+    if (M_FONTDATA->HasNativeFontInfo())
+        return new wxNativeFontInfo(M_FONTDATA->GetNativeFontInfo());
+    return 0;
+} // end of wxFont::GetNativeFontInfo
+
+//
+// Internal use only method to set the FONTMETRICS array
+//
+void wxFont::SetFM(
+  PFONTMETRICS                      pFM
+, int                               nNumFonts
+)
+{
+    M_FONTDATA->SetFM(pFM);
+    M_FONTDATA->SetNumFonts(nNumFonts);
+} // end of wxFont::SetFM
+
+
+void wxFont::SetPS(
+  HPS                               hPS
+)
+{
+    Unshare();
+
+    M_FONTDATA->SetPS(hPS);
+
+    RealizeResource();
+} // end of wxFont::SetUnderlined