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
); }
69 inline wxFont(const wxFont
* font
) { if (font
) Ref(*font
); }
73 bool Create(int pointSize
, int family
, int style
, int weight
, bool underlined
= FALSE
, const wxString
& faceName
= wxEmptyString
);
75 virtual bool Ok() const { return (m_refData
!= NULL
) ; }
77 inline int GetPointSize() const { return M_FONTDATA
->m_pointSize
; }
78 inline int GetFamily() const { return M_FONTDATA
->m_family
; }
79 inline int GetStyle() const { return M_FONTDATA
->m_style
; }
80 inline int GetWeight() const { return M_FONTDATA
->m_weight
; }
81 wxString
GetFamilyString() const ;
82 wxString
GetFaceName() const ;
83 wxString
GetStyleString() const ;
84 wxString
GetWeightString() const ;
85 inline bool GetUnderlined() const { return M_FONTDATA
->m_underlined
; }
87 void SetPointSize(int pointSize
);
88 void SetFamily(int family
);
89 void SetStyle(int style
);
90 void SetWeight(int weight
);
91 void SetFaceName(const wxString
& faceName
);
92 void SetUnderlined(bool underlined
);
94 inline wxFont
& operator = (const wxFont
& font
) { if (*this == font
) return (*this); Ref(font
); return *this; }
95 inline bool operator == (const wxFont
& font
) { return m_refData
== font
.m_refData
; }
96 inline bool operator != (const wxFont
& font
) { return m_refData
!= font
.m_refData
; }
100 // Find an existing, or create a new, XFontStruct
101 // based on this wxFont and the given scale. Append the
102 // font to list in the private data for future reference.
104 // TODO This is a fairly basic implementation, that doesn't
105 // allow for different facenames, and also doesn't do a mapping
106 // between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.)
107 // and the fonts that are available on a particular system.
108 // Maybe we need to scan the user's machine to build up a profile
109 // of the fonts and a mapping file.
111 // Return font struct, and optionally the Motif font list
112 wxXFont
* GetInternalFont(double scale
= 1.0, WXDisplay
* display
= NULL
) const;
114 // These two are helper functions for convenient access of the above.
115 inline WXFontStructPtr
GetFontStruct(double scale
= 1.0, WXDisplay
* display
= NULL
) const
117 wxXFont
* f
= GetInternalFont(scale
, display
);
118 return (f
? f
->m_fontStruct
: (WXFontStructPtr
) 0);
120 WXFontList
GetFontList(double scale
= 1.0, WXDisplay
* display
= NULL
) const
122 wxXFont
* f
= GetInternalFont(scale
, display
);
123 return (f
? f
->m_fontList
: (WXFontList
) 0);
126 WXFontStructPtr
LoadQueryFont(int pointSize
, int family
, int style
,
127 int weight
, bool underlined
) const;
129 bool RealizeResource();