Files
2026-02-02 04:50:13 +01:00

225 lines
8.6 KiB
C++

/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "ultima/ultima0/gfx/font.h"
namespace Ultima {
namespace Ultima0 {
namespace Gfx {
static const byte FONT1[2048] = {
124,130,186,162,186,130,124,0,126,129,165,129,165,153,129,126,
126,129,165,129,153,165,129,126,108,246,246,254,124,56,16,0,
16,56,124,254,124,56,16,0,16,56,84,254,84,16,56,0,
56,124,254,254,108,16,56,0,16,24,20,20,48,112,96,0,
254,254,254,238,254,254,254,0,236,138,138,170,170,170,236,0,
142,136,136,140,136,136,232,0,174,170,170,234,170,170,174,0,
238,136,136,204,136,136,136,0,238,138,138,142,140,138,234,0,
62,34,62,34,102,238,204,0,16,84,40,198,40,84,16,0,
240,248,252,254,252,248,240,0,30,62,126,254,126,62,30,0,
16,56,124,16,124,56,16,0,238,238,238,238,238,0,238,0,
254,68,68,68,68,68,68,0,126,128,188,198,122,2,252,0,
0,0,0,0,255,255,0,0,16,56,124,16,124,56,16,254,
16,56,124,254,56,56,56,0,56,56,56,254,124,56,16,0,
16,24,252,254,252,24,16,0,16,48,126,254,126,48,16,0,
144,72,36,18,36,72,144,0,18,36,72,144,72,36,18,0,
16,40,68,146,40,68,130,0,130,68,40,146,68,40,16,0,
0,0,0,0,0,0,0,0,16,16,16,16,16,0,16,0,
40,40,40,0,0,0,0,0,68,254,68,68,68,254,68,0,
16,126,144,124,18,252,16,0,66,164,72,16,36,74,132,0,
56,68,56,112,138,132,122,0,16,16,32,0,0,0,0,0,
8,16,16,16,16,16,8,0,32,16,16,16,16,16,32,0,
16,84,56,254,56,84,16,0,16,16,16,254,16,16,16,0,
0,0,0,0,0,16,16,32,0,0,0,254,0,0,0,0,
0,0,0,0,0,0,16,0,2,4,8,16,32,64,128,0,
124,130,130,130,130,130,124,0,240,16,16,16,16,16,254,0,
252,2,2,124,128,128,254,0,252,2,2,28,2,2,252,0,
130,130,130,126,2,2,2,0,254,128,252,2,2,2,252,0,
126,128,252,130,130,130,124,0,252,2,2,2,2,2,2,0,
124,130,130,124,130,130,124,0,126,130,130,126,2,2,252,0,
0,0,0,16,0,0,16,0,0,0,0,16,0,0,16,32,
8,16,32,64,32,16,8,0,0,0,0,254,0,254,0,0,
64,32,16,8,16,32,64,0,56,68,4,8,16,0,16,0,
60,66,154,170,156,64,62,0,124,130,130,254,130,130,130,0,
252,130,130,252,130,130,252,0,124,130,128,128,128,130,124,0,
252,130,130,130,130,130,252,0,254,128,128,240,128,128,254,0,
254,128,128,240,128,128,128,0,124,130,128,142,130,130,124,0,
130,130,130,254,130,130,130,0,254,16,16,16,16,16,254,0,
62,2,2,2,130,130,124,0,130,132,136,240,136,132,130,0,
128,128,128,128,128,128,254,0,252,146,146,146,146,146,146,0,
130,194,162,146,138,134,130,0,124,130,130,130,130,130,124,0,
252,130,130,252,128,128,128,0,124,130,130,130,138,134,126,0,
252,130,130,252,130,130,130,0,126,128,128,124,2,2,252,0,
254,16,16,16,16,16,16,0,130,130,130,130,130,130,124,0,
130,130,68,68,40,40,16,0,130,130,130,146,146,146,108,0,
130,68,40,16,40,68,130,0,130,130,130,126,2,2,252,0,
254,4,8,16,32,64,254,0,56,32,32,32,32,32,56,0,
128,64,32,16,8,4,2,0,56,8,8,8,8,8,56,0,
16,40,68,130,0,0,0,0,0,0,0,0,0,0,0,255,
32,32,16,0,0,0,0,0,0,0,56,68,124,68,68,0,
0,0,120,68,120,68,120,0,0,0,60,64,64,64,60,0,
0,0,120,68,68,68,120,0,0,0,124,64,112,64,124,0,
0,0,124,64,112,64,64,0,0,0,60,64,76,68,60,0,
0,0,68,68,124,68,68,0,0,0,124,16,16,16,124,0,
0,0,28,4,4,68,56,0,0,0,68,72,112,72,68,0,
0,0,64,64,64,64,124,0,0,0,120,84,84,84,84,0,
0,0,120,68,68,68,68,0,0,0,56,68,68,68,56,0,
0,0,120,68,120,64,64,0,0,0,56,68,68,76,54,0,
0,0,120,68,120,68,68,0,0,0,60,64,56,4,120,0,
0,0,124,16,16,16,16,0,0,0,68,68,68,68,56,0,
0,0,68,68,40,40,16,0,0,0,68,68,84,108,68,0,
0,0,68,40,16,40,68,0,0,0,68,68,60,4,120,0,
0,0,124,8,16,32,124,0,8,16,16,32,16,16,8,0,
16,16,16,0,16,16,16,0,32,16,16,8,16,16,32,0,
80,40,0,0,0,0,0,0,0,16,40,68,130,130,254,0,
254,254,254,254,254,254,254,0,0,0,0,0,0,254,254,0,
0,0,124,124,124,124,124,0,0,0,0,0,0,0,124,0,
128,128,128,128,128,128,128,0,0,64,64,64,64,64,64,0,
16,24,28,30,28,24,16,0,16,48,112,240,112,48,16,0,
62,30,30,62,114,224,64,0,4,14,156,248,240,240,248,0,
64,224,114,62,30,30,62,0,248,240,240,248,156,14,4,0,
56,68,130,130,130,68,56,0,56,124,254,254,254,124,56,0,
0,124,68,68,68,124,0,0,0,124,124,124,124,124,0,0,
0,60,110,126,112,126,60,0,0,60,118,126,14,126,60,0,
0,60,126,106,126,126,106,0,0,60,126,86,126,126,86,0,
0,0,0,24,24,0,0,0,0,0,24,60,60,24,0,0,
0,12,52,36,36,108,72,0,0,0,0,0,0,0,0,0,
60,126,198,231,255,224,126,60,60,126,227,231,255,7,126,60,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,52,118,118,94,126,60,0,0,60,110,126,112,126,60,0,
0,60,126,122,110,110,44,0,0,60,126,14,126,118,60,0,
0,0,0,0,0,0,0,0,126,126,126,126,60,0,0,0,
0,15,31,31,31,31,15,0,126,127,127,127,127,127,63,0,
0,0,0,60,126,126,126,126,126,126,126,126,126,126,126,126,
0,63,127,127,127,127,127,126,126,127,127,127,127,127,127,126,
0,240,248,248,248,248,240,0,126,254,254,254,254,254,252,0,
0,255,255,255,255,255,255,0,126,255,255,255,255,255,255,0,
0,252,254,254,254,254,254,126,126,254,254,254,254,254,254,126,
0,255,255,255,255,255,255,126,126,255,255,255,255,255,255,126,
0,0,63,63,48,55,52,52,0,0,255,255,0,255,0,0,
0,0,248,248,24,216,88,88,88,88,88,88,88,88,88,88,
88,216,24,248,248,0,0,0,0,255,0,255,255,0,0,0,
52,55,48,63,63,0,0,0,52,52,52,52,52,52,52,52,
0,0,0,31,24,24,24,24,0,0,0,255,0,0,0,0,
0,0,0,240,48,48,48,48,48,48,48,48,48,48,48,48,
48,48,48,240,0,0,0,0,0,0,0,255,0,0,0,0,
24,24,24,31,0,0,0,0,24,24,24,24,24,24,24,24,
136,34,136,34,136,34,136,34,85,170,85,170,85,170,85,170,
68,170,68,170,68,170,68,170,51,102,204,153,51,102,204,153,
204,102,51,153,204,102,51,153,199,143,31,62,124,248,241,227,
227,241,248,124,62,31,143,199,174,128,186,2,234,8,171,32,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
void Font::writeChar(Graphics::ManagedSurface *dst, uint32 chr,
const Common::Point &textPos, byte textColor) {
if (chr == ' ')
return; // Don't do anything for spaces
const byte *GfxData = FONT1 + chr * 8;
Graphics::Surface charArea = dst->getSubArea(Common::Rect(textPos.x, textPos.y,
textPos.x + GLYPH_WIDTH, textPos.y + GLYPH_HEIGHT));
const int w = 1;
const int h = 1;
// Work through the 64 pixel array
for (int x = 0; x < 8; ++x) {
for (int y = 0; y < 8; ++y) {
// Check for whether character has pixel in this position
if (_FONTPixelSet(GfxData, x, y)) {
Common::Rect rc2(x * 2, y * 2, x * 2 + 2, y * 2 + 2);
charArea.fillRect(rc2, textColor);
// Neaten the diagonals
if (_FONTPixelSet(GfxData, x, y + 1) == 0 &&
_FONTPixelSet(GfxData, x - 1, y) == 0 &&
_FONTPixelSet(GfxData, x - 1, y + 1) != 0)
_FONTAngleDraw(&charArea, &rc2, -w, h, textColor);
if (_FONTPixelSet(GfxData, x, y + 1) == 0 &&
_FONTPixelSet(GfxData, x + 1, y) == 0 &&
_FONTPixelSet(GfxData, x + 1, y + 1) != 0)
_FONTAngleDraw(&charArea, &rc2, w, h, textColor);
}
}
}
}
bool Font::_FONTPixelSet(const byte * Data, int x, int y) {
if (x < 0 || y < 0 || x > 7 || y > 7)
return false;
return (Data[y] & (0x80 >> x)) ? 1 : 0;
}
void Font::_FONTAngleDraw(Graphics::Surface *s, Common::Rect *rc, int w, int h, byte colour) {
int i, m;
Common::Rect rc3;
m = ABS(w);
if (ABS(h) > m)
m = ABS(h);
for (i = 0; i < m; i++) {
rc3.left = rc->left + w * i / m;
rc3.top = rc->top + h * i / m;
rc3.setWidth(rc->width());
rc3.setHeight(rc->height());
s->fillRect(rc3, colour);
}
}
} // namespace Gfx
} // namespace Ultima0
} // namespace Ultima