1 /* ScummVM - Graphic Adventure Engine
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 // Font management and font drawing header file
35 #define FONT_SHOWUNDEFINED 1 // Define to draw undefined characters * as ?'s
37 // The first defined character (!) is the only one that may
38 // have a valid offset of '0'
39 #define FONT_FIRSTCHAR 33
42 #define FONT_CH_SPACE 32
43 #define FONT_CH_QMARK 63
45 // Minimum font header size without font data
46 // (6 + 512 + 256 + 256 + 256 )
47 #define FONT_DESCSIZE 1286
49 #define FONT_CHARCOUNT 256
50 #define FONT_CHARMASK 0xFFU
52 #define SAGA_FONT_HEADER_LEN 6
54 #define TEXT_CENTERLIMIT 50
55 #define TEXT_MARGIN 10
56 #define TEXT_LINESPACING 2
58 enum FontEffectFlags
{
60 kFontOutline
= 1 << 0,
63 kFontCentered
= 1 << 3,
77 struct TextListEntry
{
82 KnownColor knownColor
;
83 KnownColor effectKnownColor
;
84 FontEffectFlags flags
;
88 memset(this, 0, sizeof(*this));
91 bool operator==(const TextListEntry
&e
) const {
92 return 0 == memcmp(this, &e
, sizeof(*this));
96 class TextList
: public Common::List
<TextListEntry
> {
99 TextListEntry
*addEntry(const TextListEntry
&entry
) {
100 Common::List
<TextListEntry
>::push_back(entry
);
101 return &*--Common::List
<TextListEntry
>::end();
111 struct FontCharEntry
{
121 FontCharEntry fontCharEntry
[256];
132 Font(SagaEngine
*vm
);
134 int getStringWidth(KnownFont font
, const char *text
, size_t count
, FontEffectFlags flags
) {
135 return getStringWidth(knownFont2FontIdx(font
), text
, count
, flags
);
137 int getHeight(KnownFont font
) {
138 return getHeight(knownFont2FontIdx(font
));
140 int getHeight(KnownFont font
, const char *text
, int width
, FontEffectFlags flags
) {
141 return getHeight(knownFont2FontIdx(font
), text
, width
, flags
);
143 void textDraw(KnownFont font
, const char *string
, const Common::Point
&point
, int color
, int effectColor
, FontEffectFlags flags
) {
144 textDraw(knownFont2FontIdx(font
), string
, point
, color
, effectColor
, flags
);
146 void textDrawRect(KnownFont font
, const char *text
, const Common::Rect
&rect
, int color
, int effectColor
, FontEffectFlags flags
) {
147 textDrawRect(knownFont2FontIdx(font
), text
, rect
, color
, effectColor
, flags
);
149 void setFontMapping(int mapping
) {
150 _fontMapping
= mapping
;
164 Font::FontId
knownFont2FontIdx(KnownFont font
);
165 int translateChar(int charId
);
167 int getStringWidth(FontId fontId
, const char *text
, size_t count
, FontEffectFlags flags
);
168 int getHeight(FontId fontId
, const char *text
, int width
, FontEffectFlags flags
);
169 void textDrawRect(FontId fontId
, const char *text
, const Common::Rect
&rect
, int color
, int effectColor
, FontEffectFlags flags
);
170 void textDraw(FontId fontId
, const char *string
, const Common::Point
&point
, int color
, int effectColor
, FontEffectFlags flags
);
172 void loadFont(uint32 fontResourceId
);
173 void createOutline(FontData
*font
);
174 void draw(FontId fontId
, const char *text
, size_t count
, const Common::Point
&point
, int color
, int effectColor
, FontEffectFlags flags
);
175 void outFont(const FontStyle
&drawFont
, const char *text
, size_t count
, const Common::Point
&point
, int color
, FontEffectFlags flags
);
177 FontData
*getFont(FontId fontId
) {
179 return _fonts
[fontId
];
182 int getHeight(FontId fontId
) {
183 return getFont(fontId
)->normal
.header
.charHeight
;
186 void validate(FontId fontId
) {
187 if (!valid(fontId
)) {
188 error("Font::validate: Invalid font id.");
191 bool valid(FontId fontId
) {
192 return ((fontId
>= 0) && (fontId
< _loadedFonts
));
194 int getByteLen(int numBits
) const {
195 int byteLength
= numBits
/ 8;
204 static const int _charMap
[128];
213 } // End of namespace Saga