+#ifndef WX_PRECOMP
+ #include <stdio.h>
+ #include "wx/list.h"
+ #include "wx/utils.h"
+ #include "wx/app.h"
+ #include "wx/log.h"
+#endif // WX_PRECOMP
+
+#include "wx/os2/private.h"
+
+#include "wx/fontutil.h"
+#include "wx/fontmap.h"
+#include "wx/encinfo.h"
+
+#include "wx/tokenzr.h"
+
+#include <malloc.h>
+
+// ----------------------------------------------------------------------------
+// wxFontRefData - the internal description of the font
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxFontRefData: public wxGDIRefData
+{
+public:
+ wxFontRefData()
+ {
+ Init(-1, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false,
+ wxEmptyString, wxFONTENCODING_DEFAULT);
+ }
+
+ wxFontRefData( int nSize
+ ,wxFontFamily nFamily
+ ,wxFontStyle nStyle
+ ,wxFontWeight nWeight
+ ,bool bUnderlined
+ ,const wxString& sFaceName
+ ,wxFontEncoding vEncoding
+ )
+ {
+ Init( nSize
+ ,nFamily
+ ,nStyle
+ ,nWeight
+ ,bUnderlined
+ ,sFaceName
+ ,vEncoding
+ );
+ }
+
+ wxFontRefData( const wxNativeFontInfo& rInfo
+ ,WXHFONT hFont = 0
+ ,WXHANDLE hPS = 0
+ )
+ {
+ Init( rInfo
+ ,hFont
+ ,hPS
+ );
+ }
+
+ wxFontRefData(const wxFontRefData& rData)
+ {
+ 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();
+
+ //
+ // Operations
+ //
+ bool Alloc(wxFont* pFont);
+ void Free(void);
+
+ //
+ // 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 wxFontFamily GetFamily(void) const
+ {
+ return m_nFamily;
+ }
+
+ inline wxFontStyle GetStyle(void) const
+ {
+ return m_bNativeFontInfoOk ? m_vNativeFontInfo.GetStyle()
+ : m_nStyle;
+ }
+
+ inline wxFontWeight 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;
+ }
+
+ inline void SetFamily(wxFontFamily nFamily)
+ {
+ m_nFamily = nFamily;
+ }
+
+ inline void SetStyle(wxFontStyle nStyle)
+ {
+ if (m_bNativeFontInfoOk)
+ m_vNativeFontInfo.SetStyle(nStyle);
+ else
+ m_nStyle = nStyle;
+ }
+
+ inline void SetWeight(wxFontWeight nWeight)
+ {
+ if (m_bNativeFontInfoOk)
+ m_vNativeFontInfo.SetWeight(nWeight);
+ else
+ m_nWeight = nWeight;
+ }
+
+ inline bool SetFaceName(const wxString& sFaceName)
+ {
+ if (m_bNativeFontInfoOk)
+ return m_vNativeFontInfo.SetFaceName(sFaceName);
+ else
+ m_sFaceName = sFaceName;
+ return true;
+ }
+
+ 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
+ ,wxFontFamily nFamily
+ ,wxFontStyle nStyle
+ ,wxFontWeight 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;
+ wxFontFamily m_nFamily;
+ wxFontStyle m_nStyle;
+ wxFontWeight 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
+
+#define M_FONTDATA ((wxFontRefData*)m_refData)
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxFontRefData
+// ----------------------------------------------------------------------------
+
+void wxFontRefData::Init(
+ int nPointSize
+, wxFontFamily nFamily
+, wxFontStyle nStyle
+, wxFontWeight 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 (hPS == NULLHANDLE)
+ {
+ m_hPS = ::WinGetPS(HWND_DESKTOP);
+ m_bInternalPS = true;
+ }
+ else
+ m_hPS = (HPS)hPS;
+
+ m_nFontId = 0;
+ m_bTemporary = false;
+ m_pFM = (PFONTMETRICS)NULL;
+ m_nNumFonts = 0;
+} // end of wxFontRefData::Init