]> git.saurik.com Git - wxWidgets.git/blame - include/wx/private/fontmgr.h
Update vc10 build file versions to 3.0.0.
[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
d7ae4a62
VS
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
17class wxFontsManager;
18class wxFontInstance;
19class wxFontInstanceList;
20class wxFontFace;
21class wxFontBundle;
22class wxFontBundleHash;
23class wxFontMgrFontRefData;
24
25WX_DECLARE_LIST(wxFontBundle, wxFontBundleList);
26
27/**
28 This class represents single font face with set parameters (point size,
29 antialiasing).
30 */
31class wxFontInstanceBase
32{
33protected:
34 wxFontInstanceBase(float ptSize, bool aa) : m_ptSize(ptSize), m_aa(aa) {}
35 virtual ~wxFontInstanceBase() {}
36
37public:
38 float GetPointSize() const { return m_ptSize; }
39 bool IsAntiAliased() const { return m_aa; }
40
41protected:
42 float m_ptSize;
43 bool m_aa;
44};
45
46
47/// This class represents loaded font face (bundle+weight+italics).
48class wxFontFaceBase
49{
50protected:
51 /// Ctor. Creates object with reference count = 0, Acquire() must be
52 /// called after the object is created.
53 wxFontFaceBase();
54 virtual ~wxFontFaceBase();
55
56public:
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
78protected:
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
83protected:
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 */
92class wxFontBundleBase
93{
94public:
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
138protected:
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 */
147class wxFontsManagerBase
148{
149protected:
150 wxFontsManagerBase();
151 virtual ~wxFontsManagerBase();
152
153public:
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
184private:
185 wxFontBundleHash *m_hash;
186 wxFontBundleList *m_list;
187
188protected:
189 static wxFontsManager *ms_instance;
190};
191
192
193
0e1f8ea4 194#if defined(__WXDFB__)
d7ae4a62
VS
195 #include "wx/dfb/private/fontmgr.h"
196#endif
197
198
199
200/// wxFontMgrFontRefData implementation using wxFontsManager classes
8f884a0d 201class wxFontMgrFontRefData : public wxGDIRefData
d7ae4a62
VS
202{
203public:
204 wxFontMgrFontRefData(int size = wxDEFAULT,
5a2c086a
VZ
205 wxFontFamily family = wxFONTFAMILY_DEFAULT,
206 wxFontStyle style = wxFONTSTYLE_NORMAL,
207 wxFontWeight weight = wxFONTWEIGHT_NORMAL,
d7ae4a62
VS
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; }
5a2c086a
VZ
223 wxFontFamily GetFamily() const { return m_info.family; }
224 wxFontStyle GetStyle() const { return m_info.style; }
225 wxFontWeight GetWeight() const { return m_info.weight; }
d7ae4a62
VS
226 bool GetUnderlined() const { return m_info.underlined; }
227 wxFontEncoding GetEncoding() const { return m_info.encoding; }
228
229 void SetPointSize(int pointSize);
5a2c086a
VZ
230 void SetFamily(wxFontFamily family);
231 void SetStyle(wxFontStyle style);
232 void SetWeight(wxFontWeight weight);
d7ae4a62
VS
233 void SetFaceName(const wxString& faceName);
234 void SetUnderlined(bool underlined);
235 void SetEncoding(wxFontEncoding encoding);
236
d7ae4a62
VS
237private:
238 void EnsureValidFont();
239
240 wxNativeFontInfo m_info;
d7ae4a62
VS
241
242 wxFontFace *m_fontFace;
243 wxFontBundle *m_fontBundle;
244 bool m_fontValid;
245};
246
247#endif // _WX_PRIVATE_FONTMGR_H_