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