Crazy Eddie's GUI System  0.8.4
Font.h
00001 /***********************************************************************
00002     created:    21/2/2004
00003     author:     Paul D Turner <paul@cegui.org.uk>
00004 *************************************************************************/
00005 /***************************************************************************
00006  *   Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
00007  *
00008  *   Permission is hereby granted, free of charge, to any person obtaining
00009  *   a copy of this software and associated documentation files (the
00010  *   "Software"), to deal in the Software without restriction, including
00011  *   without limitation the rights to use, copy, modify, merge, publish,
00012  *   distribute, sublicense, and/or sell copies of the Software, and to
00013  *   permit persons to whom the Software is furnished to do so, subject to
00014  *   the following conditions:
00015  *
00016  *   The above copyright notice and this permission notice shall be
00017  *   included in all copies or substantial portions of the Software.
00018  *
00019  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00023  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00024  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00025  *   OTHER DEALINGS IN THE SOFTWARE.
00026  ***************************************************************************/
00027 #ifndef _CEGUIFont_h_
00028 #define _CEGUIFont_h_
00029 
00030 #include "CEGUI/Base.h"
00031 #include "CEGUI/PropertySet.h"
00032 #include "CEGUI/EventSet.h"
00033 #include "CEGUI/String.h"
00034 #include "CEGUI/XMLSerializer.h"
00035 #include "CEGUI/FontGlyph.h"
00036 
00037 #include <map>
00038 
00039 #if defined(_MSC_VER)
00040 #   pragma warning(push)
00041 #   pragma warning(disable : 4251)
00042 #endif
00043 
00044 // Start of CEGUI namespace section
00045 namespace CEGUI
00046 {
00058 class CEGUIEXPORT Font :
00059     public PropertySet,
00060     public EventSet,
00061     public AllocatedObject<Font>
00062 {
00063 public:
00065     static const argb_t DefaultColour;
00066 
00068     static const String EventNamespace;
00074     static const String EventRenderSizeChanged;
00075 
00077     virtual ~Font();
00078 
00080     const String& getName() const;
00081 
00083     const String& getTypeName() const;
00084 
00086     const String& getFileName() const;
00087     
00099     bool isCodepointAvailable(utf32 cp) const
00100     { return (d_cp_map.find(cp) != d_cp_map.end()); }
00101 
00141     float drawText(GeometryBuffer& buffer, const String& text,
00142                    const Vector2f& position, const Rectf* clip_rect,
00143                    const ColourRect& colours, const float space_extra = 0.0f,
00144                    const float x_scale = 1.0f, const float y_scale = 1.0f) const;
00145 
00153     void setNativeResolution(const Sizef& size);
00154 
00163     const Sizef& getNativeResolution() const;
00164 
00174     void setAutoScaled(const AutoScaledMode auto_scaled);
00175 
00183     AutoScaledMode getAutoScaled() const;
00184 
00192     virtual void notifyDisplaySizeChanged(const Sizef& size);
00193 
00206     float getLineSpacing(float y_scale = 1.0f) const
00207     { return d_height * y_scale; }
00208 
00221     float getFontHeight(float y_scale = 1.0f) const
00222     { return (d_ascender - d_descender) * y_scale; }
00223 
00236     float getBaseline(float y_scale = 1.0f) const
00237     { return d_ascender * y_scale; }
00238 
00270     float getTextExtent(const String& text, float x_scale = 1.0f) const;
00271 
00300     float getTextAdvance(const String& text, float x_scale = 1.0f) const;
00301 
00325     size_t getCharAtPixel(const String& text, float pixel,
00326                           float x_scale = 1.0f) const
00327     { return getCharAtPixel(text, 0, pixel, x_scale); }
00328 
00357     size_t getCharAtPixel(const String& text, size_t start_char, float pixel,
00358                           float x_scale = 1.0f) const;
00359 
00370     static void setDefaultResourceGroup(const String& resourceGroup)
00371     { d_defaultResourceGroup = resourceGroup; }
00372 
00381     static const String& getDefaultResourceGroup()
00382     { return d_defaultResourceGroup; }
00383 
00394     void writeXMLToStream(XMLSerializer& xml_stream) const;
00395 
00408     const FontGlyph* getGlyphData(utf32 codepoint) const;
00409 
00410 protected:
00412     Font(const String& name, const String& type_name, const String& filename,
00413          const String& resource_group, const AutoScaledMode auto_scaled,
00414          const Sizef& native_res);
00415 
00430     virtual void rasterise(utf32 start_codepoint, utf32 end_codepoint) const;
00431 
00433     virtual void updateFont() = 0;
00434 
00436     virtual void writeXMLToStream_impl(XMLSerializer& xml_stream) const = 0;
00437 
00439     void addFontProperties();
00440 
00442     virtual void onRenderSizeChanged(FontEventArgs& args);
00443 
00449     void setMaxCodepoint(utf32 codepoint);
00450 
00452     virtual const FontGlyph* findFontGlyph(const utf32 codepoint) const;
00453 
00455     String d_name;
00457     String d_type;
00459     String d_filename;
00461     String d_resourceGroup;
00463     static String d_defaultResourceGroup;
00464 
00466     float d_ascender;
00468     float d_descender;
00470     float d_height;
00471 
00473     AutoScaledMode d_autoScaled;
00475     Sizef d_nativeResolution;
00477     float d_horzScaling;
00479     float d_vertScaling;
00480 
00482     utf32 d_maxCodepoint;
00483 
00497     uint* d_glyphPageLoaded;
00498 
00500     typedef std::map<utf32, FontGlyph, std::less<utf32>
00501         CEGUI_MAP_ALLOC(utf32, FontGlyph)> CodepointMap;
00503     mutable CodepointMap d_cp_map;
00504 };
00505 
00506 
00507 
00508 } // End of  CEGUI namespace section
00509 
00510 #if defined(_MSC_VER)
00511 #   pragma warning(pop)
00512 #endif
00513 
00514 
00515 #endif  // end of guard _CEGUIFont_h_
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends