Crazy Eddies GUI System: CEGUIFont.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

# CEGUIFont.h

    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 FontFlag
    00052 {
    00053         Default,
    00054         NoAntiAlias
    00055 };
    00056
    00057
    00062 enum TextFormatting
    00063 {
    00064         LeftAligned,
    00065         RightAligned,
    00066         Centred,
    00067         Justified,
    00068         WordWrapLeftAligned,
    00069         WordWrapRightAligned,
    00070         WordWrapCentred,
    00071         WordWrapJustified
    00072 };
    00073
    00082 class CEGUIEXPORT Font
    00083 {
    00084         friend class Font_xmlHandler;
    00085 public:
    00086         /*************************************************************************
    00087                 Constants
    00088         *************************************************************************/
    00089         static const argb_t             DefaultColour;
    00090
    00091
    00092         /*************************************************************************
    00093                 Text drawing methods
    00094         *************************************************************************/
    00128         size_t  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;
    00129
    00130
    00160         size_t  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
    00161         { return drawText(text, draw_area, z, clip_rect, fmt, ColourRect(DefaultColour, DefaultColour, DefaultColour, DefaultColour), x_scale, y_scale); }
    00162
    00163
    00190         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
    00191         { drawText(text, draw_area, z, clip_rect, LeftAligned, ColourRect(DefaultColour, DefaultColour, DefaultColour, DefaultColour), x_scale, y_scale); }
    00192
    00193
    00225         size_t  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
    00226         { return drawText(text, draw_area, z, draw_area, fmt, colours, x_scale, y_scale); }
    00227
    00228
    00256         size_t  drawText(const String& text, const Rect& draw_area, float z, TextFormatting fmt, float x_scale = 1.0f, float y_scale = 1.0f) const
    00257         { return drawText(text, draw_area, z, draw_area, fmt, ColourRect(DefaultColour, DefaultColour, DefaultColour, DefaultColour), x_scale, y_scale); }
    00258
    00259
    00284         void    drawText(const String& text, const Rect& draw_area, float z, float x_scale = 1.0f, float y_scale = 1.0f) const
    00285         { drawText(text, draw_area, z, draw_area, LeftAligned, ColourRect(DefaultColour, DefaultColour, DefaultColour, DefaultColour), x_scale, y_scale); }
    00286
    00287
    00315         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
    00316         { 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); }
    00317
    00318
    00342         void    drawText(const String& text, const Vector3& position, const Rect& clip_rect, float x_scale = 1.0f, float y_scale = 1.0f) const
    00343         { 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); }
    00344
    00345
    00346         /*************************************************************************
    00347                 Methods to define available glyphs (truetype fonts only)
    00348         *************************************************************************/
    00367         void    defineFontGlyphs(const String& glyph_set);
    00368
    00369
    00394         void    defineFontGlyphs(utf32 first_code_point, utf32 last_code_point);
    00395
    00396
    00407         void    setNativeResolution(const Size& size);
    00408
    00409
    00420         void    notifyScreenResolution(const Size& size);
    00421
    00422
    00433         void    setAutoScalingEnabled(bool setting);
    00434
    00435
    00448         void    setAntiAliased(bool setting);
    00449
    00450
    00451         /*************************************************************************
    00452                 Informational methods
    00453         *************************************************************************/
    00467         float   getTextExtent(const String& text, float x_scale = 1.0f) const;
    00468
    00469
    00480         float   getLineSpacing(float y_scale = 1.0f) const              {return d_lineSpacing * y_scale;}
    00481
    00482
    00493         float   getFontHeight(float y_scale = 1.0f) const       {return d_lineHeight * y_scale;}
    00494
    00495
    00506         float   getBaseline(float y_scale = 1.0f) const                 {return d_max_bearingY * y_scale;}
    00507
    00508
    00527         size_t  getCharAtPixel(const String& text, float pixel, float x_scale = 1.0f) const             {return getCharAtPixel(text, 0, pixel, x_scale);}
    00528
    00529
    00552         size_t  getCharAtPixel(const String& text, size_t start_char, float pixel, float x_scale = 1.0f) const;
    00553
    00554
    00562         const String&   getName(void) const             {return d_name;}
    00563
    00564
    00572         Size    getNativeResolution(void) const {return Size(d_nativeHorzRes, d_nativeVertRes);}
    00573
    00574
    00582         bool    isAutoScaled(void) const                {return d_autoScale;}
    00583
    00584
    00595         bool    isCodepointAvailable(utf32 cp) const            {return (d_cp_map.find(cp) != d_cp_map.end());}
    00596
    00597
    00620         size_t  getFormattedLineCount(const String& text, const Rect& format_area, TextFormatting fmt, float x_scale = 1.0f) const;
    00621
    00622
    00644         float   getFormattedTextExtent(const String& text, const Rect& format_area, TextFormatting fmt, float x_scale = 1.0f) const;
    00645
    00646
    00655         bool    isAntiAliased(void) const;
    00656
    00657
    00665         const String& getAvailableGlyphs(void) const;
    00666
    00667
    00677         uint    getPointSize(void) const;
    00678
    00679
    00680 private:
    00681         /*************************************************************************
    00682                 Implementation Constants
    00683         *************************************************************************/
    00684         static const char       FontSchemaName[];
    00685         static const uint       InterGlyphPadSpace;
    00686
    00687
    00688         /*************************************************************************
    00689                 Friends so that only FontManager can create and destroy font objects
    00690         *************************************************************************/
    00691         friend class FontManager;
    00692
    00693         /*************************************************************************
    00694                 Private forward refs
    00695         *************************************************************************/
    00696         struct FontImplData;
    00697
    00698
    00699         /*************************************************************************
    00700                 Construction & Destruction
    00701         *************************************************************************/
    00720         Font(const String& filename, const String& resourceGroup, FontImplData* dat);
    00721
    00722
    00748         Font(const String& name, const String& fontname, const String& resourceGroup, uint size, uint flags, FontImplData* dat);
    00749
    00750
    00779         Font(const String& name, const String& fontname, const String& resourceGroup, uint size, uint flags, const String& glyph_set, FontImplData* dat);
    00780
    00781
    00813         Font(const String& name, const String& fontname, const String& resourceGroup, uint size, uint flags, utf32 first_code_point, utf32 last_code_point, FontImplData* dat);
    00814
    00815
    00816 public:         // For luabind support
    00821         ~Font(void);
    00822
    00823
    00824 private:
    00825         /*************************************************************************
    00826                 Implementation Methods
    00827         *************************************************************************/
    00842         void    load(const String& filename, const String& resourceGroup);
    00843
    00844
    00852         void    unload(void);
    00853
    00854
    00866         uint    getRequiredTextureSize(const String& glyph_set);
    00867
    00868
    00883         uint    getRequiredTextureSize(utf32 first_code_point, utf32 last_code_point);
    00884
    00885
    00904         void    createFontGlyphSet(const String& glyph_set, uint size, argb_t* buffer);
    00905
    00906
    00928         void    createFontGlyphSet(utf32 first_code_point, utf32 last_code_point, uint size, argb_t* buffer);
    00929
    00930
    00944         void    drawGlyphToBuffer(argb_t* buffer, uint buf_width);
    00945
    00946
    00951         size_t  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;
    00952
    00953
    00958         size_t  getNextWord(const String& in_string, size_t start_idx, String& out_string) const;
    00959
    00960
    00965         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;
    00966
    00967
    00972         void    drawTextLineJustified(const String& text, const Rect& draw_area, const Vector3& position, const Rect& clip_rect, const ColourRect& colours, float x_scale = 1.0f, float y_scale = 1.0f) const;
    00973
    00974
    00979         void    createFontFromFT_Face(uint size, uint horzDpi, uint vertDpi);
    00980
    00981
    00986         void    updateFontScaling(void);
    00987
    00988
    00993         void    calculateStaticVertSpacing(void);
    00994
    00999         void    constructor_impl(const String& name, const String& fontname, const String& resourceGroup, uint size, uint flags, const String& glyph_set);
    01000
    01001
    01017         void    defineFontGlyphs_impl(void);
    01018
    01019
    01024         float   getWrappedTextExtent(const String& text, float wrapWidth, float x_scale = 1.0f) const;
    01025
    01026
    01037     void writeXMLToStream(OutStream& out_stream) const;
    01038
    01039
    01040         /*************************************************************************
    01041                 Implementation structs
    01042         *************************************************************************/
    01047         struct glyphDat
    01048         {
    01049                 const Image*    d_image;
    01050                 int                     d_horz_advance;
    01051                 int                     d_horz_advance_unscaled;
    01052         };
    01053
    01054         /*************************************************************************
    01055                 Implementation Data
    01056         *************************************************************************/
    01057         typedef         std::map<utf32, glyphDat>               CodepointMap;
    01058         CodepointMap    d_cp_map;
    01059
    01060         String          d_name;
    01061         Imageset*       d_glyph_images;
    01062         String     d_sourceFilename;
    01063
    01064         bool    d_freetype;
    01065         float   d_lineHeight;
    01066         float   d_lineSpacing;
    01067         float   d_max_bearingY;
    01068         uint    d_maxGlyphHeight;
    01069
    01070         FontImplData*   d_impldat;
    01071         uint            d_ptSize;
    01072         String          d_glyphset;
    01073
    01074         // auto-scaling fields
    01075         bool    d_autoScale;
    01076         float   d_horzScaling;
    01077         float   d_vertScaling;
    01078         float   d_nativeHorzRes;
    01079         float   d_nativeVertRes;
    01080
    01081         bool    d_antiAliased;
    01082 };
    01083
    01084 } // End of  CEGUI namespace section
    01085
    01086 #if defined(_MSC_VER)
    01087 #       pragma warning(pop)
    01088 #endif
    01089
    01090
    01091 #endif  // end of guard _CEGUIFont_h_