Crazy Eddies GUI System  0.7.8
CEGUIFont.h
1 /***********************************************************************
2  filename: CEGUIFont.h
3  created: 21/2/2004
4  author: Paul D Turner <paul@cegui.org.uk>
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef _CEGUIFont_h_
29 #define _CEGUIFont_h_
30 
31 #include "CEGUIBase.h"
32 #include "CEGUIPropertySet.h"
33 #include "CEGUIString.h"
34 #include "CEGUIXMLSerializer.h"
35 #include "CEGUIFontGlyph.h"
36 
37 #include <map>
38 
39 #if defined(_MSC_VER)
40 # pragma warning(push)
41 # pragma warning(disable : 4251)
42 #endif
43 
44 // Start of CEGUI namespace section
45 namespace CEGUI
46 {
58 class CEGUIEXPORT Font : public PropertySet
59 {
60 public:
62  static const argb_t DefaultColour;
63 
65  virtual ~Font();
66 
68  const String& getName() const;
69 
71  const String& getTypeName() const;
72 
84  bool isCodepointAvailable(utf32 cp) const
85  { return (d_cp_map.find(cp) != d_cp_map.end()); }
86 
124  void drawText(GeometryBuffer& buffer, const String& text,
125  const Vector2& position, const Rect* clip_rect,
126  const ColourRect& colours, const float space_extra = 0.0f,
127  const float x_scale = 1.0f, const float y_scale = 1.0f);
128 
136  void setNativeResolution(const Size& size);
137 
146  Size getNativeResolution() const;
147 
156  void setAutoScaled(const bool auto_scaled);
157 
166  bool isAutoScaled() const;
167 
175  virtual void notifyDisplaySizeChanged(const Size& size);
176 
189  float getLineSpacing(float y_scale = 1.0f) const
190  { return d_height * y_scale; }
191 
204  float getFontHeight(float y_scale = 1.0f) const
205  { return (d_ascender - d_descender) * y_scale; }
206 
219  float getBaseline(float y_scale = 1.0f) const
220  { return d_ascender * y_scale; }
221 
239  float getTextExtent(const String& text, float x_scale = 1.0f) const;
240 
264  size_t getCharAtPixel(const String& text, float pixel,
265  float x_scale = 1.0f) const
266  { return getCharAtPixel(text, 0, pixel, x_scale); }
267 
296  size_t getCharAtPixel(const String& text, size_t start_char, float pixel,
297  float x_scale = 1.0f) const;
298 
309  static void setDefaultResourceGroup(const String& resourceGroup)
310  { d_defaultResourceGroup = resourceGroup; }
311 
320  static const String& getDefaultResourceGroup()
321  { return d_defaultResourceGroup; }
322 
333  void writeXMLToStream(XMLSerializer& xml_stream) const;
334 
347  const FontGlyph* getGlyphData(utf32 codepoint) const;
348 
349 protected:
351  Font(const String& name, const String& type_name, const String& filename,
352  const String& resource_group, const bool auto_scaled,
353  const float native_horz_res, const float native_vert_res);
354 
369  virtual void rasterise(utf32 start_codepoint, utf32 end_codepoint) const;
370 
372  virtual void updateFont() = 0;
373 
375  virtual void writeXMLToStream_impl(XMLSerializer& xml_stream) const = 0;
376 
378  void addFontProperties();
379 
385  void setMaxCodepoint(utf32 codepoint);
386 
397 
399  float d_ascender;
401  float d_descender;
403  float d_height;
404 
415 
418 
433 
435  typedef std::map<utf32, FontGlyph> CodepointMap;
438 };
439 
440 } // End of CEGUI namespace section
441 
442 #if defined(_MSC_VER)
443 # pragma warning(pop)
444 #endif
445 
446 
447 #endif // end of guard _CEGUIFont_h_