Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CEGUIFont.h

Go to the documentation of this file.
00001 /************************************************************************
00002         filename:       CEGUIFont.h
00003         created:        21/2/2004
00004         author:         Paul D Turner
00005         
00006         purpose:        Defines interface for the Font class
00007 *************************************************************************/
00008 /*************************************************************************
00009     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012     This library is free software; you can redistribute it and/or
00013     modify it under the terms of the GNU Lesser General Public
00014     License as published by the Free Software Foundation; either
00015     version 2.1 of the License, or (at your option) any later version.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Lesser General Public License for more details.
00021 
00022     You should have received a copy of the GNU Lesser General Public
00023     License along with this library; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #ifndef _CEGUIFont_h_
00027 #define _CEGUIFont_h_
00028 
00029 #include "CEGUIBase.h"
00030 #include "CEGUIString.h"
00031 #include "CEGUIRect.h"
00032 #include "CEGUIVector.h"
00033 #include "CEGUIColourRect.h"
00034 
00035 #include <map>
00036 
00037 
00038 #if defined(_MSC_VER)
00039 #       pragma warning(push)
00040 #       pragma warning(disable : 4251)
00041 #endif
00042 
00043 
00044 // Start of CEGUI namespace section
00045 namespace CEGUI
00046 {
00051 enum CEGUIBASE_API FontFlag
00052 {
00053         Default,                        
00054         NoAntiAlias             
00055 };
00056 
00057 
00062 enum CEGUIBASE_API TextFormatting
00063 {
00064         LeftAligned,                    
00065         RightAligned,                   
00066         Centred,                                
00067         WordWrapLeftAligned,    
00068         WordWrapRightAligned,   
00069         WordWrapCentred                 
00070 };
00071 
00080 class CEGUIBASE_API Font
00081 {
00082         friend class Font_xmlHandler;
00083 public:
00084         /*************************************************************************
00085                 Constants
00086         *************************************************************************/
00087         static const uint32             DefaultColour;                  
00088 
00089 
00090         /*************************************************************************
00091                 Text drawing methods
00092         *************************************************************************/
00126         uint    drawText(const String& text, const Rect& draw_area, float z, const Rect& clip_rect, TextFormatting fmt, const ColourRect& colours, float x_scale = 1.0f, float y_scale = 1.0f) const;
00127 
00128 
00158         uint    drawText(const String& text, const Rect& draw_area, float z, const Rect& clip_rect, TextFormatting fmt, float x_scale = 1.0f, float y_scale = 1.0f) const
00159         { return drawText(text, draw_area, z, clip_rect, fmt, ColourRect(DefaultColour, DefaultColour, DefaultColour, DefaultColour), x_scale, y_scale); }
00160 
00161 
00188         void    drawText(const String& text, const Rect& draw_area, float z, const Rect& clip_rect, float x_scale = 1.0f, float y_scale = 1.0f) const
00189         { drawText(text, draw_area, z, clip_rect, LeftAligned, ColourRect(DefaultColour, DefaultColour, DefaultColour, DefaultColour), x_scale, y_scale); }
00190 
00191 
00223         uint    drawText(const String& text, const Rect& draw_area, float z, TextFormatting fmt, const ColourRect& colours, float x_scale = 1.0f, float y_scale = 1.0f) const
00224         { return drawText(text, draw_area, z, draw_area, fmt, colours, x_scale, y_scale); }
00225 
00226 
00254         uint    drawText(const String& text, const Rect& draw_area, float z, TextFormatting fmt, float x_scale = 1.0f, float y_scale = 1.0f) const
00255         { return drawText(text, draw_area, z, draw_area, fmt, ColourRect(DefaultColour, DefaultColour, DefaultColour, DefaultColour), x_scale, y_scale); }
00256 
00257 
00282         void    drawText(const String& text, const Rect& draw_area, float z, float x_scale = 1.0f, float y_scale = 1.0f) const
00283         { drawText(text, draw_area, z, draw_area, LeftAligned, ColourRect(DefaultColour, DefaultColour, DefaultColour, DefaultColour), x_scale, y_scale); }
00284 
00285 
00313         void    drawText(const String& text, const Vector3& position, const Rect& clip_rect, const ColourRect& colours, float x_scale = 1.0f, float y_scale = 1.0f) const
00314         { drawText(text, Rect(position.d_x, position.d_y, position.d_x, position.d_y), position.d_z, clip_rect, LeftAligned, colours, x_scale, y_scale); }
00315 
00316 
00340         void    drawText(const String& text, const Vector3& position, const Rect& clip_rect, float x_scale = 1.0f, float y_scale = 1.0f) const
00341         { drawText(text, Rect(position.d_x, position.d_y, position.d_x, position.d_y), position.d_z, clip_rect, LeftAligned, ColourRect(DefaultColour, DefaultColour, DefaultColour, DefaultColour), x_scale, y_scale); }
00342 
00343 
00344         /*************************************************************************
00345                 Methods to define available glyphs (truetype fonts only)
00346         *************************************************************************/
00365         void    defineFontGlyphs(const String& glyph_set);
00366 
00367 
00392         void    defineFontGlyphs(utf32 first_code_point, utf32 last_code_point);
00393 
00394 
00405         void    setNativeResolution(const Size& size);
00406 
00407 
00418         void    notifyScreenResolution(const Size& size);
00419 
00420 
00431         void    setAutoScalingEnabled(bool setting);
00432 
00433 
00446         void    setAntiAliased(bool setting);
00447 
00448 
00449         /*************************************************************************
00450                 Informational methods
00451         *************************************************************************/
00465         float   getTextExtent(const String& text, float x_scale = 1.0f) const;
00466 
00467 
00478         float   getLineSpacing(float y_scale = 1.0f) const              {return d_lineSpacing * y_scale;}
00479 
00480 
00491         float   getFontHeight(float y_scale = 1.0f) const       {return d_lineHeight * y_scale;}
00492 
00493 
00504         float   getBaseline(float y_scale = 1.0f) const                 {return d_max_bearingY * y_scale;}
00505 
00506 
00525         uint    getCharAtPixel(const String& text, float pixel, float x_scale = 1.0f) const             {return getCharAtPixel(text, 0, pixel, x_scale);}
00526 
00527 
00550         uint    getCharAtPixel(const String& text, uint start_char, float pixel, float x_scale = 1.0f) const;
00551 
00552 
00560         const String&   getName(void) const             {return d_name;}
00561 
00562 
00570         Size    getNativeResolution(void) const {return Size(d_nativeHorzRes, d_nativeVertRes);}
00571 
00572 
00580         bool    isAutoScaled(void) const                {return d_autoScale;}
00581 
00582 
00593         bool    isCodepointAvailable(utf32 cp) const            {return (d_cp_map.find(cp) != d_cp_map.end());}
00594 
00595 
00618         uint    getFormattedLineCount(const String& text, const Rect& format_area, TextFormatting fmt, float x_scale = 1.0f) const;
00619 
00620 
00642         float   getFormattedTextExtent(const String& text, const Rect& format_area, TextFormatting fmt, float x_scale = 1.0f) const;
00643 
00644 
00653         bool    isAntiAliased(void) const;
00654 
00655 
00663         const String& getAvailableGlyphs(void) const;
00664 
00665 
00675         uint    getPointSize(void) const;
00676 
00677 
00678 private:
00679         /*************************************************************************
00680                 Implementation Constants
00681         *************************************************************************/
00682         static const char       FontSchemaName[];                       
00683         static const uint       InterGlyphPadSpace;                     
00684 
00685 
00686         /*************************************************************************
00687                 Friends so that only FontManager can create and destroy font objects
00688         *************************************************************************/
00689         friend class FontManager;
00690 
00691         /*************************************************************************
00692                 Private forward refs
00693         *************************************************************************/
00694         struct FontImplData;
00695 
00696 
00697         /*************************************************************************
00698                 Construction & Destruction
00699         *************************************************************************/
00718         Font(const String& filename, const String& resourceGroup, FontImplData* dat);
00719 
00720 
00746         Font(const String& name, const String& fontname, const String& resourceGroup, uint size, uint flags, FontImplData* dat);
00747 
00748 
00777         Font(const String& name, const String& fontname, const String& resourceGroup, uint size, uint flags, const String& glyph_set, FontImplData* dat);
00778 
00779 
00811         Font(const String& name, const String& fontname, const String& resourceGroup, uint size, uint flags, utf32 first_code_point, utf32 last_code_point, FontImplData* dat);
00812 
00813 
00814 public:         // For luabind support
00819         ~Font(void);
00820 
00821 
00822 private:
00823         /*************************************************************************
00824                 Implementation Methods
00825         *************************************************************************/
00840         void    load(const String& filename, const String& resourceGroup);
00841 
00842 
00850         void    unload(void);
00851 
00852 
00864         uint    getRequiredTextureSize(const String& glyph_set);
00865 
00866 
00881         uint    getRequiredTextureSize(utf32 first_code_point, utf32 last_code_point);
00882 
00883 
00902         void    createFontGlyphSet(const String& glyph_set, uint size, uint32* buffer);
00903 
00904 
00926         void    createFontGlyphSet(utf32 first_code_point, utf32 last_code_point, uint size, uint32* buffer);
00927 
00928 
00942         void    drawGlyphToBuffer(uint32* buffer, uint buf_width);
00943 
00944 
00949         uint    drawWrappedText(const String& text, const Rect& draw_area, float z, const Rect& clip_rect, TextFormatting fmt, const ColourRect& colours, float x_scale = 1.0f, float y_scale = 1.0f) const;
00950 
00951 
00956         uint    getNextWord(const String& in_string, uint start_idx, String& out_string) const;
00957 
00958 
00963         void    drawTextLine(const String& text, const Vector3& position, const Rect& clip_rect, const ColourRect& colours, float x_scale = 1.0f, float y_scale = 1.0f) const;
00964 
00965 
00970         void    createFontFromFT_Face(uint size, uint horzDpi, uint vertDpi);
00971 
00972 
00977         void    updateFontScaling(void);
00978 
00979 
00984         void    calculateStaticVertSpacing(void);
00985 
00990         void    constructor_impl(const String& name, const String& fontname, const String& resourceGroup, uint size, uint flags, const String& glyph_set);
00991 
00992 
01008         void    defineFontGlyphs_impl(void);
01009 
01010 
01015         float   getWrappedTextExtent(const String& text, float wrapWidth, float x_scale = 1.0f) const;
01016 
01017 
01018         /*************************************************************************
01019                 Implementation structs
01020         *************************************************************************/
01025         struct glyphDat
01026         {
01027                 const Image*    d_image;                                
01028                 uint                    d_horz_advance;                 
01029                 uint                    d_horz_advance_unscaled;        
01030         };
01031 
01032         /*************************************************************************
01033                 Implementation Data
01034         *************************************************************************/
01035         typedef         std::map<utf32, glyphDat>               CodepointMap;
01036         CodepointMap    d_cp_map;       
01037 
01038         String          d_name;                 
01039         Imageset*       d_glyph_images; 
01040 
01041         bool    d_freetype;                     
01042         float   d_lineHeight;           
01043         float   d_lineSpacing;          
01044         float   d_max_bearingY;         
01045         uint    d_maxGlyphHeight;       
01046 
01047         FontImplData*   d_impldat;      
01048         uint            d_ptSize;               
01049         String          d_glyphset;             
01050 
01051         // auto-scaling fields
01052         bool    d_autoScale;                    
01053         float   d_horzScaling;                  
01054         float   d_vertScaling;                  
01055         float   d_nativeHorzRes;                
01056         float   d_nativeVertRes;                
01057 
01058         bool    d_antiAliased;                  
01059 };
01060 
01061 } // End of  CEGUI namespace section
01062 
01063 #if defined(_MSC_VER)
01064 #       pragma warning(pop)
01065 #endif
01066 
01067 
01068 #endif  // end of guard _CEGUIFont_h_

Generated on Wed Feb 16 12:41:06 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1