+friend class WXDLLEXPORT wxFont;
+
+public:
+ wxFontRefData()
+ {
+ Init(wxDEFAULT_FONT_SIZE, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE,
+ "", wxFONTENCODING_DEFAULT);
+ }
+
+ wxFontRefData(const wxFontRefData& data)
+ {
+ Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
+ data.m_underlined, data.m_faceName, data.m_encoding);
+
+ m_fontId = data.m_fontId;
+ }
+
+ wxFontRefData(int size,
+ int family,
+ int style,
+ int weight,
+ bool underlined,
+ const wxString& faceName,
+ wxFontEncoding encoding)
+ {
+ Init(size, family, style, weight, underlined, faceName, encoding);
+ }
+
+ wxFontRefData(const wxNativeFontInfo& info, WXHFONT hFont = 0)
+ {
+ Init(info, hFont);
+ }
+
+ 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);
+
+ void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0);
+
+ // If TRUE, the pointer to the actual font is temporary and SHOULD NOT BE
+ // DELETED by destructor
+ bool m_temporary;
+
+ int m_fontId;
+
+ // font characterstics
+ int m_pointSize;
+ int m_family;
+ int m_style;
+ int m_weight;
+ bool m_underlined;
+ wxString m_faceName;
+ wxFontEncoding m_encoding;
+
+ // Windows font handle
+ WXHFONT m_hFont;
+
+ // Native font info
+ wxNativeFontInfo m_nativeFontInfo;
+ bool m_nativeFontInfoOk;
+};
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// 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;
+
+ m_nativeFontInfoOk = FALSE;
+}
+
+void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont)
+{
+ // extract family from pitch-and-family
+ int lfFamily = info.lf.lfPitchAndFamily;
+ if ( lfFamily & FIXED_PITCH )
+ lfFamily -= FIXED_PITCH;
+ if ( lfFamily & VARIABLE_PITCH )
+ lfFamily -= VARIABLE_PITCH;
+
+ switch ( lfFamily )
+ {
+ case FF_ROMAN:
+ m_family = wxROMAN;
+ break;
+
+ case FF_SWISS:
+ m_family = wxSWISS;
+ break;
+
+ case FF_SCRIPT:
+ m_family = wxSCRIPT;
+ break;
+
+ case FF_MODERN:
+ m_family = wxMODERN;
+ break;
+
+ case FF_DECORATIVE:
+ m_family = wxDECORATIVE;
+ break;
+
+ default:
+ m_family = wxSWISS;
+ }
+
+ // weight and style
+ switch ( info.lf.lfWeight )
+ {
+ case FW_LIGHT:
+ m_weight = wxLIGHT;
+ break;
+
+ default:
+ case FW_NORMAL:
+ m_weight = wxNORMAL;
+ break;
+
+ case FW_BOLD:
+ m_weight = wxBOLD;
+ break;
+ }
+
+ m_style = info.lf.lfItalic ? wxITALIC : wxNORMAL;
+
+ m_underlined = info.lf.lfUnderline != 0;
+
+ m_faceName = info.lf.lfFaceName;
+
+ int height = abs(info.lf.lfHeight);
+
+ // remember that 1pt = 1/72inch
+ const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
+ m_pointSize = (int) (((72.0*((double)height))/(double) ppInch) + 0.5);
+
+ m_encoding = wxGetFontEncFromCharSet(info.lf.lfCharSet);
+
+ m_fontId = 0;
+ m_temporary = FALSE;
+
+ // 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_nativeFontInfoOk = TRUE;
+ m_nativeFontInfo = info;