1  /*
2   * SoFont - SDL Object Font Library
3   *
4   * This library is free software; you can redistribute it and/or modify it
5   * under the terms of the GNU Library General Public License as published by
6   * the Free Software Foundation; either version 2 of the License, or (at
7   * your option) any later version.
8   *
9   * This library is distributed in the hope that it will be useful, but
10   * WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
12   * General Public License for more details.
13   *
14   * You should have received a copy of the GNU Library General Public License
15   * along with this library; if not, write to the Free Foundation, Inc., 59
16   * Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Originally from C Library: Karl Bartel
19   *
20   * *    SFONT - SDL Font Library by Karl Bartel <karlb@gmx.net>            *
21   * *                                                                       *
22   * *  All functions are explained below. There are two versions of each    *
23   * *  funtction. The first is the normal one, the function with the        *
24   * *  2 at the end can be used when you want to handle more than one font  *
25   * *  in your program.                                                     *
26   * *                                                                       *
27   *
28   * Copied into a C++ object to allow multiple fonts by: Luc-Olivier de
29   * Charriere
30   *
31   * David Olofson <do@reologica.se>:
32   * * Strings changed to 'const char *'
33   * * Cursor tests first check if '|' is present.
34   * * Shadowed variables fixed.
35   * * Garbage data in spacing table fixed. (Thanks to Andreas Sp�ngberg for
36   *   discovering this one!)
37   *
38   * Put back into C by Jean-Christophe Hoelt <jeko@free.fr> */
39 
40 #ifndef __SOFONT_H
41 #define __SOFONT_H
42 
43 #include "glSDL.h"
44 #include "IosImgProcess.h"
45 
46 typedef struct _SOFONT SoFont;
47 
48 SoFont *SoFont_new ();
49 void    SoFont_free (SoFont * font);
50 
51 int     SoFont_load (SoFont * font, IIM_Surface * FontSurface);
52 void    SoFont_Refresh(SoFont * font);
53 
54 /// Blits a string to a surface
55 ///   Destination: the suface you want to blit to
56 ///   text: a string containing the text you want to blit.
57 void    SoFont_PutString (SoFont * font, SDL_Surface * Surface, int x, int y,
58 													const char *text, SDL_Rect * clip /*=NULL*/ );
59 void    SoFont_PutStringWithCursor (SoFont * font, SDL_Surface * Surface,
60 																		int x, int y, const char *text,
61 																		int cursPos, SDL_Rect * clip /*=NULL*/ , int showCurs																															/*=true*/
62 	);
63 
64 /// Returns the width of "text" in pixels
65 int     SoFont_TextWidth (SoFont * font, const char *text);
66 int     SoFont_TextWidth_MinMax (SoFont * font, const char *text,
67 																 int min /*=0*/ , int max /*=255*/ );
68 
69 int     SoFont_FontHeight (SoFont * font);
70 
71 /// Blits a string to with centered x position
72 void    SoFont_XCenteredString (SoFont * font, SDL_Surface * Surface, int y,
73 																const char *text, SDL_Rect * clip /*=NULL*/ );
74 
75 /// Blits a string to with centered x & y position
76 void    SoFont_CenteredString (SoFont * font, SDL_Surface * Surface,
77 															 const char *text, SDL_Rect * clip /*=NULL*/ );
78 
79 /// Blits a string to with centered around x & y positions
80 void    SoFont_CenteredString_XY (SoFont * font, SDL_Surface * Surface, int x,
81 																	int y, const char *text,
82 
83 																	SDL_Rect * clip /*=NULL*/ );
84 
85 /// This was specially developped for GUI
86 void    SoFont_PutStringCleverCursor (SoFont * font, SDL_Surface * Surface,
87 																			const char *text, int cursPos,
88 																			SDL_Rect * r,
89 																			SDL_Rect * clip /*=NULL*/ ,
90 
91 																			int showCurs /*=true*/ );
92 
93 /// Gives the cursor position given a x-axix point in the text
94 int     SoFont_TextCursorAt (SoFont * font, const char *text, int px);
95 int     SoFont_CleverTextCursorAt (SoFont * font, const char *text, int px,
96 																	 int cursPos, SDL_Rect * r);
97 
98 #define START_CHAR 33
99 int     SoFont_getMinChar (SoFont * font);
100 int     SoFont_getMaxChar (SoFont * font);
101 
102 #endif
103