Main Page   Class Hierarchy   Compound List   File List   Compound Members  

fontresource.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2002
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under 2 licenses:
00008 
00009         - The GPL, with no additional restrictions.
00010         - The LGPL, provided you display the Kyra splash screen, described below.
00011 
00012 
00013 --- GPL License --
00014         This program is free software; you can redistribute it and/or
00015         modify it under the terms of the GNU General Public License
00016         as published by the Free Software Foundation; either version 2
00017         of the License, or (at your option) any later version.
00018 
00019         This program is distributed in the hope that it will be useful,
00020         but WITHOUT ANY WARRANTY; without even the implied warranty of
00021         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022         GNU General Public License for more details.
00023 
00024         You should have received a copy of the GNU General Public License
00025         along with this program; if not, write to the Free Software
00026         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028         The full text of the license can be found in license.txt
00029 
00030 
00031 --- LGPL License --
00032   **Provided you kindly display the Kyra splash screen (details below), 
00033         you     may use the LGPL license:**
00034 
00035     This library is free software; you can redistribute it and/or
00036     modify it under the terms of the GNU Lesser General Public
00037     License as published by the Free Software Foundation; either
00038     version 2.1 of the License, or (at your option) any later version.
00039 
00040     This library is distributed in the hope that it will be useful,
00041     but WITHOUT ANY WARRANTY; without even the implied warranty of
00042     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00043     Lesser General Public License for more details.
00044 
00045     You should have received a copy of the GNU Lesser General Public
00046     License along with this library; if not, write to the Free Software
00047     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00048 
00049         The full text of the license can be found in lgpl.txt
00050 
00051 
00052 --- Kyra Splash Screen.
00053 
00054         It would be appreciate if you display the Kyra splash screen when using
00055         either license, however it is only required for the LGPL. All the
00056         resources for the splash are compiled into the library, and it can be
00057         accessed through the following API:
00058 
00059                 KrEngine::StartSplash
00060                 KrEngine::UpdateSplash
00061                 KrEngine::EndSplash
00062 
00063         Full documentation is provided with the KrEngine class. The splash screen
00064         should be displayed for 2 seconds.
00065 
00066         Thank you.
00067 */
00068 
00069 
00070 #ifndef KYRA_FONTRESOURCE_INCLUDED
00071 #define KYRA_FONTRESOURCE_INCLUDED
00072 
00073 #include "spriteresource.h"
00074 
00075 
00088 class KrFontResource : public KrSpriteResource
00089 {
00090   public:
00091         // Create by reading from a .dat file
00092         KrFontResource( U32 size, SDL_RWops* data );
00093                 
00094         KrFontResource( const std::string& name,
00095                                         KrPaintInfo* info,
00096                                         int startingGlyph,
00097                                         int addSpaceGlyph,
00098                                         int type,
00099                                         int numGlyphs );        // only need for fixed fonts
00100 
00101         virtual ~KrFontResource();
00102 
00103         virtual U32 Type()                                                              { return KYRATAG_FONT; }
00104         virtual const std::string&      TypeName()                      { return fontName; }
00105         virtual KrFontResource* ToFontResource()                { return this; }
00106 
00107         enum {
00108                 FIXED,
00109                 SFONT
00110         };
00111 
00113         int FontHeight()        { return actionArr[0]->Frame( 0 ).Delta().y; }
00114 
00115         int FontWidth1( U16 glyphCode );        
00116         int FontWidth( const U16* str );        
00117         int FontWidthN( const U16* str, int nChars );   
00118         
00122         bool GlyphInFont( U16 glyphCode );
00123         int  GlyphToFrame(  U16 glyphCode );
00124 
00125         /*  Draw a character in the font.
00126                 @param  paintInfo       Information about the target surface for drawing (optimizing).
00127                 @param  glyphCode       The glyph code: ascii, latin-1, whatever
00128                 @param  x                       X location in pixels.
00129                 @param  y                       Y location in pixels.
00130                 @param  cForm           Color transformation applied to the drawing.
00131                 @param  clip            A clipping rectangle, which can be null.
00132         */
00133         void Draw( KrPaintInfo* paintInfo,
00134                            U16 glyphCode,
00135                            const KrMatrix2& matrix,
00136                            const KrColorTransform& cForm,
00137                            const KrRect& clipping,
00138                            int openGLZ );
00139 
00140 
00141         virtual void Save( KrEncoder* encoder );
00142 
00143   private:
00144         // The font (and text) somewhat abuses the sprite system. Fonts
00145         // are single action sprites, with a number of frames equal to
00146         // the length of the font. The delta is interpreted as the 
00147         // bounding box of the letter.
00148 
00149         void CalcSpaceWidth();
00150 
00151         const static std::string fontName;
00152 
00153         U32                     startIndex;
00154         U32                     space;
00155         int                     spaceWidth;
00156         int                     fontType;
00157 //      KrAction*       action;         // A font is only one action.
00158 
00159 };
00160 
00161 
00162 #endif

Generated on Mon Sep 15 12:01:10 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001