1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFont class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "font.h"
19 #include "wx/gdiobj.h"
22 class WXDLLEXPORT wxFont
;
24 // For every wxFont, there must be a font for each display and scale requested.
25 // So these objects are stored in wxFontRefData::m_fonts
26 class WXDLLEXPORT wxXFont
: public wxObject
32 WXFontStructPtr m_fontStruct
; // XFontStruct
33 WXFontList m_fontList
; // Motif XmFontList
34 WXDisplay
* m_display
; // XDisplay
35 int m_scale
; // Scale * 100
38 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
40 friend class WXDLLEXPORT wxFont
;
43 wxFontRefData(const wxFontRefData
& data
);
57 #define M_FONTDATA ((wxFontRefData *)m_refData)
59 WXDLLEXPORT_DATA(extern const char*) wxEmptyString
;
62 class WXDLLEXPORT wxFont
: public wxGDIObject
64 DECLARE_DYNAMIC_CLASS(wxFont
)
67 wxFont(int pointSize
, int family
, int style
, int weight
, bool underlined
= FALSE
, const wxString
& faceName
= wxEmptyString
);
68 inline wxFont(const wxFont
& font
) { Ref(font
); }
72 bool Create(int pointSize
, int family
, int style
, int weight
, bool underlined
= FALSE
, const wxString
& faceName
= wxEmptyString
);
74 virtual bool Ok() const { return (m_refData
!= NULL
) ; }
76 inline int GetPointSize() const { return M_FONTDATA
->m_pointSize
; }
77 inline int GetFamily() const { return M_FONTDATA
->m_family
; }
78 inline int GetStyle() const { return M_FONTDATA
->m_style
; }
79 inline int GetWeight() const { return M_FONTDATA
->m_weight
; }
80 wxString
GetFamilyString() const ;
81 wxString
GetFaceName() const ;
82 wxString
GetStyleString() const ;
83 wxString
GetWeightString() const ;
84 inline bool GetUnderlined() const { return M_FONTDATA
->m_underlined
; }
86 void SetPointSize(int pointSize
);
87 void SetFamily(int family
);
88 void SetStyle(int style
);
89 void SetWeight(int weight
);
90 void SetFaceName(const wxString
& faceName
);
91 void SetUnderlined(bool underlined
);
93 inline wxFont
& operator = (const wxFont
& font
) { if (*this == font
) return (*this); Ref(font
); return *this; }
94 inline bool operator == (const wxFont
& font
) const { return m_refData
== font
.m_refData
; }
95 inline bool operator != (const wxFont
& font
) const { return m_refData
!= font
.m_refData
; }
99 // Find an existing, or create a new, XFontStruct
100 // based on this wxFont and the given scale. Append the
101 // font to list in the private data for future reference.
103 // TODO This is a fairly basic implementation, that doesn't
104 // allow for different facenames, and also doesn't do a mapping
105 // between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.)
106 // and the fonts that are available on a particular system.
107 // Maybe we need to scan the user's machine to build up a profile
108 // of the fonts and a mapping file.
110 // Return font struct, and optionally the Motif font list
111 wxXFont
* GetInternalFont(double scale
= 1.0, WXDisplay
* display
= NULL
) const;
113 // These two are helper functions for convenient access of the above.
114 inline WXFontStructPtr
GetFontStruct(double scale
= 1.0, WXDisplay
* display
= NULL
) const
116 wxXFont
* f
= GetInternalFont(scale
, display
);
117 return (f
? f
->m_fontStruct
: (WXFontStructPtr
) 0);
119 WXFontList
GetFontList(double scale
= 1.0, WXDisplay
* display
= NULL
) const
121 wxXFont
* f
= GetInternalFont(scale
, display
);
122 return (f
? f
->m_fontList
: (WXFontList
) 0);
125 WXFontStructPtr
LoadQueryFont(int pointSize
, int family
, int style
,
126 int weight
, bool underlined
) const;
128 bool RealizeResource();