]> git.saurik.com Git - wxWidgets.git/blob - include/wx/private/fontmgr.h
Fix wxPropertyGrid::GetPropertyRect when the last item is collapsed.
[wxWidgets.git] / include / wx / private / fontmgr.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/fontmgr.h
3 // Purpose: font management for ports that don't have their own
4 // Author: Vaclav Slavik
5 // Created: 2006-11-18
6 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
7 // (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_PRIVATE_FONTMGR_H_
12 #define _WX_PRIVATE_FONTMGR_H_
13
14 #include "wx/list.h"
15 #include "wx/fontutil.h"
16
17 class wxFontsManager;
18 class wxFontInstance;
19 class wxFontInstanceList;
20 class wxFontFace;
21 class wxFontBundle;
22 class wxFontBundleHash;
23 class wxFontMgrFontRefData;
24
25 WX_DECLARE_LIST(wxFontBundle, wxFontBundleList);
26
27 /**
28 This class represents single font face with set parameters (point size,
29 antialiasing).
30 */
31 class wxFontInstanceBase
32 {
33 protected:
34 wxFontInstanceBase(float ptSize, bool aa) : m_ptSize(ptSize), m_aa(aa) {}
35 virtual ~wxFontInstanceBase() {}
36
37 public:
38 float GetPointSize() const { return m_ptSize; }
39 bool IsAntiAliased() const { return m_aa; }
40
41 protected:
42 float m_ptSize;
43 bool m_aa;
44 };
45
46
47 /// This class represents loaded font face (bundle+weight+italics).
48 class wxFontFaceBase
49 {
50 protected:
51 /// Ctor. Creates object with reference count = 0, Acquire() must be
52 /// called after the object is created.
53 wxFontFaceBase();
54 virtual ~wxFontFaceBase();
55
56 public:
57 /// Increases reference count of the face
58 virtual void Acquire();
59
60 /**
61 Decreases reference count of the face. Call this when you no longer
62 use the object returned by wxFontBundle. Note that this doesn't destroy
63 the object, but only optionally shuts it down, so it's possible to
64 call Acquire() and Release() more than once.
65 */
66 virtual void Release();
67
68 /**
69 Returns instance of the font at given size.
70
71 @param ptSize point size of the font to create; note that this is
72 a float and not integer, it should be wxFont's point
73 size multipled by wxDC's scale factor
74 @param aa should the font be antialiased?
75 */
76 virtual wxFontInstance *GetFontInstance(float ptSize, bool aa);
77
78 protected:
79 /// Called to create a new instance of the font by GetFontInstance() if
80 /// it wasn't found it cache.
81 virtual wxFontInstance *CreateFontInstance(float ptSize, bool aa) = 0;
82
83 protected:
84 unsigned m_refCnt;
85 wxFontInstanceList *m_instances;
86 };
87
88 /**
89 This class represents font bundle. Font bundle is set of faces that have
90 the same name, but differ in weight and italics.
91 */
92 class wxFontBundleBase
93 {
94 public:
95 wxFontBundleBase();
96 virtual ~wxFontBundleBase();
97
98 /// Returns name of the bundle
99 virtual wxString GetName() const = 0;
100
101 /// Returns true if the font is fixe-width
102 virtual bool IsFixed() const = 0;
103
104 /// Type of faces in the bundle
105 enum FaceType
106 {
107 // NB: values of these constants are set so that it's possible to
108 // make OR-combinations of them and still get valid enum element
109 FaceType_Regular = 0,
110 FaceType_Italic = 1,
111 FaceType_Bold = 2,
112 FaceType_BoldItalic = FaceType_Italic | FaceType_Bold,
113
114 FaceType_Max
115 };
116
117 /// Returns true if the given face is available
118 bool HasFace(FaceType type) const { return m_faces[type] != NULL; }
119
120 /**
121 Returns font face object that can be used to render font of given type.
122
123 Note that this method can only be called if HasFace(type) returns true.
124
125 Acquire() was called on the returned object, you must call Release()
126 when you stop using it.
127 */
128 wxFontFace *GetFace(FaceType type) const;
129
130 /**
131 Returns font face object that can be used to render given font.
132
133 Acquire() was called on the returned object, you must call Release()
134 when you stop using it.
135 */
136 wxFontFace *GetFaceForFont(const wxFontMgrFontRefData& font) const;
137
138 protected:
139 wxFontFace *m_faces[FaceType_Max];
140 };
141
142
143 /**
144 Base class for wxFontsManager class, which manages the list of all
145 available fonts and their loaded instances.
146 */
147 class wxFontsManagerBase
148 {
149 protected:
150 wxFontsManagerBase();
151 virtual ~wxFontsManagerBase();
152
153 public:
154 /// Returns the font manager singleton, creating it if it doesn't exist
155 static wxFontsManager *Get();
156
157 /// Called by wxApp to shut down the manager
158 static void CleanUp();
159
160 /// Returns list of all available font bundles
161 const wxFontBundleList& GetBundles() const { return *m_list; }
162
163 /**
164 Returns object representing font bundle with the given name.
165
166 The returned object is owned by wxFontsManager, you must not delete it.
167 */
168 wxFontBundle *GetBundle(const wxString& name) const;
169
170 /**
171 Returns object representing font bundle that can be used to render
172 given font.
173
174 The returned object is owned by wxFontsManager, you must not delete it.
175 */
176 wxFontBundle *GetBundleForFont(const wxFontMgrFontRefData& font) const;
177
178 /// This method must be called by derived
179 void AddBundle(wxFontBundle *bundle);
180
181 /// Returns default facename for given wxFont family
182 virtual wxString GetDefaultFacename(wxFontFamily family) const = 0;
183
184 private:
185 wxFontBundleHash *m_hash;
186 wxFontBundleList *m_list;
187
188 protected:
189 static wxFontsManager *ms_instance;
190 };
191
192
193
194 #if defined(__WXDFB__)
195 #include "wx/dfb/private/fontmgr.h"
196 #endif
197
198
199
200 /// wxFontMgrFontRefData implementation using wxFontsManager classes
201 class wxFontMgrFontRefData : public wxGDIRefData
202 {
203 public:
204 wxFontMgrFontRefData(int size = wxDEFAULT,
205 wxFontFamily family = wxFONTFAMILY_DEFAULT,
206 wxFontStyle style = wxFONTSTYLE_NORMAL,
207 wxFontWeight weight = wxFONTWEIGHT_NORMAL,
208 bool underlined = false,
209 const wxString& faceName = wxEmptyString,
210 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
211 wxFontMgrFontRefData(const wxFontMgrFontRefData& data);
212 ~wxFontMgrFontRefData();
213
214 wxFontBundle *GetFontBundle() const;
215 wxFontInstance *GetFontInstance(float scale, bool antialiased) const;
216
217 bool IsFixedWidth() const { return GetFontBundle()->IsFixed(); }
218
219 const wxNativeFontInfo *GetNativeFontInfo() const { return &m_info; }
220
221 int GetPointSize() const { return m_info.pointSize; }
222 wxString GetFaceName() const { return m_info.faceName; }
223 wxFontFamily GetFamily() const { return m_info.family; }
224 wxFontStyle GetStyle() const { return m_info.style; }
225 wxFontWeight GetWeight() const { return m_info.weight; }
226 bool GetUnderlined() const { return m_info.underlined; }
227 wxFontEncoding GetEncoding() const { return m_info.encoding; }
228
229 void SetPointSize(int pointSize);
230 void SetFamily(wxFontFamily family);
231 void SetStyle(wxFontStyle style);
232 void SetWeight(wxFontWeight weight);
233 void SetFaceName(const wxString& faceName);
234 void SetUnderlined(bool underlined);
235 void SetEncoding(wxFontEncoding encoding);
236
237 private:
238 void EnsureValidFont();
239
240 wxNativeFontInfo m_info;
241
242 wxFontFace *m_fontFace;
243 wxFontBundle *m_fontBundle;
244 bool m_fontValid;
245 };
246
247 #endif // _WX_PRIVATE_FONTMGR_H_