2007-05-30 21:56:52 +00:00
|
|
|
/* 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.
|
2002-12-25 21:04:47 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-12-25 21:04:47 +00:00
|
|
|
*
|
2006-02-11 09:55:41 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-12-25 21:04:47 +00:00
|
|
|
*/
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
#include "scumm/charset.h"
|
|
|
|
#include "scumm/scumm.h"
|
|
|
|
#include "scumm/nut_renderer.h"
|
2005-04-10 12:59:17 +00:00
|
|
|
#include "scumm/util.h"
|
2006-09-17 23:35:09 +00:00
|
|
|
#include "scumm/he/intern_he.h"
|
2006-02-15 00:57:50 +00:00
|
|
|
#include "scumm/he/wiz_he.h"
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2003-10-03 18:33:57 +00:00
|
|
|
namespace Scumm {
|
|
|
|
|
2007-01-28 20:11:31 +00:00
|
|
|
/*
|
|
|
|
TODO:
|
|
|
|
Right now our charset renderers directly access _textSurface, as well as the
|
|
|
|
virtual screens of ScummEngine. Ideally, this would not be the case. Instead,
|
2007-09-19 08:40:12 +00:00
|
|
|
ScummVM would simply pass the appropriate Surface to the resp. methods.
|
2007-01-28 20:11:31 +00:00
|
|
|
Of course it is not quite as simple, various flags and offsets have to
|
|
|
|
be taken into account for that.
|
|
|
|
|
2007-09-19 08:40:12 +00:00
|
|
|
The advantage will be cleaner coder (easier to debug, in particular), and a
|
2007-01-28 20:11:31 +00:00
|
|
|
better separation of the various modules.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-09-20 22:04:06 +00:00
|
|
|
void ScummEngine::loadCJKFont() {
|
2005-05-10 22:56:25 +00:00
|
|
|
Common::File fp;
|
2004-09-20 22:04:06 +00:00
|
|
|
_useCJKMode = false;
|
2007-07-10 00:39:12 +00:00
|
|
|
_textSurfaceMultiplier = 1;
|
2008-08-02 21:36:08 +00:00
|
|
|
_newLineCharacter = 0;
|
2007-07-10 00:39:12 +00:00
|
|
|
|
2007-08-14 13:42:05 +00:00
|
|
|
if (_game.version <= 5 && _game.platform == Common::kPlatformFMTowns && _language == Common::JA_JPN) { // FM-TOWNS v3 / v5 Kanji
|
2004-10-23 23:08:53 +00:00
|
|
|
int numChar = 256 * 32;
|
|
|
|
_2byteWidth = 16;
|
|
|
|
_2byteHeight = 16;
|
|
|
|
// use FM-TOWNS font rom, since game files don't have kanji font resources
|
2009-09-25 11:39:22 +00:00
|
|
|
if (!fp.open("fmt_fnt.rom")) {
|
|
|
|
error("SCUMM::Font: Couldn't open fmt_fnt.rom");
|
|
|
|
} else {
|
2004-10-23 23:08:53 +00:00
|
|
|
_useCJKMode = true;
|
|
|
|
debug(2, "Loading FM-TOWNS Kanji rom");
|
|
|
|
_2byteFontPtr = new byte[((_2byteWidth + 7) / 8) * _2byteHeight * numChar];
|
|
|
|
fp.read(_2byteFontPtr, ((_2byteWidth + 7) / 8) * _2byteHeight * numChar);
|
|
|
|
fp.close();
|
|
|
|
}
|
2007-07-10 00:39:12 +00:00
|
|
|
_textSurfaceMultiplier = 2;
|
2009-11-22 08:20:20 +00:00
|
|
|
} else if (_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine && _language == Common::JA_JPN) {
|
|
|
|
int numChar = 3418;
|
|
|
|
_2byteWidth = 12;
|
|
|
|
_2byteHeight = 12;
|
|
|
|
// use PC-Engine System Card, since game files don't have kanji font resources
|
|
|
|
if (!fp.open("pce.cdbios")) {
|
|
|
|
error("SCUMM::Font: Couldn't open System Card pce.cdbios");
|
|
|
|
} else {
|
|
|
|
_useCJKMode = true;
|
|
|
|
debug(2, "Loading PC-Engine System Card");
|
2009-11-22 23:33:58 +00:00
|
|
|
|
|
|
|
// A 0x200 byte header can be present at the beginning of the syscard. Seek past it too.
|
|
|
|
fp.seek((fp.size() & 0x200) ? 0x30200 : 0x30000);
|
|
|
|
|
2009-11-22 08:20:20 +00:00
|
|
|
_2byteFontPtr = new byte[_2byteWidth * _2byteHeight * numChar / 8];
|
|
|
|
fp.read(_2byteFontPtr, _2byteWidth * _2byteHeight * numChar / 8);
|
|
|
|
fp.close();
|
|
|
|
}
|
2009-12-30 20:51:49 +00:00
|
|
|
} else if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD && _language == Common::JA_JPN) {
|
|
|
|
int numChar = 1413;
|
|
|
|
_2byteWidth = 16;
|
|
|
|
_2byteHeight = 16;
|
|
|
|
_useCJKMode = true;
|
|
|
|
_newLineCharacter = 0x5F;
|
|
|
|
// charset resources are not inited yet, load charset later
|
|
|
|
_2byteFontPtr = new byte[_2byteWidth * _2byteHeight * numChar / 8];
|
|
|
|
// set byte 0 to 0xFF (0x00 when loaded) to indicate that the font was not loaded
|
|
|
|
_2byteFontPtr[0] = 0xFF;
|
2007-08-14 14:40:11 +00:00
|
|
|
} else if (_game.version >= 7 && (_language == Common::KO_KOR || _language == Common::JA_JPN || _language == Common::ZH_TWN)) {
|
2004-10-23 23:08:53 +00:00
|
|
|
int numChar = 0;
|
2004-09-20 22:04:06 +00:00
|
|
|
const char *fontFile = NULL;
|
2004-10-23 23:08:53 +00:00
|
|
|
|
2004-10-22 10:25:56 +00:00
|
|
|
switch (_language) {
|
2004-09-20 22:04:06 +00:00
|
|
|
case Common::KO_KOR:
|
|
|
|
fontFile = "korean.fnt";
|
2004-10-23 23:08:53 +00:00
|
|
|
numChar = 2350;
|
2004-09-20 22:04:06 +00:00
|
|
|
break;
|
|
|
|
case Common::JA_JPN:
|
2006-02-20 16:51:30 +00:00
|
|
|
fontFile = (_game.id == GID_DIG) ? "kanji16.fnt" : "japanese.fnt";
|
2008-04-26 20:33:59 +00:00
|
|
|
numChar = 8192;
|
2004-09-20 22:04:06 +00:00
|
|
|
break;
|
|
|
|
case Common::ZH_TWN:
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_game.id == GID_CMI) {
|
2004-09-20 22:04:06 +00:00
|
|
|
fontFile = "chinese.fnt";
|
2007-07-21 22:57:21 +00:00
|
|
|
numChar = 13630;
|
2004-09-20 22:04:06 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fontFile && fp.open(fontFile)) {
|
|
|
|
debug(2, "Loading CJK Font");
|
|
|
|
_useCJKMode = true;
|
2007-07-10 00:39:12 +00:00
|
|
|
_textSurfaceMultiplier = 1; // No multiplication here
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-07-21 22:40:02 +00:00
|
|
|
switch (_language) {
|
|
|
|
case Common::KO_KOR:
|
|
|
|
fp.seek(2, SEEK_CUR);
|
|
|
|
_2byteWidth = fp.readByte();
|
|
|
|
_2byteHeight = fp.readByte();
|
2008-04-28 15:21:36 +00:00
|
|
|
_newLineCharacter = 0xff;
|
2007-07-21 22:40:02 +00:00
|
|
|
break;
|
|
|
|
case Common::JA_JPN:
|
|
|
|
_2byteWidth = 16;
|
|
|
|
_2byteHeight = 16;
|
2008-04-28 15:21:36 +00:00
|
|
|
_newLineCharacter = 0xfe;
|
2007-07-21 22:40:02 +00:00
|
|
|
break;
|
|
|
|
case Common::ZH_TWN:
|
|
|
|
_2byteWidth = 16;
|
2007-07-21 22:57:21 +00:00
|
|
|
_2byteHeight = 15;
|
2008-04-28 15:21:36 +00:00
|
|
|
_newLineCharacter = 0x21;
|
2007-07-21 22:40:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2004-09-20 22:04:06 +00:00
|
|
|
|
|
|
|
_2byteFontPtr = new byte[((_2byteWidth + 7) / 8) * _2byteHeight * numChar];
|
|
|
|
fp.read(_2byteFontPtr, ((_2byteWidth + 7) / 8) * _2byteHeight * numChar);
|
|
|
|
fp.close();
|
2004-10-23 23:08:53 +00:00
|
|
|
} else {
|
2009-09-25 11:39:22 +00:00
|
|
|
if (fontFile)
|
|
|
|
error("SCUMM::Font: Couldn't open %s",fontFile);
|
|
|
|
else
|
|
|
|
error("SCUMM::Font: Couldn't load any font");
|
2004-09-20 22:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
static int SJIStoFMTChunk(int f, int s) { //converts sjis code to fmt font offset
|
2004-09-20 22:04:06 +00:00
|
|
|
enum {
|
|
|
|
KANA = 0,
|
|
|
|
KANJI = 1,
|
|
|
|
EKANJI = 2
|
|
|
|
};
|
2004-10-23 23:08:53 +00:00
|
|
|
int base = s - ((s + 1) % 32);
|
|
|
|
int c = 0, p = 0, chunk_f = 0, chunk = 0, cr = 0, kanjiType = KANA;
|
2004-09-20 22:04:06 +00:00
|
|
|
|
|
|
|
if (f >= 0x81 && f <= 0x84) kanjiType = KANA;
|
|
|
|
if (f >= 0x88 && f <= 0x9f) kanjiType = KANJI;
|
|
|
|
if (f >= 0xe0 && f <= 0xea) kanjiType = EKANJI;
|
|
|
|
|
|
|
|
if ((f > 0xe8 || (f == 0xe8 && base >= 0x9f)) || (f > 0x90 || (f == 0x90 && base >= 0x9f))) {
|
|
|
|
c = 48; //correction
|
|
|
|
p = -8; //correction
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kanjiType == KANA) {//Kana
|
|
|
|
chunk_f = (f - 0x81) * 2;
|
|
|
|
} else if (kanjiType == KANJI) {//Standard Kanji
|
|
|
|
p += f - 0x88;
|
|
|
|
chunk_f = c + 2 * p;
|
|
|
|
} else if (kanjiType == EKANJI) {//Enhanced Kanji
|
|
|
|
p += f - 0xe0;
|
|
|
|
chunk_f = c + 2 * p;
|
|
|
|
}
|
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
// Base corrections
|
2004-09-20 22:04:06 +00:00
|
|
|
if (base == 0x7f && s == 0x7f)
|
2004-10-23 23:08:53 +00:00
|
|
|
base -= 0x20;
|
|
|
|
if (base == 0x9f && s == 0xbe)
|
|
|
|
base += 0x20;
|
|
|
|
if (base == 0xbf && s == 0xde)
|
|
|
|
base += 0x20;
|
|
|
|
//if (base == 0x7f && s == 0x9e)
|
|
|
|
// base += 0x20;
|
2004-09-20 22:04:06 +00:00
|
|
|
|
2004-10-22 10:25:56 +00:00
|
|
|
switch (base) {
|
2004-09-20 22:04:06 +00:00
|
|
|
case 0x3f:
|
|
|
|
cr = 0; //3f
|
|
|
|
if (kanjiType == KANA) chunk = 1;
|
|
|
|
else if (kanjiType == KANJI) chunk = 31;
|
|
|
|
else if (kanjiType == EKANJI) chunk = 111;
|
|
|
|
break;
|
|
|
|
case 0x5f:
|
|
|
|
cr = 0; //5f
|
|
|
|
if (kanjiType == KANA) chunk = 17;
|
|
|
|
else if (kanjiType == KANJI) chunk = 47;
|
|
|
|
else if (kanjiType == EKANJI) chunk = 127;
|
|
|
|
break;
|
|
|
|
case 0x7f:
|
|
|
|
cr = -1; //80
|
|
|
|
if (kanjiType == KANA) chunk = 9;
|
|
|
|
else if (kanjiType == KANJI) chunk = 63;
|
|
|
|
else if (kanjiType == EKANJI) chunk = 143;
|
|
|
|
break;
|
|
|
|
case 0x9f:
|
|
|
|
cr = 1; //9e
|
|
|
|
if (kanjiType == KANA) chunk = 2;
|
|
|
|
else if (kanjiType == KANJI) chunk = 32;
|
|
|
|
else if (kanjiType == EKANJI) chunk = 112;
|
|
|
|
break;
|
|
|
|
case 0xbf:
|
|
|
|
cr = 1; //be
|
|
|
|
if (kanjiType == KANA) chunk = 18;
|
|
|
|
else if (kanjiType == KANJI) chunk = 48;
|
|
|
|
else if (kanjiType == EKANJI) chunk = 128;
|
|
|
|
break;
|
|
|
|
case 0xdf:
|
|
|
|
cr = 1; //de
|
|
|
|
if (kanjiType == KANA) chunk = 10;
|
|
|
|
else if (kanjiType == KANJI) chunk = 64;
|
|
|
|
else if (kanjiType == EKANJI) chunk = 144;
|
|
|
|
break;
|
|
|
|
default:
|
2005-11-27 10:32:21 +00:00
|
|
|
debug(4, "Invalid Char! f %x s %x base %x c %d p %d", f, s, base, c, p);
|
2004-09-20 22:04:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
debug(6, "Kanji: %c%c f 0x%x s 0x%x base 0x%x c %d p %d chunk %d cr %d index %d", f, s, f, s, base, c, p, chunk, cr, ((chunk_f + chunk) * 32 + (s - base)) + cr);
|
2004-09-20 22:04:06 +00:00
|
|
|
return ((chunk_f + chunk) * 32 + (s - base)) + cr;
|
|
|
|
}
|
|
|
|
|
2009-11-22 08:20:20 +00:00
|
|
|
static int SJIStoPCEChunk(int f, int s) { //converts sjis code to pce font offset
|
|
|
|
// rangeTbl maps SJIS char-codes to the PCE System Card font rom.
|
|
|
|
// Each pair {<upperBound>,<lowerBound>} in the array represents a SJIS range.
|
|
|
|
const int rangeCnt = 45;
|
|
|
|
static const uint16 rangeTbl[rangeCnt][2] = {
|
|
|
|
// Symbols
|
|
|
|
{0x8140,0x817E},{0x8180,0x81AC},
|
|
|
|
// 0-9
|
|
|
|
{0x824F,0x8258},
|
|
|
|
// Latin upper
|
|
|
|
{0x8260,0x8279},
|
|
|
|
// Latin lower
|
|
|
|
{0x8281,0x829A},
|
|
|
|
// Kana
|
|
|
|
{0x829F,0x82F1},{0x8340,0x837E},{0x8380,0x8396},
|
|
|
|
// Greek upper
|
|
|
|
{0x839F,0x83B6},
|
|
|
|
// Greek lower
|
|
|
|
{0x83BF,0x83D6},
|
|
|
|
// Cyrillic upper
|
|
|
|
{0x8440,0x8460},
|
|
|
|
// Cyrillic lower
|
|
|
|
{0x8470,0x847E},{0x8480,0x8491},
|
|
|
|
// Kanji
|
|
|
|
{0x889F,0x88FC},
|
|
|
|
{0x8940,0x897E},{0x8980,0x89FC},
|
|
|
|
{0x8A40,0x8A7E},{0x8A80,0x8AFC},
|
|
|
|
{0x8B40,0x8B7E},{0x8B80,0x8BFC},
|
|
|
|
{0x8C40,0x8C7E},{0x8C80,0x8CFC},
|
|
|
|
{0x8D40,0x8D7E},{0x8D80,0x8DFC},
|
|
|
|
{0x8E40,0x8E7E},{0x8E80,0x8EFC},
|
|
|
|
{0x8F40,0x8F7E},{0x8F80,0x8FFC},
|
|
|
|
{0x9040,0x907E},{0x9080,0x90FC},
|
|
|
|
{0x9140,0x917E},{0x9180,0x91FC},
|
|
|
|
{0x9240,0x927E},{0x9280,0x92FC},
|
|
|
|
{0x9340,0x937E},{0x9380,0x93FC},
|
|
|
|
{0x9440,0x947E},{0x9480,0x94FC},
|
|
|
|
{0x9540,0x957E},{0x9580,0x95FC},
|
|
|
|
{0x9640,0x967E},{0x9680,0x96FC},
|
|
|
|
{0x9740,0x977E},{0x9780,0x97FC},
|
|
|
|
{0x9840,0x9872}
|
|
|
|
};
|
|
|
|
|
|
|
|
int ch = (f << 8) | (s & 0xFF);
|
|
|
|
int offset = 0;
|
|
|
|
for (int i = 0; i < rangeCnt; ++i) {
|
|
|
|
if (ch >= rangeTbl[i][0] && ch <= rangeTbl[i][1])
|
|
|
|
return offset + ch - rangeTbl[i][0];
|
|
|
|
offset += rangeTbl[i][1] - rangeTbl[i][0] + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(4, "Invalid Char: 0x%x", ch);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-20 22:04:06 +00:00
|
|
|
byte *ScummEngine::get2byteCharPtr(int idx) {
|
2007-09-19 08:40:12 +00:00
|
|
|
switch (_language) {
|
2004-09-20 22:04:06 +00:00
|
|
|
case Common::KO_KOR:
|
|
|
|
idx = ((idx % 256) - 0xb0) * 94 + (idx / 256) - 0xa1;
|
|
|
|
break;
|
|
|
|
case Common::JA_JPN:
|
2009-11-22 08:20:20 +00:00
|
|
|
if (_game.id == GID_LOOM && _game.platform == Common::kPlatformPCEngine) {
|
|
|
|
idx = SJIStoPCEChunk((idx % 256), (idx / 256));
|
|
|
|
return _2byteFontPtr + (_2byteWidth * _2byteHeight / 8) * idx;
|
2009-12-30 20:51:49 +00:00
|
|
|
} else if (_game.id == GID_MONKEY && _game.platform == Common::kPlatformSegaCD && _language == Common::JA_JPN) {
|
|
|
|
// init pointer to charset resource
|
|
|
|
if (_2byteFontPtr[0] == 0xFF) {
|
|
|
|
int charsetId = 5;
|
|
|
|
int numChar = 1413;
|
|
|
|
byte *charsetPtr = getResourceAddress(rtCharset, charsetId);
|
|
|
|
if (charsetPtr == 0)
|
|
|
|
error("ScummEngine::get2byteCharPtr: charset %d not found", charsetId);
|
|
|
|
memcpy(_2byteFontPtr, charsetPtr + 46, _2byteWidth * _2byteHeight * numChar / 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = ((idx & 0x7F) << 8) | ((idx >> 8) & 0xFF) - 1;
|
2009-11-22 08:20:20 +00:00
|
|
|
} else {
|
|
|
|
idx = SJIStoFMTChunk((idx % 256), (idx / 256));
|
|
|
|
}
|
2004-09-20 22:04:06 +00:00
|
|
|
break;
|
|
|
|
case Common::ZH_TWN:
|
2007-07-21 22:40:02 +00:00
|
|
|
{
|
|
|
|
int base = 0;
|
|
|
|
byte low = idx % 256;
|
|
|
|
int high = 0;
|
|
|
|
|
|
|
|
if (low >= 0x20 && low <= 0x7e) {
|
2008-04-26 20:33:59 +00:00
|
|
|
base = (3 * low + 81012) * 5;
|
2007-07-21 22:40:02 +00:00
|
|
|
} else {
|
|
|
|
if (low >= 0xa1 && low <= 0xa3) {
|
|
|
|
base = 392820;
|
|
|
|
low += 0x5f;
|
|
|
|
} else if (low >= 0xa4 && low <= 0xc6) {
|
|
|
|
base = 0;
|
|
|
|
low += 0x5c;
|
|
|
|
} else if (low >= 0xc9 && low <= 0xf9) {
|
|
|
|
base = 162030;
|
|
|
|
low += 0x37;
|
|
|
|
} else {
|
|
|
|
base = 392820;
|
|
|
|
low = 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (low != 0xff) {
|
|
|
|
high = idx / 256;
|
|
|
|
if (high >= 0x40 && high <= 0x7e) {
|
|
|
|
high -= 0x40;
|
|
|
|
} else {
|
|
|
|
high -= 0x62;
|
|
|
|
}
|
|
|
|
|
2007-07-21 22:57:21 +00:00
|
|
|
base += (low * 0x9d + high) * 30;
|
2007-07-21 22:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-21 22:57:21 +00:00
|
|
|
return _2byteFontPtr + base;
|
2007-07-21 22:40:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-09-20 22:04:06 +00:00
|
|
|
default:
|
|
|
|
idx = 0;
|
|
|
|
}
|
2008-01-28 00:14:17 +00:00
|
|
|
return _2byteFontPtr + ((_2byteWidth + 7) / 8) * _2byteHeight * idx;
|
2004-09-20 22:04:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
2003-10-02 22:42:03 +00:00
|
|
|
CharsetRenderer::CharsetRenderer(ScummEngine *vm) {
|
2003-05-20 15:12:33 +00:00
|
|
|
_top = 0;
|
|
|
|
_left = 0;
|
|
|
|
_startLeft = 0;
|
|
|
|
_right = 0;
|
|
|
|
|
|
|
|
_color = 0;
|
|
|
|
|
|
|
|
_center = false;
|
|
|
|
_hasMask = false;
|
2004-04-08 23:41:10 +00:00
|
|
|
_textScreenID = kMainVirtScreen;
|
2003-05-20 15:12:33 +00:00
|
|
|
_blitAlso = false;
|
|
|
|
_firstChar = false;
|
|
|
|
_disableOffsX = false;
|
|
|
|
|
|
|
|
_vm = vm;
|
2008-08-02 22:51:53 +00:00
|
|
|
_curId = -1;
|
2005-03-25 01:52:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CharsetRenderer::~CharsetRenderer() {
|
2003-05-20 15:12:33 +00:00
|
|
|
}
|
2004-08-30 11:52:33 +00:00
|
|
|
|
2005-06-04 16:10:39 +00:00
|
|
|
CharsetRendererCommon::CharsetRendererCommon(ScummEngine *vm)
|
2009-09-25 09:13:33 +00:00
|
|
|
: CharsetRenderer(vm), _bytesPerPixel(0), _fontHeight(0), _numChars(0) {
|
2005-06-04 16:10:39 +00:00
|
|
|
_shadowMode = kNoShadowMode;
|
|
|
|
_shadowColor = 0;
|
|
|
|
}
|
|
|
|
|
2008-08-02 22:51:53 +00:00
|
|
|
void CharsetRendererCommon::setCurID(int32 id) {
|
|
|
|
if (id == -1)
|
|
|
|
return;
|
|
|
|
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, id, _vm->_numCharsets - 1, "charset");
|
2002-12-26 00:21:19 +00:00
|
|
|
|
2002-12-25 21:04:47 +00:00
|
|
|
_curId = id;
|
|
|
|
|
2002-12-26 00:21:19 +00:00
|
|
|
_fontPtr = _vm->getResourceAddress(rtCharset, id);
|
2003-05-01 11:03:41 +00:00
|
|
|
if (_fontPtr == 0)
|
2009-05-31 10:02:16 +00:00
|
|
|
error("CharsetRendererCommon::setCurID: charset %d not found", id);
|
2003-05-01 11:03:41 +00:00
|
|
|
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_vm->_game.version == 4)
|
2002-12-26 00:21:19 +00:00
|
|
|
_fontPtr += 17;
|
2002-12-25 21:04:47 +00:00
|
|
|
else
|
2002-12-26 00:21:19 +00:00
|
|
|
_fontPtr += 29;
|
2005-05-26 16:38:02 +00:00
|
|
|
|
2009-09-25 09:13:33 +00:00
|
|
|
_bytesPerPixel = _fontPtr[0];
|
2005-05-26 16:38:02 +00:00
|
|
|
_fontHeight = _fontPtr[1];
|
|
|
|
_numChars = READ_LE_UINT16(_fontPtr + 2);
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
|
|
|
|
2008-08-02 22:51:53 +00:00
|
|
|
void CharsetRendererV3::setCurID(int32 id) {
|
|
|
|
if (id == -1)
|
|
|
|
return;
|
|
|
|
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, id, _vm->_numCharsets - 1, "charset");
|
2003-05-08 22:44:46 +00:00
|
|
|
|
|
|
|
_curId = id;
|
|
|
|
|
|
|
|
_fontPtr = _vm->getResourceAddress(rtCharset, id);
|
|
|
|
if (_fontPtr == 0)
|
2009-05-31 10:02:16 +00:00
|
|
|
error("CharsetRendererCommon::setCurID: charset %d not found", id);
|
2003-05-08 22:44:46 +00:00
|
|
|
|
2009-09-25 09:13:33 +00:00
|
|
|
_bytesPerPixel = 1;
|
2004-08-23 08:37:55 +00:00
|
|
|
_numChars = _fontPtr[4];
|
2005-05-26 16:38:02 +00:00
|
|
|
_fontHeight = _fontPtr[5];
|
|
|
|
|
2003-05-08 22:44:46 +00:00
|
|
|
_fontPtr += 6;
|
|
|
|
_widthTable = _fontPtr;
|
2004-08-23 08:37:55 +00:00
|
|
|
_fontPtr += _numChars;
|
2003-05-08 22:44:46 +00:00
|
|
|
}
|
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
int CharsetRendererCommon::getFontHeight() {
|
2005-05-08 21:49:52 +00:00
|
|
|
if (_vm->_useCJKMode)
|
2005-05-26 16:38:02 +00:00
|
|
|
return MAX(_vm->_2byteHeight + 1, _fontHeight);
|
2004-10-23 23:08:53 +00:00
|
|
|
else
|
2005-05-26 16:38:02 +00:00
|
|
|
return _fontHeight;
|
2004-10-23 23:08:53 +00:00
|
|
|
}
|
|
|
|
|
2002-12-25 21:04:47 +00:00
|
|
|
// do spacing for variable width old-style font
|
2003-03-06 17:58:13 +00:00
|
|
|
int CharsetRendererClassic::getCharWidth(byte chr) {
|
2004-09-18 22:42:45 +00:00
|
|
|
if (chr >= 0x80 && _vm->_useCJKMode)
|
2007-07-10 01:26:12 +00:00
|
|
|
return _vm->_2byteWidth / 2;
|
2002-12-25 21:04:47 +00:00
|
|
|
int spacing = 0;
|
2002-12-25 21:57:01 +00:00
|
|
|
|
2002-12-26 00:21:19 +00:00
|
|
|
int offs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
|
2002-12-25 21:57:01 +00:00
|
|
|
if (offs) {
|
2003-06-04 14:37:43 +00:00
|
|
|
spacing = _fontPtr[offs] + (signed char)_fontPtr[offs + 2];
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-12-25 21:57:01 +00:00
|
|
|
return spacing;
|
|
|
|
}
|
|
|
|
|
2003-05-21 16:28:02 +00:00
|
|
|
int CharsetRenderer::getStringWidth(int arg, const byte *text) {
|
2002-12-25 21:42:22 +00:00
|
|
|
int pos = 0;
|
2002-12-26 00:21:19 +00:00
|
|
|
int width = 1;
|
2002-12-25 21:04:47 +00:00
|
|
|
byte chr;
|
2003-06-19 11:13:11 +00:00
|
|
|
int oldID = getCurID();
|
2006-02-20 16:51:30 +00:00
|
|
|
int code = (_vm->_game.heversion >= 80) ? 127 : 64;
|
2002-12-25 21:04:47 +00:00
|
|
|
|
|
|
|
while ((chr = text[pos++]) != 0) {
|
2008-04-28 15:21:36 +00:00
|
|
|
if (chr == '\n' || chr == '\r' || chr == _vm->_newLineCharacter)
|
2005-11-04 23:52:01 +00:00
|
|
|
break;
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_vm->_game.heversion >= 72) {
|
2005-11-04 13:09:57 +00:00
|
|
|
if (chr == code) {
|
|
|
|
chr = text[pos++];
|
2005-11-04 23:52:01 +00:00
|
|
|
if (chr == 84 || chr == 116) { // Strings of speech offset/size
|
2005-11-04 13:09:57 +00:00
|
|
|
while (chr != code)
|
|
|
|
chr = text[pos++];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (chr == 119) // 'Wait'
|
|
|
|
break;
|
|
|
|
if (chr == 104|| chr == 110) // 'Newline'
|
2002-12-25 21:04:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-11-04 13:09:57 +00:00
|
|
|
} else {
|
2008-05-19 17:34:29 +00:00
|
|
|
if (chr == '@' && !(_vm->_game.id == GID_CMI && _vm->_language == Common::ZH_TWN))
|
2002-12-25 21:04:47 +00:00
|
|
|
continue;
|
2006-02-20 16:51:30 +00:00
|
|
|
if (chr == 255 || (_vm->_game.version <= 6 && chr == 254)) {
|
2005-11-04 13:09:57 +00:00
|
|
|
chr = text[pos++];
|
|
|
|
if (chr == 3) // 'WAIT'
|
|
|
|
break;
|
|
|
|
if (chr == 8) { // 'Verb on next line'
|
|
|
|
if (arg == 1)
|
|
|
|
break;
|
|
|
|
while (text[pos++] == ' ')
|
|
|
|
;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (chr == 10 || chr == 21 || chr == 12 || chr == 13) {
|
|
|
|
pos += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (chr == 9 || chr == 1 || chr == 2) // 'Newline'
|
|
|
|
break;
|
|
|
|
if (chr == 14) {
|
|
|
|
int set = text[pos] | (text[pos + 1] << 8);
|
|
|
|
pos += 2;
|
|
|
|
setCurID(set);
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2007-07-22 22:59:08 +00:00
|
|
|
// Some localizations may override colors
|
|
|
|
// See credits in Chinese COMI
|
2008-05-19 17:34:29 +00:00
|
|
|
if (_vm->_game.id == GID_CMI && _vm->_language == Common::ZH_TWN &&
|
|
|
|
chr == '^' && pos == 1) {
|
2007-07-22 22:59:08 +00:00
|
|
|
if (text[pos] == 'c') {
|
|
|
|
pos += 4;
|
|
|
|
chr = text[pos++];
|
|
|
|
}
|
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
2004-10-23 23:08:53 +00:00
|
|
|
if ((chr & 0x80) && _vm->_useCJKMode) {
|
|
|
|
pos++;
|
|
|
|
width += _vm->_2byteWidth;
|
|
|
|
} else {
|
|
|
|
width += getCharWidth(chr);
|
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
|
|
|
|
2002-12-26 00:21:19 +00:00
|
|
|
setCurID(oldID);
|
|
|
|
|
2002-12-25 21:04:47 +00:00
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
void CharsetRenderer::addLinebreaks(int a, byte *str, int pos, int maxwidth) {
|
2002-12-25 21:04:47 +00:00
|
|
|
int lastspace = -1;
|
|
|
|
int curw = 1;
|
|
|
|
byte chr;
|
2003-06-19 11:13:11 +00:00
|
|
|
int oldID = getCurID();
|
2006-02-20 16:51:30 +00:00
|
|
|
int code = (_vm->_game.heversion >= 80) ? 127 : 64;
|
2002-12-25 21:04:47 +00:00
|
|
|
|
|
|
|
while ((chr = str[pos++]) != 0) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_vm->_game.heversion >= 72) {
|
2005-11-04 13:09:57 +00:00
|
|
|
if (chr == code) {
|
|
|
|
chr = str[pos++];
|
2005-11-04 23:52:01 +00:00
|
|
|
if (chr == 84 || chr == 116) { // Strings of speech offset/size
|
2005-11-04 13:09:57 +00:00
|
|
|
while (chr != code)
|
|
|
|
chr = str[pos++];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (chr == 119) // 'Wait'
|
|
|
|
break;
|
|
|
|
if (chr == 110) { // 'Newline'
|
2002-12-25 21:04:47 +00:00
|
|
|
curw = 1;
|
2005-11-04 13:09:57 +00:00
|
|
|
continue;
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
2005-11-04 13:09:57 +00:00
|
|
|
if (chr == 104) // 'Don't terminate with \n'
|
|
|
|
break;
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
2005-11-04 13:09:57 +00:00
|
|
|
} else {
|
|
|
|
if (chr == '@')
|
2002-12-25 21:04:47 +00:00
|
|
|
continue;
|
2006-02-20 16:51:30 +00:00
|
|
|
if (chr == 255 || (_vm->_game.version <= 6 && chr == 254)) {
|
2005-11-04 13:09:57 +00:00
|
|
|
chr = str[pos++];
|
|
|
|
if (chr == 3) // 'Wait'
|
|
|
|
break;
|
|
|
|
if (chr == 8) { // 'Verb on next line'
|
|
|
|
if (a == 1) {
|
|
|
|
curw = 1;
|
|
|
|
} else {
|
|
|
|
while (str[pos] == ' ')
|
|
|
|
str[pos++] = '@';
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (chr == 10 || chr == 21 || chr == 12 || chr == 13) {
|
|
|
|
pos += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (chr == 1) { // 'Newline'
|
|
|
|
curw = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (chr == 2) // 'Don't terminate with \n'
|
|
|
|
break;
|
|
|
|
if (chr == 14) {
|
|
|
|
int set = str[pos] | (str[pos + 1] << 8);
|
|
|
|
pos += 2;
|
|
|
|
setCurID(set);
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chr == ' ')
|
|
|
|
lastspace = pos - 1;
|
|
|
|
|
2008-04-28 15:21:36 +00:00
|
|
|
if (chr == _vm->_newLineCharacter)
|
|
|
|
lastspace = pos - 1;
|
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
if ((chr & 0x80) && _vm->_useCJKMode) {
|
|
|
|
pos++;
|
|
|
|
curw += _vm->_2byteWidth;
|
|
|
|
} else {
|
|
|
|
curw += getCharWidth(chr);
|
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
if (lastspace == -1)
|
|
|
|
continue;
|
|
|
|
if (curw > maxwidth) {
|
|
|
|
str[lastspace] = 0xD;
|
|
|
|
curw = 1;
|
|
|
|
pos = lastspace + 1;
|
|
|
|
lastspace = -1;
|
|
|
|
}
|
|
|
|
}
|
2002-12-26 00:21:19 +00:00
|
|
|
|
|
|
|
setCurID(oldID);
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
|
|
|
|
2003-05-08 22:44:46 +00:00
|
|
|
int CharsetRendererV3::getCharWidth(byte chr) {
|
2004-10-23 23:08:53 +00:00
|
|
|
if (chr & 0x80 && _vm->_useCJKMode)
|
2007-07-10 01:26:12 +00:00
|
|
|
return _vm->_2byteWidth / 2;
|
2003-05-08 22:44:46 +00:00
|
|
|
int spacing = 0;
|
|
|
|
|
|
|
|
spacing = *(_widthTable + chr);
|
|
|
|
|
|
|
|
return spacing;
|
|
|
|
}
|
|
|
|
|
2007-09-10 13:17:20 +00:00
|
|
|
void CharsetRendererV3::setColor(byte color) {
|
2005-06-04 16:10:39 +00:00
|
|
|
bool useShadow = false;
|
2003-04-27 18:49:27 +00:00
|
|
|
_color = color;
|
2005-06-04 16:10:39 +00:00
|
|
|
|
2006-01-23 20:09:25 +00:00
|
|
|
// FM-TOWNS version of Loom uses old color method as well
|
2008-11-06 14:03:38 +00:00
|
|
|
if ((_vm->_game.version >= 2) && ((_vm->_game.features & GF_16COLOR) || (_vm->_game.id == GID_LOOM && _vm->_game.version == 3))) {
|
2005-06-04 16:10:39 +00:00
|
|
|
useShadow = ((_color & 0xF0) != 0);
|
2003-04-27 18:49:27 +00:00
|
|
|
_color &= 0x0f;
|
2006-02-20 16:51:30 +00:00
|
|
|
} else if (_vm->_game.features & GF_OLD256) {
|
2005-06-04 16:10:39 +00:00
|
|
|
useShadow = ((_color & 0x80) != 0);
|
2003-09-14 00:37:47 +00:00
|
|
|
_color &= 0x7f;
|
2003-04-27 18:49:27 +00:00
|
|
|
} else
|
2005-06-04 16:10:39 +00:00
|
|
|
useShadow = false;
|
|
|
|
|
|
|
|
enableShadow(useShadow);
|
2005-02-20 00:17:22 +00:00
|
|
|
|
|
|
|
translateColor();
|
2003-04-27 18:49:27 +00:00
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2009-11-22 11:43:12 +00:00
|
|
|
#ifdef USE_RGB_COLOR
|
2009-11-22 08:36:14 +00:00
|
|
|
void CharsetRendererPCE::setColor(byte color) {
|
|
|
|
_vm->setPCETextPalette(color);
|
|
|
|
_color = 15;
|
|
|
|
|
|
|
|
enableShadow(true);
|
|
|
|
}
|
2009-11-22 11:43:12 +00:00
|
|
|
#endif
|
2009-11-22 08:36:14 +00:00
|
|
|
|
2005-06-04 16:10:39 +00:00
|
|
|
void CharsetRendererCommon::enableShadow(bool enable) {
|
|
|
|
if (enable) {
|
2006-02-20 16:51:30 +00:00
|
|
|
if (_vm->_game.platform == Common::kPlatformFMTowns) {
|
2005-06-04 16:10:39 +00:00
|
|
|
_shadowColor = 8;
|
|
|
|
_shadowMode = kFMTOWNSShadowMode;
|
|
|
|
} else {
|
|
|
|
_shadowColor = 0;
|
|
|
|
_shadowMode = kNormalShadowMode;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_shadowMode = kNoShadowMode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-10 00:28:10 +00:00
|
|
|
void CharsetRendererV3::printChar(int chr, bool ignoreCharsetMask) {
|
2007-12-16 21:46:34 +00:00
|
|
|
// WORKAROUND for bug #1509509: Indy3 Mac does not show black
|
|
|
|
// characters (such as in the grail diary) if ignoreCharsetMask
|
|
|
|
// is true. See also patch #1851568.
|
|
|
|
if (_vm->_game.id == GID_INDY3 && _vm->_game.platform == Common::kPlatformMacintosh && _color == 0)
|
|
|
|
ignoreCharsetMask = false;
|
|
|
|
|
2003-04-28 17:17:39 +00:00
|
|
|
// Indy3 / Zak256 / Loom
|
2006-05-09 14:16:43 +00:00
|
|
|
int width, height, origWidth = 0, origHeight;
|
2002-12-25 21:04:47 +00:00
|
|
|
VirtScreen *vs;
|
2006-10-15 02:00:48 +00:00
|
|
|
const byte *charPtr;
|
|
|
|
byte *dst;
|
2004-10-23 23:08:53 +00:00
|
|
|
int is2byte = (chr >= 0x80 && _vm->_useCJKMode) ? 1 : 0;
|
2003-04-27 18:30:35 +00:00
|
|
|
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(0, _curId, _vm->_numCharsets - 1, "charset");
|
2002-12-25 21:04:47 +00:00
|
|
|
|
|
|
|
if ((vs = _vm->findVirtScreen(_top)) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (chr == '@')
|
|
|
|
return;
|
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
if (is2byte) {
|
|
|
|
charPtr = _vm->get2byteCharPtr(chr);
|
|
|
|
width = _vm->_2byteWidth;
|
|
|
|
height = _vm->_2byteHeight;
|
|
|
|
} else {
|
|
|
|
charPtr = _fontPtr + chr * 8;
|
|
|
|
width = getCharWidth(chr);
|
|
|
|
height = 8;
|
|
|
|
}
|
|
|
|
|
2006-05-07 11:45:55 +00:00
|
|
|
// Clip at the right side (to avoid drawing "outside" the screen bounds).
|
|
|
|
if (_left + origWidth > _right + 1)
|
|
|
|
return;
|
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
origWidth = width;
|
|
|
|
origHeight = height;
|
|
|
|
|
2005-06-04 16:10:39 +00:00
|
|
|
if (_shadowMode != kNoShadowMode) {
|
2004-10-23 23:08:53 +00:00
|
|
|
width++;
|
|
|
|
height++;
|
|
|
|
}
|
|
|
|
|
2002-12-25 21:04:47 +00:00
|
|
|
if (_firstChar) {
|
2003-05-15 22:30:32 +00:00
|
|
|
_str.left = _left;
|
|
|
|
_str.top = _top;
|
|
|
|
_str.right = _left;
|
|
|
|
_str.bottom = _top;
|
2002-12-25 21:04:47 +00:00
|
|
|
_firstChar = false;
|
|
|
|
}
|
2003-04-07 14:38:26 +00:00
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
int drawTop = _top - vs->topline;
|
2003-04-28 17:17:39 +00:00
|
|
|
|
2004-04-06 22:02:02 +00:00
|
|
|
_vm->markRectAsDirty(vs->number, _left, _left + width, drawTop, drawTop + height);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-01-10 00:28:10 +00:00
|
|
|
if (!ignoreCharsetMask) {
|
2003-04-28 17:17:39 +00:00
|
|
|
_hasMask = true;
|
2004-04-08 23:41:10 +00:00
|
|
|
_textScreenID = vs->number;
|
|
|
|
}
|
2007-07-10 00:39:12 +00:00
|
|
|
if ((ignoreCharsetMask || !vs->hasTwoBuffers) && !(_vm->_useCJKMode && _vm->_textSurfaceMultiplier == 2)) {
|
2004-10-23 23:08:53 +00:00
|
|
|
dst = vs->getPixels(_left, drawTop);
|
2009-10-26 13:22:05 +00:00
|
|
|
drawBits1(*vs, dst, charPtr, drawTop, origWidth, origHeight, vs->bytesPerPixel);
|
2004-08-08 22:10:38 +00:00
|
|
|
} else {
|
2007-07-10 00:39:12 +00:00
|
|
|
dst = (byte *)_vm->_textSurface.getBasePtr(_left * _vm->_textSurfaceMultiplier, _top * _vm->_textSurfaceMultiplier);
|
2009-10-26 13:22:05 +00:00
|
|
|
drawBits1(_vm->_textSurface, dst, charPtr, drawTop, origWidth, origHeight, _vm->_textSurface.bytesPerPixel);
|
2004-08-08 22:10:38 +00:00
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
if (_str.left > _left)
|
|
|
|
_str.left = _left;
|
2003-04-27 18:30:35 +00:00
|
|
|
|
2007-07-10 00:39:12 +00:00
|
|
|
_left += origWidth / _vm->_textSurfaceMultiplier;
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
if (_str.right < _left) {
|
|
|
|
_str.right = _left;
|
2005-06-04 16:10:39 +00:00
|
|
|
if (_shadowMode != kNoShadowMode)
|
2003-05-15 22:30:32 +00:00
|
|
|
_str.right++;
|
2003-04-27 18:30:35 +00:00
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2007-07-10 00:39:12 +00:00
|
|
|
if (_str.bottom < _top + height / _vm->_textSurfaceMultiplier)
|
|
|
|
_str.bottom = _top + height / _vm->_textSurfaceMultiplier;
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
|
|
|
|
2004-08-23 08:37:55 +00:00
|
|
|
void CharsetRendererV3::drawChar(int chr, const Graphics::Surface &s, int x, int y) {
|
2006-10-15 02:00:48 +00:00
|
|
|
const byte *charPtr;
|
|
|
|
byte *dst;
|
2004-10-23 23:08:53 +00:00
|
|
|
int width, height;
|
|
|
|
int is2byte = (chr >= 0x80 && _vm->_useCJKMode) ? 1 : 0;
|
|
|
|
if (is2byte) {
|
|
|
|
charPtr = _vm->get2byteCharPtr(chr);
|
|
|
|
width = _vm->_2byteWidth;
|
|
|
|
height = _vm->_2byteHeight;
|
|
|
|
} else {
|
|
|
|
charPtr = _fontPtr + chr * 8;
|
|
|
|
// width = height = 8;
|
|
|
|
width = getCharWidth(chr);
|
|
|
|
height = 8;
|
|
|
|
}
|
|
|
|
dst = (byte *)s.pixels + y * s.pitch + x;
|
2009-10-26 13:22:05 +00:00
|
|
|
drawBits1(s, dst, charPtr, y, width, height, s.bytesPerPixel);
|
2004-08-23 08:37:55 +00:00
|
|
|
}
|
|
|
|
|
2005-02-20 00:17:22 +00:00
|
|
|
void CharsetRenderer::translateColor() {
|
|
|
|
// Based on disassembly
|
|
|
|
if (_vm->_renderMode == Common::kRenderCGA) {
|
2006-10-15 02:00:48 +00:00
|
|
|
static const byte CGAtextColorMap[16] = {0, 3, 3, 3, 5, 5, 5, 15,
|
2005-02-20 00:17:22 +00:00
|
|
|
15, 3, 3, 3, 5, 5, 15, 15};
|
|
|
|
_color = CGAtextColorMap[_color & 0x0f];
|
|
|
|
}
|
|
|
|
|
2005-03-02 21:46:51 +00:00
|
|
|
if (_vm->_renderMode == Common::kRenderHercA || _vm->_renderMode == Common::kRenderHercG) {
|
2006-10-15 02:00:48 +00:00
|
|
|
static const byte HercTextColorMap[16] = {0, 15, 2, 15, 15, 5, 15, 15,
|
2005-02-20 00:17:22 +00:00
|
|
|
8, 15, 15, 15, 15, 15, 15, 15};
|
|
|
|
_color = HercTextColorMap[_color & 0x0f];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-28 08:02:10 +00:00
|
|
|
void CharsetRenderer::saveLoadWithSerializer(Serializer *ser) {
|
|
|
|
static const SaveLoadEntry charsetRendererEntries[] = {
|
2008-08-02 22:51:53 +00:00
|
|
|
MKLINE_OLD(CharsetRenderer, _curId, sleByte, VER(73), VER(73)),
|
|
|
|
MKLINE(CharsetRenderer, _curId, sleInt32, VER(74)),
|
2007-05-28 08:02:10 +00:00
|
|
|
MKLINE(CharsetRenderer, _color, sleByte, VER(73)),
|
|
|
|
MKEND()
|
|
|
|
};
|
|
|
|
|
|
|
|
ser->saveLoadEntries(this, charsetRendererEntries);
|
|
|
|
|
|
|
|
if (ser->isLoading()) {
|
|
|
|
setCurID(_curId);
|
|
|
|
setColor(_color);
|
|
|
|
}
|
|
|
|
}
|
2004-08-23 08:37:55 +00:00
|
|
|
|
2006-01-10 00:28:10 +00:00
|
|
|
void CharsetRendererClassic::printChar(int chr, bool ignoreCharsetMask) {
|
2003-06-04 14:37:43 +00:00
|
|
|
int width, height, origWidth, origHeight;
|
2002-12-25 21:14:26 +00:00
|
|
|
int offsX, offsY;
|
2002-12-25 21:04:47 +00:00
|
|
|
VirtScreen *vs;
|
2003-06-04 14:37:43 +00:00
|
|
|
const byte *charPtr;
|
2007-01-28 20:11:31 +00:00
|
|
|
bool is2byte = (chr >= 0x80 && _vm->_useCJKMode);
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2006-09-16 13:38:43 +00:00
|
|
|
assertRange(1, _curId, _vm->_numCharsets - 1, "charset");
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-08 15:17:14 +00:00
|
|
|
if ((vs = _vm->findVirtScreen(_top)) == NULL && (vs = _vm->findVirtScreen(_top + getFontHeight())) == NULL)
|
2002-12-25 21:04:47 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (chr == '@')
|
|
|
|
return;
|
|
|
|
|
2005-02-20 00:17:22 +00:00
|
|
|
translateColor();
|
|
|
|
|
2002-12-26 00:21:19 +00:00
|
|
|
_vm->_charsetColorMap[1] = _color;
|
2003-11-08 21:59:32 +00:00
|
|
|
|
2003-06-07 00:49:36 +00:00
|
|
|
if (is2byte) {
|
2005-06-04 16:10:39 +00:00
|
|
|
enableShadow(true);
|
2003-12-27 14:03:07 +00:00
|
|
|
charPtr = _vm->get2byteCharPtr(chr);
|
|
|
|
width = _vm->_2byteWidth;
|
|
|
|
height = _vm->_2byteHeight;
|
2003-06-04 14:37:43 +00:00
|
|
|
offsX = offsY = 0;
|
|
|
|
} else {
|
|
|
|
uint32 charOffs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
|
|
|
|
assert(charOffs < 0x10000);
|
|
|
|
if (!charOffs)
|
|
|
|
return;
|
|
|
|
charPtr = _fontPtr + charOffs;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-04 14:37:43 +00:00
|
|
|
width = charPtr[0];
|
|
|
|
height = charPtr[1];
|
|
|
|
|
|
|
|
if (_disableOffsX) {
|
|
|
|
offsX = 0;
|
|
|
|
} else {
|
|
|
|
offsX = (signed char)charPtr[2];
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-04 14:37:43 +00:00
|
|
|
offsY = (signed char)charPtr[3];
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2003-06-04 14:37:43 +00:00
|
|
|
charPtr += 4; // Skip over char header
|
|
|
|
}
|
|
|
|
origWidth = width;
|
|
|
|
origHeight = height;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-06-04 16:10:39 +00:00
|
|
|
if (_shadowMode != kNoShadowMode) {
|
2003-06-04 14:37:43 +00:00
|
|
|
width++;
|
|
|
|
height++;
|
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
if (_firstChar) {
|
2003-05-15 22:30:32 +00:00
|
|
|
_str.left = 0;
|
|
|
|
_str.top = 0;
|
|
|
|
_str.right = 0;
|
|
|
|
_str.bottom = 0;
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
|
|
|
|
2002-12-25 21:14:26 +00:00
|
|
|
_top += offsY;
|
|
|
|
_left += offsX;
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2007-07-10 00:39:12 +00:00
|
|
|
if (_left + origWidth / _vm->_textSurfaceMultiplier > _right + 1 || _left < 0) {
|
|
|
|
_left += origWidth / _vm->_textSurfaceMultiplier;
|
2002-12-25 21:14:26 +00:00
|
|
|
_top -= offsY;
|
2002-12-25 21:04:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_disableOffsX = false;
|
|
|
|
|
|
|
|
if (_firstChar) {
|
2003-05-15 22:30:32 +00:00
|
|
|
_str.left = _left;
|
|
|
|
_str.top = _top;
|
|
|
|
_str.right = _left;
|
|
|
|
_str.bottom = _top;
|
2002-12-25 21:04:47 +00:00
|
|
|
_firstChar = false;
|
|
|
|
}
|
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
if (_left < _str.left)
|
|
|
|
_str.left = _left;
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2003-05-15 22:30:32 +00:00
|
|
|
if (_top < _str.top)
|
|
|
|
_str.top = _top;
|
2002-12-25 21:04:47 +00:00
|
|
|
|
|
|
|
int drawTop = _top - vs->topline;
|
|
|
|
|
2004-10-09 00:33:35 +00:00
|
|
|
_vm->markRectAsDirty(vs->number, _left, _left + width, drawTop, drawTop + height);
|
2002-12-25 21:04:47 +00:00
|
|
|
|
2006-01-10 00:28:10 +00:00
|
|
|
if (!ignoreCharsetMask) {
|
2002-12-25 21:04:47 +00:00
|
|
|
_hasMask = true;
|
2004-04-08 23:41:10 +00:00
|
|
|
_textScreenID = vs->number;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2007-01-28 20:11:31 +00:00
|
|
|
printCharIntern(is2byte, charPtr, origWidth, origHeight, width, height, vs, ignoreCharsetMask);
|
|
|
|
|
2007-07-10 00:39:12 +00:00
|
|
|
_left += origWidth / _vm->_textSurfaceMultiplier;
|
2007-01-28 20:11:31 +00:00
|
|
|
|
|
|
|
if (_str.right < _left) {
|
|
|
|
_str.right = _left;
|
|
|
|
if (_shadowMode != kNoShadowMode)
|
|
|
|
_str.right++;
|
|
|
|
}
|
|
|
|
|
2007-07-10 00:39:12 +00:00
|
|
|
if (_str.bottom < _top + height / _vm->_textSurfaceMultiplier)
|
|
|
|
_str.bottom = _top + height / _vm->_textSurfaceMultiplier;
|
2007-01-28 20:11:31 +00:00
|
|
|
|
|
|
|
_top -= offsY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharsetRendererClassic::printCharIntern(bool is2byte, const byte *charPtr, int origWidth, int origHeight, int width, int height, VirtScreen *vs, bool ignoreCharsetMask) {
|
|
|
|
byte *dstPtr;
|
|
|
|
byte *back = NULL;
|
|
|
|
int drawTop = _top - vs->topline;
|
|
|
|
|
2009-09-25 09:13:33 +00:00
|
|
|
if ((_vm->_game.heversion >= 71 && _bytesPerPixel >= 8) || (_vm->_game.heversion >= 90 && _bytesPerPixel == 0)) {
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef ENABLE_HE
|
2006-01-10 00:28:10 +00:00
|
|
|
if (ignoreCharsetMask || !vs->hasTwoBuffers) {
|
2005-04-23 14:32:40 +00:00
|
|
|
dstPtr = vs->getPixels(0, 0);
|
|
|
|
} else {
|
2007-01-28 20:11:31 +00:00
|
|
|
dstPtr = (byte *)_vm->_textSurface.pixels;
|
2004-10-06 01:01:44 +00:00
|
|
|
}
|
2004-10-05 23:37:59 +00:00
|
|
|
|
2005-04-23 14:32:40 +00:00
|
|
|
if (_blitAlso && vs->hasTwoBuffers) {
|
|
|
|
dstPtr = vs->getBackPixels(0, 0);
|
2004-10-06 01:01:44 +00:00
|
|
|
}
|
2004-10-05 23:37:59 +00:00
|
|
|
|
2005-04-23 14:32:40 +00:00
|
|
|
Common::Rect rScreen(vs->w, vs->h);
|
2009-09-25 09:13:33 +00:00
|
|
|
if (_bytesPerPixel >= 8) {
|
2005-04-23 14:32:40 +00:00
|
|
|
byte imagePalette[256];
|
|
|
|
memset(imagePalette, 0, sizeof(imagePalette));
|
2005-11-06 11:30:17 +00:00
|
|
|
memcpy(imagePalette, _vm->_charsetColorMap, 4);
|
2009-09-25 09:13:33 +00:00
|
|
|
Wiz::copyWizImage(dstPtr, charPtr, vs->pitch, kDstScreen, vs->w, vs->h, _left, _top, origWidth, origHeight, &rScreen, 0, imagePalette, NULL, _vm->_bytesPerPixel);
|
2005-04-23 14:32:40 +00:00
|
|
|
} else {
|
2009-09-25 09:13:33 +00:00
|
|
|
Wiz::copyWizImage(dstPtr, charPtr, vs->pitch, kDstScreen, vs->w, vs->h, _left, _top, origWidth, origHeight, &rScreen, 0, NULL, NULL, _vm->_bytesPerPixel);
|
2005-04-23 14:32:40 +00:00
|
|
|
}
|
2004-10-05 05:52:48 +00:00
|
|
|
|
2005-04-23 14:32:40 +00:00
|
|
|
if (_blitAlso && vs->hasTwoBuffers) {
|
|
|
|
Common::Rect dst(_left, _top, _left + origWidth, _top + origHeight);
|
2006-09-17 23:35:09 +00:00
|
|
|
((ScummEngine_v71he *)_vm)->restoreBackgroundHE(dst);
|
2005-04-23 14:32:40 +00:00
|
|
|
}
|
2005-05-14 14:06:37 +00:00
|
|
|
#endif
|
2005-04-23 14:32:40 +00:00
|
|
|
} else {
|
|
|
|
Graphics::Surface dstSurface;
|
|
|
|
Graphics::Surface backSurface;
|
2007-07-10 00:39:12 +00:00
|
|
|
if ((ignoreCharsetMask || !vs->hasTwoBuffers) && !(_vm->_useCJKMode && _vm->_textSurfaceMultiplier == 2)) {
|
2005-04-23 14:32:40 +00:00
|
|
|
dstSurface = *vs;
|
|
|
|
dstPtr = vs->getPixels(_left, drawTop);
|
|
|
|
} else {
|
2007-01-28 20:11:31 +00:00
|
|
|
dstSurface = _vm->_textSurface;
|
2007-07-10 00:39:12 +00:00
|
|
|
dstPtr = (byte *)_vm->_textSurface.pixels + (_top - _vm->_screenTop) * _vm->_textSurface.pitch * _vm->_textSurfaceMultiplier + _left * _vm->_textSurfaceMultiplier;
|
2005-04-23 14:32:40 +00:00
|
|
|
}
|
2004-10-05 05:52:48 +00:00
|
|
|
|
2005-04-23 14:32:40 +00:00
|
|
|
if (_blitAlso && vs->hasTwoBuffers) {
|
|
|
|
backSurface = dstSurface;
|
|
|
|
back = dstPtr;
|
|
|
|
dstSurface = *vs;
|
|
|
|
dstPtr = vs->getBackPixels(_left, drawTop);
|
|
|
|
}
|
2004-10-05 05:52:48 +00:00
|
|
|
|
2006-01-10 00:28:10 +00:00
|
|
|
if (!ignoreCharsetMask && vs->hasTwoBuffers) {
|
2005-04-23 14:32:40 +00:00
|
|
|
drawTop = _top - _vm->_screenTop;
|
|
|
|
}
|
2004-10-05 05:52:48 +00:00
|
|
|
|
|
|
|
if (is2byte) {
|
2009-10-26 13:22:05 +00:00
|
|
|
drawBits1(dstSurface, dstPtr, charPtr, drawTop, origWidth, origHeight, dstSurface.bytesPerPixel);
|
2004-10-05 05:52:48 +00:00
|
|
|
} else {
|
|
|
|
drawBitsN(dstSurface, dstPtr, charPtr, *_fontPtr, drawTop, origWidth, origHeight);
|
2004-09-27 20:42:10 +00:00
|
|
|
}
|
2004-10-05 05:52:48 +00:00
|
|
|
|
|
|
|
if (_blitAlso && vs->hasTwoBuffers) {
|
|
|
|
// FIXME: Revisiting this code, I think the _blitAlso mode is likely broken
|
|
|
|
// right now -- we are copying stuff from "dstPtr" to "back", but "dstPtr" really
|
2005-07-30 21:11:48 +00:00
|
|
|
// only conatains charset data...
|
2004-10-05 05:52:48 +00:00
|
|
|
// One way to fix this: don't copy etc.; rather simply render the char twice,
|
|
|
|
// once to each of the two buffers. That should hypothetically yield
|
|
|
|
// identical results, though I didn't try it and right now I don't know
|
|
|
|
// any spots where I can test this...
|
2006-01-10 00:28:10 +00:00
|
|
|
if (!ignoreCharsetMask)
|
2006-05-07 11:58:01 +00:00
|
|
|
error("This might be broken -- please report where you encountered this to Fingolfin");
|
2004-10-05 05:52:48 +00:00
|
|
|
|
|
|
|
// Perform some clipping
|
|
|
|
int w = MIN(width, dstSurface.w - _left);
|
|
|
|
int h = MIN(height, dstSurface.h - drawTop);
|
|
|
|
if (_left < 0) {
|
|
|
|
w += _left;
|
|
|
|
back -= _left;
|
|
|
|
dstPtr -= _left;
|
|
|
|
}
|
|
|
|
if (drawTop < 0) {
|
|
|
|
h += drawTop;
|
|
|
|
back -= drawTop * backSurface.pitch;
|
|
|
|
dstPtr -= drawTop * dstSurface.pitch;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-10-05 05:52:48 +00:00
|
|
|
// Blit the image data
|
|
|
|
if (w > 0) {
|
|
|
|
while (h-- > 0) {
|
|
|
|
memcpy(back, dstPtr, w);
|
|
|
|
back += backSurface.pitch;
|
|
|
|
dstPtr += dstSurface.pitch;
|
|
|
|
}
|
2004-09-29 00:04:38 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
}
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
|
|
|
|
2004-08-23 08:37:55 +00:00
|
|
|
void CharsetRendererClassic::drawChar(int chr, const Graphics::Surface &s, int x, int y) {
|
|
|
|
const byte *charPtr;
|
|
|
|
byte *dst;
|
2004-10-23 23:08:53 +00:00
|
|
|
int width, height;
|
|
|
|
int is2byte = (chr >= 0x80 && _vm->_useCJKMode) ? 1 : 0;
|
2004-08-23 08:37:55 +00:00
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
if (is2byte) {
|
2005-06-04 16:10:39 +00:00
|
|
|
enableShadow(true);
|
2004-10-23 23:08:53 +00:00
|
|
|
charPtr = _vm->get2byteCharPtr(chr);
|
|
|
|
width = _vm->_2byteWidth;
|
|
|
|
height = _vm->_2byteHeight;
|
|
|
|
} else {
|
|
|
|
uint32 charOffs = READ_LE_UINT32(_fontPtr + chr * 4 + 4);
|
|
|
|
assert(charOffs < 0x10000);
|
|
|
|
if (!charOffs)
|
|
|
|
return;
|
|
|
|
charPtr = _fontPtr + charOffs;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
width = charPtr[0];
|
|
|
|
height = charPtr[1];
|
2004-08-23 08:37:55 +00:00
|
|
|
|
2004-10-23 23:08:53 +00:00
|
|
|
charPtr += 4; // Skip over char header
|
|
|
|
}
|
2004-08-23 08:37:55 +00:00
|
|
|
|
|
|
|
dst = (byte *)s.pixels + y * s.pitch + x;
|
2004-10-23 23:08:53 +00:00
|
|
|
|
|
|
|
if (is2byte) {
|
2009-10-26 13:22:05 +00:00
|
|
|
drawBits1(s, dst, charPtr, y, width, height, s.bytesPerPixel);
|
2004-10-23 23:08:53 +00:00
|
|
|
} else {
|
|
|
|
drawBitsN(s, dst, charPtr, *_fontPtr, y, width, height);
|
|
|
|
}
|
2004-08-23 08:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CharsetRendererClassic::drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height) {
|
2002-12-25 21:04:47 +00:00
|
|
|
int y, x;
|
|
|
|
int color;
|
|
|
|
byte numbits, bits;
|
|
|
|
|
2003-06-19 11:13:11 +00:00
|
|
|
assert(bpp == 1 || bpp == 2 || bpp == 4 || bpp == 8);
|
2003-06-04 14:37:43 +00:00
|
|
|
bits = *src++;
|
2002-12-25 21:04:47 +00:00
|
|
|
numbits = 8;
|
|
|
|
|
2004-08-23 08:37:55 +00:00
|
|
|
for (y = 0; y < height && y + drawTop < s.h; y++) {
|
2002-12-25 21:04:47 +00:00
|
|
|
for (x = 0; x < width; x++) {
|
2003-06-04 14:37:43 +00:00
|
|
|
color = (bits >> (8 - bpp)) & 0xFF;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-06-08 15:17:14 +00:00
|
|
|
if (color && y + drawTop >= 0) {
|
2003-06-04 14:37:43 +00:00
|
|
|
*dst = _vm->_charsetColorMap[color];
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
|
|
|
dst++;
|
2003-06-04 14:37:43 +00:00
|
|
|
bits <<= bpp;
|
|
|
|
numbits -= bpp;
|
2002-12-25 21:04:47 +00:00
|
|
|
if (numbits == 0) {
|
2003-06-04 14:37:43 +00:00
|
|
|
bits = *src++;
|
2002-12-25 21:04:47 +00:00
|
|
|
numbits = 8;
|
|
|
|
}
|
|
|
|
}
|
2004-08-23 08:37:55 +00:00
|
|
|
dst += s.pitch - width;
|
2002-12-25 21:04:47 +00:00
|
|
|
}
|
|
|
|
}
|
2002-12-26 01:47:40 +00:00
|
|
|
|
2009-10-26 13:22:05 +00:00
|
|
|
void CharsetRendererCommon::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth) {
|
2003-06-04 14:37:43 +00:00
|
|
|
int y, x;
|
|
|
|
byte bits = 0;
|
|
|
|
|
2004-08-23 08:37:55 +00:00
|
|
|
for (y = 0; y < height && y + drawTop < s.h; y++) {
|
2003-06-04 14:37:43 +00:00
|
|
|
for (x = 0; x < width; x++) {
|
2003-06-07 00:49:36 +00:00
|
|
|
if ((x % 8) == 0)
|
2003-06-04 14:37:43 +00:00
|
|
|
bits = *src++;
|
2005-05-15 10:40:28 +00:00
|
|
|
if ((bits & revBitMask(x % 8)) && y + drawTop >= 0) {
|
2009-10-26 13:22:05 +00:00
|
|
|
if (bitDepth == 2) {
|
|
|
|
if (_shadowMode != kNoShadowMode) {
|
2009-10-26 14:49:01 +00:00
|
|
|
WRITE_UINT16(dst + 2, _vm->_16BitPalette[_shadowColor]);
|
|
|
|
WRITE_UINT16(dst + s.pitch, _vm->_16BitPalette[_shadowColor]);
|
2009-10-26 13:22:05 +00:00
|
|
|
if (_shadowMode != kFMTOWNSShadowMode)
|
2009-10-26 14:49:01 +00:00
|
|
|
WRITE_UINT16(dst + s.pitch + 2, _vm->_16BitPalette[_shadowColor]);
|
2009-10-26 13:22:05 +00:00
|
|
|
}
|
2009-10-26 14:49:01 +00:00
|
|
|
WRITE_UINT16(dst, _vm->_16BitPalette[_color]);
|
2009-10-26 13:22:05 +00:00
|
|
|
} else {
|
|
|
|
if (_shadowMode != kNoShadowMode) {
|
|
|
|
*(dst + 1) = _shadowColor;
|
|
|
|
*(dst + s.pitch) = _shadowColor;
|
|
|
|
if (_shadowMode != kFMTOWNSShadowMode)
|
|
|
|
*(dst + s.pitch + 1) = _shadowColor;
|
|
|
|
}
|
|
|
|
*dst = _color;
|
2005-07-30 21:11:48 +00:00
|
|
|
}
|
2003-06-04 14:37:43 +00:00
|
|
|
}
|
2009-10-26 13:22:05 +00:00
|
|
|
dst += bitDepth;
|
2003-06-04 14:37:43 +00:00
|
|
|
}
|
|
|
|
|
2009-10-26 13:22:05 +00:00
|
|
|
dst += s.pitch - width * bitDepth;
|
2003-06-04 14:37:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-22 11:43:12 +00:00
|
|
|
#ifdef USE_RGB_COLOR
|
2009-11-22 08:20:20 +00:00
|
|
|
void CharsetRendererPCE::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth) {
|
|
|
|
int y, x;
|
|
|
|
int bitCount = 0;
|
|
|
|
byte bits = 0;
|
|
|
|
|
|
|
|
const bool resetLineBitCount = (_vm->_language != Common::JA_JPN || width != 12);
|
|
|
|
|
|
|
|
for (y = 0; y < height && y + drawTop < s.h; y++) {
|
|
|
|
if (resetLineBitCount)
|
|
|
|
bitCount = 0;
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
if ((bitCount % 8) == 0)
|
|
|
|
bits = *src++;
|
|
|
|
if ((bits & revBitMask(bitCount % 8)) && y + drawTop >= 0) {
|
|
|
|
if (bitDepth == 2) {
|
|
|
|
if (_shadowMode != kNoShadowMode) {
|
2009-11-22 11:36:30 +00:00
|
|
|
WRITE_UINT16(dst + s.pitch + 2, _vm->_16BitPalette[_shadowColor]);
|
2009-11-22 08:20:20 +00:00
|
|
|
}
|
|
|
|
WRITE_UINT16(dst, _vm->_16BitPalette[_color]);
|
|
|
|
} else {
|
|
|
|
if (_shadowMode != kNoShadowMode) {
|
2009-11-22 11:36:30 +00:00
|
|
|
*(dst + s.pitch + 1) = _shadowColor;
|
2009-11-22 08:20:20 +00:00
|
|
|
}
|
|
|
|
*dst = _color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst += bitDepth;
|
|
|
|
bitCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst += s.pitch - width * bitDepth;
|
|
|
|
}
|
|
|
|
}
|
2009-11-22 11:43:12 +00:00
|
|
|
#endif
|
2009-11-22 08:20:20 +00:00
|
|
|
|
2008-05-06 03:00:26 +00:00
|
|
|
#ifdef ENABLE_SCUMM_7_8
|
2003-10-02 22:42:03 +00:00
|
|
|
CharsetRendererNut::CharsetRendererNut(ScummEngine *vm)
|
2003-03-06 17:58:13 +00:00
|
|
|
: CharsetRenderer(vm) {
|
2002-12-26 01:47:40 +00:00
|
|
|
_current = 0;
|
2003-03-04 02:43:43 +00:00
|
|
|
|
2002-12-31 21:41:24 +00:00
|
|
|
for (int i = 0; i < 5; i++) {
|
2007-01-27 01:50:41 +00:00
|
|
|
_fr[i] = NULL;
|
2002-12-26 01:47:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
CharsetRendererNut::~CharsetRendererNut() {
|
2003-11-18 05:14:18 +00:00
|
|
|
for (int i = 0; i < 5; i++) {
|
2002-12-26 01:47:40 +00:00
|
|
|
delete _fr[i];
|
2003-11-18 05:14:18 +00:00
|
|
|
}
|
2002-12-26 01:47:40 +00:00
|
|
|
}
|
|
|
|
|
2008-08-02 22:51:53 +00:00
|
|
|
void CharsetRendererNut::setCurID(int32 id) {
|
|
|
|
if (id == -1)
|
|
|
|
return;
|
|
|
|
|
2007-01-27 01:50:41 +00:00
|
|
|
int numFonts = ((_vm->_game.id == GID_CMI) && (_vm->_game.features & GF_DEMO)) ? 4 : 5;
|
|
|
|
assert(id < numFonts);
|
2002-12-26 01:47:40 +00:00
|
|
|
_curId = id;
|
2007-01-27 01:50:41 +00:00
|
|
|
if (!_fr[id]) {
|
|
|
|
char fontname[11];
|
|
|
|
sprintf(fontname, "font%d.nut", id);
|
2007-02-03 05:50:35 +00:00
|
|
|
_fr[id] = new NutRenderer(_vm, fontname);
|
2007-01-27 01:50:41 +00:00
|
|
|
}
|
2002-12-26 01:47:40 +00:00
|
|
|
_current = _fr[id];
|
2003-03-04 02:43:43 +00:00
|
|
|
assert(_current);
|
2002-12-26 01:47:40 +00:00
|
|
|
}
|
|
|
|
|
2005-05-26 12:26:03 +00:00
|
|
|
int CharsetRendererNut::getCharHeight(byte chr) {
|
|
|
|
assert(_current);
|
|
|
|
return _current->getCharHeight(chr);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int CharsetRendererNut::getCharWidth(byte chr) {
|
2002-12-26 01:47:40 +00:00
|
|
|
assert(_current);
|
|
|
|
return _current->getCharWidth(chr);
|
|
|
|
}
|
|
|
|
|
2003-03-06 17:58:13 +00:00
|
|
|
int CharsetRendererNut::getFontHeight() {
|
2002-12-26 01:47:40 +00:00
|
|
|
// FIXME / TODO: how to implement this properly???
|
|
|
|
assert(_current);
|
|
|
|
return _current->getCharHeight('|');
|
|
|
|
}
|
|
|
|
|
2006-01-10 00:28:10 +00:00
|
|
|
void CharsetRendererNut::printChar(int chr, bool ignoreCharsetMask) {
|
2004-01-08 03:10:16 +00:00
|
|
|
Common::Rect shadow;
|
2003-06-15 15:19:22 +00:00
|
|
|
|
2002-12-26 01:47:40 +00:00
|
|
|
assert(_current);
|
|
|
|
if (chr == '@')
|
|
|
|
return;
|
|
|
|
|
2007-02-03 05:50:35 +00:00
|
|
|
shadow.left = _left;
|
|
|
|
shadow.top = _top;
|
2003-06-15 15:19:22 +00:00
|
|
|
|
2002-12-26 01:47:40 +00:00
|
|
|
if (_firstChar) {
|
2004-04-03 23:44:06 +00:00
|
|
|
_str.left = (shadow.left >= 0) ? shadow.left : 0;
|
|
|
|
_str.top = (shadow.top >= 0) ? shadow.top : 0;
|
|
|
|
_str.right = _str.left;
|
|
|
|
_str.bottom = _str.top;
|
2002-12-26 01:47:40 +00:00
|
|
|
_firstChar = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width = _current->getCharWidth(chr);
|
|
|
|
int height = _current->getCharHeight(chr);
|
|
|
|
|
2004-09-18 22:42:45 +00:00
|
|
|
if (chr >= 256 && _vm->_useCJKMode)
|
2004-10-23 23:08:53 +00:00
|
|
|
width = _vm->_2byteWidth;
|
2003-06-04 14:37:43 +00:00
|
|
|
|
2007-02-03 05:50:35 +00:00
|
|
|
shadow.right = _left + width;
|
|
|
|
shadow.bottom = _top + height;
|
2003-06-15 15:19:22 +00:00
|
|
|
|
2004-08-08 22:10:38 +00:00
|
|
|
Graphics::Surface s;
|
2006-01-10 00:28:10 +00:00
|
|
|
if (!ignoreCharsetMask) {
|
2004-04-08 01:38:07 +00:00
|
|
|
_hasMask = true;
|
2004-04-08 23:41:10 +00:00
|
|
|
_textScreenID = kMainVirtScreen;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-10-01 09:06:12 +00:00
|
|
|
int drawTop = _top;
|
2006-01-10 00:28:10 +00:00
|
|
|
if (ignoreCharsetMask) {
|
2007-09-08 11:15:27 +00:00
|
|
|
VirtScreen *vs = &_vm->_virtscr[kMainVirtScreen];
|
2004-08-14 19:42:00 +00:00
|
|
|
s = *vs;
|
2004-10-01 09:06:12 +00:00
|
|
|
s.pixels = vs->getPixels(0, 0);
|
2004-08-08 22:10:38 +00:00
|
|
|
} else {
|
2007-01-28 20:11:31 +00:00
|
|
|
s = _vm->_textSurface;
|
2004-10-01 09:06:12 +00:00
|
|
|
drawTop -= _vm->_screenTop;
|
2004-08-08 22:10:38 +00:00
|
|
|
}
|
2004-04-08 01:38:07 +00:00
|
|
|
|
2007-02-03 05:50:35 +00:00
|
|
|
if (chr >= 256 && _vm->_useCJKMode)
|
|
|
|
_current->draw2byte(s, chr, _left, drawTop, _color);
|
|
|
|
else
|
|
|
|
_current->drawChar(s, (byte)chr, _left, drawTop, _color);
|
2004-01-08 03:24:41 +00:00
|
|
|
_vm->markRectAsDirty(kMainVirtScreen, shadow);
|
2002-12-26 01:47:40 +00:00
|
|
|
|
2004-01-08 02:16:27 +00:00
|
|
|
if (_str.left > _left)
|
|
|
|
_str.left = _left;
|
|
|
|
|
2007-07-21 22:40:02 +00:00
|
|
|
// Original keeps glyph width and character dimensions separately
|
2007-07-22 21:01:31 +00:00
|
|
|
if (_vm->_language == Common::ZH_TWN && width == 16)
|
2007-07-21 22:40:02 +00:00
|
|
|
width = 17;
|
|
|
|
|
2002-12-26 01:47:40 +00:00
|
|
|
_left += width;
|
|
|
|
|
2004-02-22 21:02:06 +00:00
|
|
|
if (_str.right < shadow.right)
|
2004-01-08 03:10:16 +00:00
|
|
|
_str.right = shadow.right;
|
2003-06-15 15:19:22 +00:00
|
|
|
|
2004-01-08 03:10:16 +00:00
|
|
|
if (_str.bottom < shadow.bottom)
|
|
|
|
_str.bottom = shadow.bottom;
|
2002-12-26 01:47:40 +00:00
|
|
|
}
|
2005-06-18 15:44:40 +00:00
|
|
|
#endif
|
2002-12-26 01:47:40 +00:00
|
|
|
|
2006-01-10 00:28:10 +00:00
|
|
|
void CharsetRendererNES::printChar(int chr, bool ignoreCharsetMask) {
|
2005-03-16 03:20:32 +00:00
|
|
|
int width, height, origWidth, origHeight;
|
|
|
|
VirtScreen *vs;
|
|
|
|
byte *charPtr, *dst;
|
|
|
|
|
2005-05-20 22:49:09 +00:00
|
|
|
// Init it here each time since it is cheap and fixes bug with
|
|
|
|
// charset after game load
|
|
|
|
_trTable = _vm->getResourceAddress(rtCostume, 77) + 2;
|
2005-04-10 09:58:37 +00:00
|
|
|
|
2005-03-24 04:53:28 +00:00
|
|
|
// HACK: how to set it properly?
|
|
|
|
if (_top == 0)
|
|
|
|
_top = 16;
|
|
|
|
|
2005-03-16 03:20:32 +00:00
|
|
|
if ((vs = _vm->findVirtScreen(_top)) == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (chr == '@')
|
|
|
|
return;
|
|
|
|
|
2005-03-24 03:22:32 +00:00
|
|
|
charPtr = _vm->_NESPatTable[1] + _trTable[chr - 32] * 16;
|
2005-03-16 03:20:32 +00:00
|
|
|
width = getCharWidth(chr);
|
|
|
|
height = 8;
|
|
|
|
|
|
|
|
origWidth = width;
|
|
|
|
origHeight = height;
|
|
|
|
|
|
|
|
if (_firstChar) {
|
|
|
|
_str.left = _left;
|
|
|
|
_str.top = _top;
|
|
|
|
_str.right = _left;
|
|
|
|
_str.bottom = _top;
|
|
|
|
_firstChar = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int drawTop = _top - vs->topline;
|
|
|
|
|
|
|
|
_vm->markRectAsDirty(vs->number, _left, _left + width, drawTop, drawTop + height);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-01-10 00:28:10 +00:00
|
|
|
if (!ignoreCharsetMask) {
|
2005-03-16 03:20:32 +00:00
|
|
|
_hasMask = true;
|
|
|
|
_textScreenID = vs->number;
|
|
|
|
}
|
2005-03-23 04:22:11 +00:00
|
|
|
|
2006-01-10 00:28:10 +00:00
|
|
|
if (ignoreCharsetMask || !vs->hasTwoBuffers) {
|
2005-03-23 04:22:11 +00:00
|
|
|
dst = vs->getPixels(_left, drawTop);
|
2009-10-26 13:22:05 +00:00
|
|
|
drawBits1(*vs, dst, charPtr, drawTop, origWidth, origHeight, vs->bytesPerPixel);
|
2005-03-23 04:22:11 +00:00
|
|
|
} else {
|
2007-01-28 20:11:31 +00:00
|
|
|
dst = (byte *)_vm->_textSurface.pixels + _top * _vm->_textSurface.pitch + _left;
|
2009-10-26 13:22:05 +00:00
|
|
|
drawBits1(_vm->_textSurface, dst, charPtr, drawTop, origWidth, origHeight, _vm->_textSurface.bytesPerPixel);
|
2005-03-23 04:22:11 +00:00
|
|
|
}
|
2005-03-16 03:20:32 +00:00
|
|
|
|
|
|
|
if (_str.left > _left)
|
|
|
|
_str.left = _left;
|
|
|
|
|
|
|
|
_left += origWidth;
|
|
|
|
|
|
|
|
if (_str.right < _left) {
|
|
|
|
_str.right = _left;
|
2005-06-04 16:10:39 +00:00
|
|
|
if (_shadowMode != kNoShadowMode)
|
2005-03-16 03:20:32 +00:00
|
|
|
_str.right++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_str.bottom < _top + height)
|
|
|
|
_str.bottom = _top + height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CharsetRendererNES::drawChar(int chr, const Graphics::Surface &s, int x, int y) {
|
|
|
|
byte *charPtr, *dst;
|
|
|
|
int width, height;
|
|
|
|
|
2005-04-10 09:58:37 +00:00
|
|
|
if (!_trTable)
|
|
|
|
_trTable = _vm->getResourceAddress(rtCostume, 77) + 2;
|
|
|
|
|
2005-03-24 03:22:32 +00:00
|
|
|
charPtr = _vm->_NESPatTable[1] + _trTable[chr - 32] * 16;
|
2005-03-16 03:20:32 +00:00
|
|
|
width = getCharWidth(chr);
|
|
|
|
height = 8;
|
|
|
|
|
|
|
|
dst = (byte *)s.pixels + y * s.pitch + x;
|
2009-10-26 13:22:05 +00:00
|
|
|
drawBits1(s, dst, charPtr, y, width, height, s.bytesPerPixel);
|
2005-03-16 03:20:32 +00:00
|
|
|
}
|
|
|
|
|
2009-10-26 13:22:05 +00:00
|
|
|
void CharsetRendererNES::drawBits1(const Graphics::Surface &s, byte *dst, const byte *src, int drawTop, int width, int height, uint8 bitDepth) {
|
2005-03-16 03:20:32 +00:00
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
byte c0 = src[i];
|
|
|
|
byte c1 = src[i + 8];
|
|
|
|
for (int j = 0; j < 8; j++)
|
2005-03-24 03:22:32 +00:00
|
|
|
dst[j] = _vm->_NESPalette[0][((c0 >> (7 - j)) & 1) | (((c1 >> (7 - j)) & 1) << 1) |
|
2005-03-21 23:51:48 +00:00
|
|
|
(_color ? 12 : 8)];
|
2005-03-16 03:20:32 +00:00
|
|
|
dst += s.pitch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-09 14:17:06 +00:00
|
|
|
} // End of namespace Scumm
|