]>
git.saurik.com Git - wxWidgets.git/blob - 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
6 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
7 // (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PRIVATE_FONTMGR_H_
12 #define _WX_PRIVATE_FONTMGR_H_
15 #include "wx/fontutil.h"
19 class wxFontInstanceList
;
22 class wxFontBundleHash
;
23 class wxFontMgrFontRefData
;
25 WX_DECLARE_LIST(wxFontBundle
, wxFontBundleList
);
28 This class represents single font face with set parameters (point size,
31 class wxFontInstanceBase
34 wxFontInstanceBase(float ptSize
, bool aa
) : m_ptSize(ptSize
), m_aa(aa
) {}
35 virtual ~wxFontInstanceBase() {}
38 float GetPointSize() const { return m_ptSize
; }
39 bool IsAntiAliased() const { return m_aa
; }
47 /// This class represents loaded font face (bundle+weight+italics).
51 /// Ctor. Creates object with reference count = 0, Acquire() must be
52 /// called after the object is created.
54 virtual ~wxFontFaceBase();
57 /// Increases reference count of the face
58 virtual void Acquire();
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.
66 virtual void Release();
69 Returns instance of the font at given size.
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?
76 virtual wxFontInstance
*GetFontInstance(float ptSize
, bool aa
);
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;
85 wxFontInstanceList
*m_instances
;
89 This class represents font bundle. Font bundle is set of faces that have
90 the same name, but differ in weight and italics.
92 class wxFontBundleBase
96 virtual ~wxFontBundleBase();
98 /// Returns name of the bundle
99 virtual wxString
GetName() const = 0;
101 /// Returns true if the font is fixe-width
102 virtual bool IsFixed() const = 0;
104 /// Type of faces in the bundle
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,
112 FaceType_BoldItalic
= FaceType_Italic
| FaceType_Bold
,
117 /// Returns true if the given face is available
118 bool HasFace(FaceType type
) const { return m_faces
[type
] != NULL
; }
121 Returns font face object that can be used to render font of given type.
123 Note that this method can only be called if HasFace(type) returns true.
125 Acquire() was called on the returned object, you must call Release()
126 when you stop using it.
128 wxFontFace
*GetFace(FaceType type
) const;
131 Returns font face object that can be used to render given font.
133 Acquire() was called on the returned object, you must call Release()
134 when you stop using it.
136 wxFontFace
*GetFaceForFont(const wxFontMgrFontRefData
& font
) const;
139 wxFontFace
*m_faces
[FaceType_Max
];
144 Base class for wxFontsManager class, which manages the list of all
145 available fonts and their loaded instances.
147 class wxFontsManagerBase
150 wxFontsManagerBase();
151 virtual ~wxFontsManagerBase();
154 /// Returns the font manager singleton, creating it if it doesn't exist
155 static wxFontsManager
*Get();
157 /// Called by wxApp to shut down the manager
158 static void CleanUp();
160 /// Returns list of all available font bundles
161 const wxFontBundleList
& GetBundles() const { return *m_list
; }
164 Returns object representing font bundle with the given name.
166 The returned object is owned by wxFontsManager, you must not delete it.
168 wxFontBundle
*GetBundle(const wxString
& name
) const;
171 Returns object representing font bundle that can be used to render
174 The returned object is owned by wxFontsManager, you must not delete it.
176 wxFontBundle
*GetBundleForFont(const wxFontMgrFontRefData
& font
) const;
178 /// This method must be called by derived
179 void AddBundle(wxFontBundle
*bundle
);
181 /// Returns default facename for given wxFont family
182 virtual wxString
GetDefaultFacename(wxFontFamily family
) const = 0;
185 wxFontBundleHash
*m_hash
;
186 wxFontBundleList
*m_list
;
189 static wxFontsManager
*ms_instance
;
194 #if defined(__WXDFB__)
195 #include "wx/dfb/private/fontmgr.h"
200 /// wxFontMgrFontRefData implementation using wxFontsManager classes
201 class wxFontMgrFontRefData
: public wxGDIRefData
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();
214 wxFontBundle
*GetFontBundle() const;
215 wxFontInstance
*GetFontInstance(float scale
, bool antialiased
) const;
217 bool IsFixedWidth() const { return GetFontBundle()->IsFixed(); }
219 const wxNativeFontInfo
*GetNativeFontInfo() const { return &m_info
; }
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
; }
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
);
238 void EnsureValidFont();
240 wxNativeFontInfo m_info
;
242 wxFontFace
*m_fontFace
;
243 wxFontBundle
*m_fontBundle
;
247 #endif // _WX_PRIVATE_FONTMGR_H_