Crazy Eddie's GUI System  0.8.7
Font.h
1 /***********************************************************************
2  created: 21/2/2004
3  author: Paul D Turner <paul@cegui.org.uk>
4 *************************************************************************/
5 /***************************************************************************
6  * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #ifndef _CEGUIFont_h_
28 #define _CEGUIFont_h_
29 
30 #include "CEGUI/Base.h"
31 #include "CEGUI/PropertySet.h"
32 #include "CEGUI/EventSet.h"
33 #include "CEGUI/String.h"
34 #include "CEGUI/XMLSerializer.h"
35 #include "CEGUI/FontGlyph.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 :
59  public PropertySet,
60  public EventSet,
61  public AllocatedObject<Font>
62 {
63 public:
65  static const argb_t DefaultColour;
66 
68  static const String EventNamespace;
75 
77  virtual ~Font();
78 
80  const String& getName() const;
81 
83  const String& getTypeName() const;
84 
86  const String& getFileName() const;
87 
99  bool isCodepointAvailable(utf32 cp) const
100  { return (d_cp_map.find(cp) != d_cp_map.end()); }
101 
141  float drawText(GeometryBuffer& buffer, const String& text,
142  const Vector2f& position, const Rectf* clip_rect,
143  const ColourRect& colours, const float space_extra = 0.0f,
144  const float x_scale = 1.0f, const float y_scale = 1.0f) const;
145 
153  void setNativeResolution(const Sizef& size);
154 
163  const Sizef& getNativeResolution() const;
164 
174  void setAutoScaled(const AutoScaledMode auto_scaled);
175 
184 
192  virtual void notifyDisplaySizeChanged(const Sizef& size);
193 
206  float getLineSpacing(float y_scale = 1.0f) const
207  { return d_height * y_scale; }
208 
221  float getFontHeight(float y_scale = 1.0f) const
222  { return (d_ascender - d_descender) * y_scale; }
223 
236  float getBaseline(float y_scale = 1.0f) const
237  { return d_ascender * y_scale; }
238 
270  float getTextExtent(const String& text, float x_scale = 1.0f) const;
271 
300  float getTextAdvance(const String& text, float x_scale = 1.0f) const;
301 
325  size_t getCharAtPixel(const String& text, float pixel,
326  float x_scale = 1.0f) const
327  { return getCharAtPixel(text, 0, pixel, x_scale); }
328 
357  size_t getCharAtPixel(const String& text, size_t start_char, float pixel,
358  float x_scale = 1.0f) const;
359 
370  static void setDefaultResourceGroup(const String& resourceGroup)
371  { d_defaultResourceGroup = resourceGroup; }
372 
382  { return d_defaultResourceGroup; }
383 
394  void writeXMLToStream(XMLSerializer& xml_stream) const;
395 
408  const FontGlyph* getGlyphData(utf32 codepoint) const;
409 
410 protected:
412  Font(const String& name, const String& type_name, const String& filename,
413  const String& resource_group, const AutoScaledMode auto_scaled,
414  const Sizef& native_res);
415 
430  virtual void rasterise(utf32 start_codepoint, utf32 end_codepoint) const;
431 
433  virtual void updateFont() = 0;
434 
436  virtual void writeXMLToStream_impl(XMLSerializer& xml_stream) const = 0;
437 
440 
442  virtual void onRenderSizeChanged(FontEventArgs& args);
443 
449  void setMaxCodepoint(utf32 codepoint);
450 
452  virtual const FontGlyph* findFontGlyph(const utf32 codepoint) const;
453 
464 
466  float d_ascender;
468  float d_descender;
470  float d_height;
471 
480 
483 
498 
500  typedef std::map<utf32, FontGlyph, std::less<utf32>
501  CEGUI_MAP_ALLOC(utf32, FontGlyph)> CodepointMap;
504 };
505 
506 
507 
508 } // End of CEGUI namespace section
509 
510 #if defined(_MSC_VER)
511 # pragma warning(pop)
512 #endif
513 
514 
515 #endif // end of guard _CEGUIFont_h_
CEGUI::GeometryBuffer
Abstract class defining the interface for objects that buffer geometry for later rendering.
Definition: GeometryBuffer.h:44
CEGUI::Font
Class that encapsulates a typeface.
Definition: Font.h:62
CEGUI::FontEventArgs
EventArgs based class that is used for notifications regarding Font objects.
Definition: InputEvent.h:381
CEGUI::Font::rasterise
virtual void rasterise(utf32 start_codepoint, utf32 end_codepoint) const
This function prepares a certain range of glyphs to be ready for displaying. This means that after re...
CEGUI::Font::d_defaultResourceGroup
static String d_defaultResourceGroup
Holds default resource group for font loading.
Definition: Font.h:463
CEGUI::Font::CodepointMap
std::map< utf32, FontGlyph, std::less< utf32 > CEGUI_MAP_ALLOC(utf32, FontGlyph)> CodepointMap
Definition of CodepointMap type.
Definition: Font.h:501
CEGUI::Font::d_filename
String d_filename
Name of the file used to create this font (font file or imagset)
Definition: Font.h:459
CEGUI::Font::getGlyphData
const FontGlyph * getGlyphData(utf32 codepoint) const
Return a pointer to the glyphDat struct for the given codepoint, or 0 if the codepoint does not have ...
CEGUI::Font::setNativeResolution
void setNativeResolution(const Sizef &size)
Set the native resolution for this Font.
CEGUI::Font::updateFont
virtual void updateFont()=0
Update the font as needed, according to the current parameters.
CEGUI::Font::getName
const String & getName() const
Return the string holding the font name.
CEGUI::Font::d_maxCodepoint
utf32 d_maxCodepoint
Maximal codepoint for font glyphs.
Definition: Font.h:482
CEGUI::Font::Font
Font(const String &name, const String &type_name, const String &filename, const String &resource_group, const AutoScaledMode auto_scaled, const Sizef &native_res)
Constructor.
CEGUI::Font::d_autoScaled
AutoScaledMode d_autoScaled
which mode should we use for auto-scaling
Definition: Font.h:473
CEGUI::Font::d_resourceGroup
String d_resourceGroup
Name of the font file's resource group.
Definition: Font.h:461
CEGUI::Font::setAutoScaled
void setAutoScaled(const AutoScaledMode auto_scaled)
Enable or disable auto-scaling for this Font.
CEGUI::Font::~Font
virtual ~Font()
Destructor.
CEGUI::XMLSerializer
Class used to create XML Document.
Definition: XMLSerializer.h:87
CEGUI::Font::d_glyphPageLoaded
uint * d_glyphPageLoaded
This bitmap holds information about loaded 'pages' of glyphs. A glyph page is a set of 256 codepoints...
Definition: Font.h:497
CEGUI::Font::setDefaultResourceGroup
static void setDefaultResourceGroup(const String &resourceGroup)
Sets the default resource group to be used when loading font data.
Definition: Font.h:370
CEGUI
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
CEGUI::Font::drawText
float drawText(GeometryBuffer &buffer, const String &text, const Vector2f &position, const Rectf *clip_rect, const ColourRect &colours, const float space_extra=0.0f, const float x_scale=1.0f, const float y_scale=1.0f) const
Draw text into a specified area of the display.
CEGUI::EventSet
Interface providing event signaling and handling.
Definition: EventSet.h:167
CEGUI::PropertySet
Interface providing introspection capabilities.
Definition: PropertySet.h:108
CEGUI::AllocatedObject
Definition: MemoryAllocatedObject.h:110
CEGUI::Vector2< float >
CEGUI::ColourRect
Class that holds details of colours for the four corners of a rectangle.
Definition: ColourRect.h:45
CEGUI::Font::d_name
String d_name
Name of this font.
Definition: Font.h:455
CEGUI::Font::getFileName
const String & getFileName() const
Return the filename of the used font.
CEGUI::Font::EventRenderSizeChanged
static const String EventRenderSizeChanged
Definition: Font.h:74
CEGUI::Font::getAutoScaled
AutoScaledMode getAutoScaled() const
Checks whether this font is being auto-scaled and how.
CEGUI::Font::d_type
String d_type
Type name string for this font (not used internally)
Definition: Font.h:457
CEGUI::Font::getFontHeight
float getFontHeight(float y_scale=1.0f) const
return the exact pixel height of the font.
Definition: Font.h:221
CEGUI::Font::DefaultColour
static const argb_t DefaultColour
Colour value used whenever a colour is not specified.
Definition: Font.h:65
CEGUI::Font::isCodepointAvailable
bool isCodepointAvailable(utf32 cp) const
Return whether this Font can draw the specified code-point.
Definition: Font.h:99
CEGUI::Font::d_vertScaling
float d_vertScaling
current vertical scaling factor.
Definition: Font.h:479
CEGUI::Font::getLineSpacing
float getLineSpacing(float y_scale=1.0f) const
Return the pixel line spacing value for.
Definition: Font.h:206
CEGUI::Font::findFontGlyph
virtual const FontGlyph * findFontGlyph(const utf32 codepoint) const
finds FontGlyph in map and returns it, or 0 if none.
CEGUI::Font::getNativeResolution
const Sizef & getNativeResolution() const
Return the native display size for this Font. This is only relevant if the Font is being auto-scaled.
CEGUI::AutoScaledMode
AutoScaledMode
Definition: Image.h:40
CEGUI::Font::getTextExtent
float getTextExtent(const String &text, float x_scale=1.0f) const
Return the pixel width of the specified text if rendered with this Font.
CEGUI::argb_t
uint32 argb_t
32 bit ARGB representation of a colour.
Definition: Colour.h:38
CEGUI::FontGlyph
internal class representing a single font glyph.
Definition: FontGlyph.h:44
CEGUI::Font::getCharAtPixel
size_t getCharAtPixel(const String &text, size_t start_char, float pixel, float x_scale=1.0f) const
Return the index of the closest text character in String text, starting at character index start_char...
CEGUI::Font::d_nativeResolution
Sizef d_nativeResolution
native resolution for this Font.
Definition: Font.h:475
CEGUI::Font::getBaseline
float getBaseline(float y_scale=1.0f) const
Return the number of pixels from the top of the highest glyph to the baseline.
Definition: Font.h:236
CEGUI::Font::getCharAtPixel
size_t getCharAtPixel(const String &text, float pixel, float x_scale=1.0f) const
Return the index of the closest text character in String text that corresponds to pixel location pixe...
Definition: Font.h:325
CEGUI::Font::getTypeName
const String & getTypeName() const
Return the type of the font.
CEGUI::Font::d_ascender
float d_ascender
maximal font ascender (pixels above the baseline)
Definition: Font.h:466
CEGUI::Size< float >
CEGUI::Font::d_height
float d_height
(ascender - descender) + linegap
Definition: Font.h:470
CEGUI::Font::addFontProperties
void addFontProperties()
Register all properties of this class.
CEGUI::String
String class used within the GUI system.
Definition: String.h:64
CEGUI::Font::writeXMLToStream
void writeXMLToStream(XMLSerializer &xml_stream) const
Writes an xml representation of this Font to out_stream.
CEGUI::Font::notifyDisplaySizeChanged
virtual void notifyDisplaySizeChanged(const Sizef &size)
Notify the Font that the display size may have changed.
CEGUI::Font::onRenderSizeChanged
virtual void onRenderSizeChanged(FontEventArgs &args)
event trigger function for when the font rendering size changes.
CEGUI::Font::setMaxCodepoint
void setMaxCodepoint(utf32 codepoint)
Set the maximal glyph index. This reserves the respective number of bits in the d_glyphPageLoaded arr...
CEGUI::Font::EventNamespace
static const String EventNamespace
Event namespace for font events.
Definition: Font.h:68
CEGUI::Rect< float >
CEGUI::Font::writeXMLToStream_impl
virtual void writeXMLToStream_impl(XMLSerializer &xml_stream) const =0
implementaion version of writeXMLToStream.
CEGUI::Font::d_cp_map
CodepointMap d_cp_map
Contains mappings from code points to Image objects.
Definition: Font.h:503
CEGUI::Font::d_descender
float d_descender
maximal font descender (negative pixels below the baseline)
Definition: Font.h:468
CEGUI::Font::getDefaultResourceGroup
static const String & getDefaultResourceGroup()
Returns the default resource group currently set for Fonts.
Definition: Font.h:381
CEGUI::Font::d_horzScaling
float d_horzScaling
current horizontal scaling factor.
Definition: Font.h:477
CEGUI::Font::getTextAdvance
float getTextAdvance(const String &text, float x_scale=1.0f) const
Return pixel advance of the specified text when rendered with this Font.