aboutsummaryrefslogtreecommitdiff
path: root/graphics/fonts/bdf.h
blob: 02bf23b211013a2863541267ef29551d6916831c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef GRAPHICS_FONTS_BDF_H
#define GRAPHICS_FONTS_BDF_H

#include "common/system.h"

#include "graphics/font.h"

namespace Common {
class SeekableReadStream;
}

namespace Graphics {

typedef uint16 bitmap_t; /* bitmap image unit size*/

struct BBX {
	int8 w;
	int8 h;
	int8 x;
	int8 y;
};

/* builtin C-based proportional/fixed font structure */
/* based on The Microwindows Project http://microwindows.org */
struct FontDesc {
	const char *	name;		/* font name*/
	int		maxwidth;	/* max width in pixels*/
	int		height;		/* height in pixels*/
	int	fbbw, fbbh, fbbx, fbby;	/* max bounding box */
	int		ascent;		/* ascent (baseline) height*/
	int		firstchar;	/* first character in bitmap*/
	int		size;		/* font size in glyphs*/
	const bitmap_t*	bits;		/* 16-bit right-padded bitmap data*/
	const unsigned long* offset;	/* offsets into bitmap data*/
	const unsigned char* width;	/* character widths or NULL if fixed*/
	const BBX* bbx;			/* character bounding box or NULL if fixed */
	int		defaultchar;	/* default char (not glyph index)*/
	long	bits_size;	/* # words of bitmap_t bits*/
};

struct NewFontData;

class NewFont : public Font {
protected:
	FontDesc _desc;
	NewFontData *_font;

public:
	NewFont(const FontDesc &desc, NewFontData *font = 0) : _desc(desc), _font(font) {}
	~NewFont();

	virtual int getFontHeight() const { return _desc.height; }
	virtual int getMaxCharWidth() const { return _desc.maxwidth; }

	virtual int getCharWidth(byte chr) const;
	virtual void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const;

	static NewFont *loadFont(Common::SeekableReadStream &stream);
	static bool cacheFontData(const NewFont &font, const Common::String &filename);
	static NewFont *loadFromCache(Common::SeekableReadStream &stream);
};

#define DEFINE_FONT(n) \
		const NewFont *n = 0;	\
		void create_##n() {	\
			n = new NewFont(desc);	\
		}

#define FORWARD_DECLARE_FONT(n) \
		extern const NewFont *n; \
		extern void create_##n()

#define INIT_FONT(n) \
		create_##n()

} // End of namespace Graphics

#endif