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

# fontresource.h

    00001 /*--License:
    00002         Kyra Sprite Engine
    00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
    00004         www.grinninglizard.com/kyra
    00005         www.sourceforge.net/projects/kyra
    00006
    00007         Kyra is provided under the LGPL.
    00008
    00009         I kindly request you display a splash screen (provided in the HTML documentation)
    00010         to promote Kyra and acknowledge the software and everyone who has contributed to it,
    00011         but it is not required by the license.
    00012
    00013 --- LGPL License --
    00014
    00015     This library is free software; you can redistribute it and/or
    00016     modify it under the terms of the GNU Lesser General Public
    00017     License as published by the Free Software Foundation; either
    00018     version 2.1 of the License, or (at your option) any later version.
    00019
    00020     This library is distributed in the hope that it will be useful,
    00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00023     Lesser General Public License for more details.
    00024
    00025     You should have received a copy of the GNU Lesser General Public
    00026     License along with this library; if not, write to the Free Software
    00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00028
    00029         The full text of the license can be found in lgpl.txt
    00030 */
    00031
    00032
    00033 #ifndef KYRA_FONTRESOURCE_INCLUDED
    00034 #define KYRA_FONTRESOURCE_INCLUDED
    00035
    00036 #ifdef _MSC_VER
    00037 // Disable the no-exception handling warning.
    00038 #pragma warning( disable : 4530 )
    00039 #pragma warning( disable : 4786 )
    00040 #endif
    00041
    00042 #include "spriteresource.h"
    00043
    00056 class KrFontResource : public KrSpriteResource
    00057 {
    00058   public:
    00059         // Create by reading from a .dat file
    00060         KrFontResource( U32 size, SDL_RWops* data );
    00061
    00062         KrFontResource( const std::string& name,
    00063                                         KrPaintInfo* info,
    00064                                         int startingGlyph,
    00065                                         int addSpaceGlyph,
    00066                                         int type,
    00067                                         int numGlyphs );        // only need for fixed fonts
    00068
    00069         virtual ~KrFontResource();
    00070
    00071         virtual U32 Type()                                                              { return KYRATAG_FONT; }
    00072         virtual const std::string&      TypeName()                      { return fontName; }
    00073         virtual KrFontResource* ToFontResource()                { return this; }
    00074
    00075         enum {
    00076                 FIXED,
    00077                 SFONT
    00078         };
    00079
    00081         int FontHeight()        { return actionArr[0]->Frame( 0 ).Delta().y; }
    00082
    00083         int FontWidth1( U16 glyphCode );
    00084         int FontWidth( const U16* str );
    00085         int FontWidthN( const U16* str, int nChars );
    00086
    00090         bool GlyphInFont( U16 glyphCode );
    00091         int  GlyphToFrame(  U16 glyphCode );
    00092
    00093         /*  Draw a character in the font.
    00094                 @param  paintInfo       Information about the target surface for drawing (optimizing).
    00095                 @param  glyphCode       The glyph code: ascii, latin-1, whatever
    00096                 @param  x                       X location in pixels.
    00097                 @param  y                       Y location in pixels.
    00098                 @param  cForm           Color transformation applied to the drawing.
    00099                 @param  clip            A clipping rectangle, which can be null.
    00100         */
    00101         void Draw( KrPaintInfo* paintInfo,
    00102                            U16 glyphCode,
    00103                            const KrMatrix2& matrix,
    00104                            const KrColorTransform& cForm,
    00105                            const grinliz::Rectangle2I& clipping );
    00106
    00107         virtual void Save( KrEncoder* encoder );
    00108
    00109   private:
    00110         // The font (and text) somewhat abuses the sprite system. Fonts
    00111         // are single action sprites, with a number of frames equal to
    00112         // the length of the font. The delta is interpreted as the
    00113         // bounding box of the letter.
    00114
    00115         void CalcSpaceWidth();
    00116
    00117         const static std::string fontName;
    00118
    00119         U32                     startIndex;
    00120         U32                     space;
    00121         int                     spaceWidth;
    00122         int                     fontType;
    00123 //      KrAction*       action;         // A font is only one action.
    00124
    00125 };
    00126
    00127
    00128 #endif