Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Font.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 - 2011 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 "CEGUI/Base.h"
32 #include "CEGUI/PropertySet.h"
33 #include "CEGUI/EventSet.h"
34 #include "CEGUI/String.h"
35 #include "CEGUI/XMLSerializer.h"
36 #include "CEGUI/FontGlyph.h"
37 
38 #include <map>
39 
40 #if defined(_MSC_VER)
41 # pragma warning(push)
42 # pragma warning(disable : 4251)
43 #endif
44 
45 // Start of CEGUI namespace section
46 namespace CEGUI
47 {
59 class CEGUIEXPORT Font :
60  public PropertySet,
61  public EventSet,
62  public AllocatedObject<Font>
63 {
64 public:
66  static const argb_t DefaultColour;
67 
69  static const String EventNamespace;
76 
78  virtual ~Font();
79 
81  const String& getName() const;
82 
84  const String& getTypeName() const;
85 
87  const String& getFileName() const;
88 
100  bool isCodepointAvailable(utf32 cp) const
101  { return (d_cp_map.find(cp) != d_cp_map.end()); }
102 
142  float drawText(GeometryBuffer& buffer, const String& text,
143  const Vector2f& position, const Rectf* clip_rect,
144  const ColourRect& colours, const float space_extra = 0.0f,
145  const float x_scale = 1.0f, const float y_scale = 1.0f) const;
146 
154  void setNativeResolution(const Sizef& size);
155 
164  const Sizef& getNativeResolution() const;
165 
175  void setAutoScaled(const AutoScaledMode auto_scaled);
176 
184  AutoScaledMode getAutoScaled() const;
185 
193  virtual void notifyDisplaySizeChanged(const Sizef& size);
194 
207  float getLineSpacing(float y_scale = 1.0f) const
208  { return d_height * y_scale; }
209 
222  float getFontHeight(float y_scale = 1.0f) const
223  { return (d_ascender - d_descender) * y_scale; }
224 
237  float getBaseline(float y_scale = 1.0f) const
238  { return d_ascender * y_scale; }
239 
271  float getTextExtent(const String& text, float x_scale = 1.0f) const;
272 
301  float getTextAdvance(const String& text, float x_scale = 1.0f) const;
302 
326  size_t getCharAtPixel(const String& text, float pixel,
327  float x_scale = 1.0f) const
328  { return getCharAtPixel(text, 0, pixel, x_scale); }
329 
358  size_t getCharAtPixel(const String& text, size_t start_char, float pixel,
359  float x_scale = 1.0f) const;
360 
371  static void setDefaultResourceGroup(const String& resourceGroup)
372  { d_defaultResourceGroup = resourceGroup; }
373 
382  static const String& getDefaultResourceGroup()
383  { return d_defaultResourceGroup; }
384 
395  void writeXMLToStream(XMLSerializer& xml_stream) const;
396 
409  const FontGlyph* getGlyphData(utf32 codepoint) const;
410 
411 protected:
413  Font(const String& name, const String& type_name, const String& filename,
414  const String& resource_group, const AutoScaledMode auto_scaled,
415  const Sizef& native_res);
416 
431  virtual void rasterise(utf32 start_codepoint, utf32 end_codepoint) const;
432 
434  virtual void updateFont() = 0;
435 
437  virtual void writeXMLToStream_impl(XMLSerializer& xml_stream) const = 0;
438 
440  void addFontProperties();
441 
443  virtual void onRenderSizeChanged(FontEventArgs& args);
444 
450  void setMaxCodepoint(utf32 codepoint);
451 
453  virtual const FontGlyph* findFontGlyph(const utf32 codepoint) const;
454 
465 
467  float d_ascender;
469  float d_descender;
471  float d_height;
472 
481 
484 
499 
501  typedef std::map<utf32, FontGlyph, std::less<utf32>
502  CEGUI_MAP_ALLOC(utf32, FontGlyph)> CodepointMap;
505 };
506 
507 
508 
509 } // End of CEGUI namespace section
510 
511 #if defined(_MSC_VER)
512 # pragma warning(pop)
513 #endif
514 
515 
516 #endif // end of guard _CEGUIFont_h_