Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5131 clevermous 1
/*
2
SDL_bdf - renders BDF fonts
3
Copyright (C) 2002-2003 Andre de Leiradella
4
 
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
 
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
Lesser General Public License for more details.
14
 
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
19
For information about SDL_bdf contact leiradella@bigfoot.com
20
 
21
Version 1.0: first public release.
22
Version 1.1: removed SDL dependecies, now SDL_bdf can be used with any graphics
23
	     library.
24
Version 1.2: fixed BDF_SizeH and BDF_SizeEntitiesH to return the correct sizes.
25
*/
26
#ifndef __SDL_bdf_h__
27
#define __SDL_bdf_h__
28
 
29
#ifdef __cplusplus
30
extern "C" {
31
#endif
32
 
33
/* Error codes. */
34
 
35
/* No error. */
36
#define BDF_OK			 0
37
/* Not enough memory reading BDF font. */
38
#define BDF_MEMORYERROR 	 1
39
/* Error reading BDF font. */
40
#define BDF_READERROR		 2
41
/* Can only handle BDF font varsions up to 2.2. */
42
#define BDF_WRONGVERSION	 3
43
/* Can only handle horizontal BDF fonts. */
44
#define BDF_CANNOTHANDLEVERTICAL 4
45
/* Character found past end of BDF font. */
46
#define BDF_TOOMANYCHARACTERS	 5
47
/* BDF font is missing characters. */
48
#define BDF_TOOFEWCHARACTERS	 6
49
/* Error parsing BDF font. */
50
#define BDF_PARSEERROR		 7
51
 
52
/* A BDF character. */
53
typedef struct {
54
	char	      *name;
55
	int	      code;
56
	int	      dwx0, dwy0;
57
	int	      dwx1, dwy1;
58
	int	      bbw, bbh, bbxoff0x, bbyoff0y, wbytes;
59
	unsigned char *bits;
60
} BDF_Char;
61
 
62
/* A BDF font. */
63
typedef struct {
64
	int	 metricsSet, numChars;
65
	BDF_Char *chars;
66
	BDF_Char *code[256];
67
} BDF_Font;
68
 
69
/*
70
Function to put a pixel on the surface, it receives a pointer to the surface
71
(whatever format it may be), the x and y coordinates and the color.
72
*/
73
typedef void (*BDF_PutPixel)(void *, int, int, unsigned int);
74
 
75
/*
76
Function to read a byte, it receives an user defined void pointer and must
77
return a value in the range [0..255] or -1 to indicate EOF.
78
*/
79
typedef int (*BDF_ReadByte)(void *);
80
 
81
/*
82
Opens a BDF font, it receives the function that will produce the stream of
83
bytes, the user defined void pointer that will be passed to getbyte and a
84
pointer to an int that will receive the error code. Returns the BDF font.
85
*/
86
extern BDF_Font *BDF_OpenFont(BDF_ReadByte getbyte, void *info, int *error);
87
/*
88
Closes the font and frees all associated memory.
89
*/
90
extern void BDF_CloseFont(BDF_Font *font);
91
/*
92
Determines the size of the horizontal text, returns the width and height of the
93
smallest rectangle that can acomodate the rendered text and the start position
94
in x0 and y0 on where the text must be rendered to exactly fit the rectangle.
95
This is because the render functions take the y parameter as the baseline of
96
the text to allow different fonts (e.g. normal and italic) to be mixed in the
97
same line. It handles NULL pointers for pieces of information you don't want.
98
*/
99
extern void BDF_SizeH(BDF_Font *font, char *text, int *x0, int *y0, int *width, int *height);
100
/*
101
Same as above but accepts entities in the form &...;
102
*/
103
extern void BDF_SizeEntitiesH(BDF_Font *font, char *text, int *x0, int *y0, int *width, int *height);
104
/*
105
Draws the text at the given surface starting at position (x, y). It calls
106
putpixel with the surface, coordinates and color to draw the pixel (doesn't
107
clip). Returns the next x coordinate to continue to render more text. Only
108
accepts characters in the range [0..255].
109
*/
110
extern int BDF_DrawH(void *surface, BDF_PutPixel putpixel, BDF_Font *font, char *text, int x, int y, unsigned int color);
111
/*
112
Same as above but accepts entities in the form &...;
113
*/
114
extern int BDF_DrawEntitiesH(void *, BDF_PutPixel, BDF_Font *, char *, int, int, unsigned int);
115
 
116
#ifdef __cplusplus
117
};
118
#endif
119
 
120
#endif