diff options
-rw-r--r-- | scumm/nut_renderer.cpp | 43 | ||||
-rw-r--r-- | scumm/nut_renderer.h | 7 | ||||
-rw-r--r-- | scumm/smush/smush_font.cpp | 145 | ||||
-rw-r--r-- | scumm/smush/smush_font.h | 14 |
4 files changed, 33 insertions, 176 deletions
diff --git a/scumm/nut_renderer.cpp b/scumm/nut_renderer.cpp index 50367b57aa..d25ba15d07 100644 --- a/scumm/nut_renderer.cpp +++ b/scumm/nut_renderer.cpp @@ -23,11 +23,11 @@ #include "nut_renderer.h" -NutRenderer::NutRenderer(Scumm *vm) { - _vm = vm; - _initialized = false; - _loaded = false; - _nbChars = 0; +NutRenderer::NutRenderer(Scumm *vm) : + _vm(vm), + _initialized(false), + _loaded(false), + _nbChars(0) { for(int i = 0; i < 256; i++) _chars[i].src = NULL; @@ -134,10 +134,10 @@ int NutRenderer::getCharWidth(byte c) { return 0; } - if(c >= 0x80 && g_scumm->_CJKMode) { - if(g_scumm->_gameId == GID_CMI) + if(c >= 0x80 && _vm->_CJKMode) { + if(_vm->_gameId == GID_CMI) return 8; - if(g_scumm->_gameId == GID_DIG) + if(_vm->_gameId == GID_DIG) return 6; return 0; } @@ -155,10 +155,10 @@ int NutRenderer::getCharHeight(byte c) { return 0; } - if(c >= 0x80 && g_scumm->_CJKMode) { - if(g_scumm->_gameId == GID_CMI) + if(c >= 0x80 && _vm->_CJKMode) { + if(_vm->_gameId == GID_CMI) return 16; - if(g_scumm->_gameId == GID_DIG) + if(_vm->_gameId == GID_DIG) return 10; return 0; } @@ -169,21 +169,6 @@ int NutRenderer::getCharHeight(byte c) { return _chars[c].height; } -int NutRenderer::getStringWidth(const byte *str) { - debug(8, "NutRenderer::getStringWidth() called"); - if (!_loaded) { - warning("NutRenderer::getStringWidth() Font is not loaded"); - return 0; - } - int width = 0; - - while (*str) { - width += getCharWidth(*str++); - } - - return width; -} - void NutRenderer::drawShadowChar(int c, int x, int y, byte color, bool useMask) { debug(8, "NutRenderer::drawChar('%c', %d, %d, %d, %d) called", c, x, y, (int)color, useMask); if (!_loaded) { @@ -263,9 +248,9 @@ void NutRenderer::draw2byte(byte *dst, byte *mask, int c, int x, int y, byte col return; } - int width = g_scumm->_2byteWidth; - int height = g_scumm->_2byteHeight; - byte *src = g_scumm->get2byteCharPtr(c); + int width = _vm->_2byteWidth; + int height = _vm->_2byteHeight; + byte *src = _vm->get2byteCharPtr(c); byte bits = 0; byte maskmask; diff --git a/scumm/nut_renderer.h b/scumm/nut_renderer.h index aead436bb6..d68fb93894 100644 --- a/scumm/nut_renderer.h +++ b/scumm/nut_renderer.h @@ -39,12 +39,12 @@ protected: void decodeCodec44(byte *dst, const byte *src, uint32 length); - void draw2byte(byte *dst, byte *mask, int c, int x, int y, byte color); - void drawChar(byte *dst, byte *mask, byte c, int x, int y, byte color); + virtual void draw2byte(byte *dst, byte *mask, int c, int x, int y, byte color); + virtual void drawChar(byte *dst, byte *mask, byte c, int x, int y, byte color); public: NutRenderer(Scumm *vm); - ~NutRenderer(); + virtual ~NutRenderer(); bool loadFont(const char *filename, const char *dir); @@ -52,7 +52,6 @@ public: int getCharWidth(byte c); int getCharHeight(byte c); - int getStringWidth(const byte *string); }; diff --git a/scumm/smush/smush_font.cpp b/scumm/smush/smush_font.cpp index ac2222587d..3c7887e3ba 100644 --- a/scumm/smush/smush_font.cpp +++ b/scumm/smush/smush_font.cpp @@ -20,161 +20,44 @@ */ #include "stdafx.h" -#include "common/util.h" -#include "common/engine.h" #include "common/file.h" #include "scumm/scumm.h" #include "smush_font.h" SmushFont::SmushFont(bool use_original_colors, bool new_colors) : - _nbChars(0), + NutRenderer(g_scumm), // FIXME: evil hack _color(-1), _new_colors(new_colors), _original(use_original_colors) { - for(int i = 0; i < 256; i++) - _chars[i].src = NULL; } -SmushFont::~SmushFont() { - for(int i = 0; i < _nbChars; i++) { - if(_chars[i].src) - delete []_chars[i].src; - } -} - -bool SmushFont::loadFont(const char *filename, const char *directory) { - debug(8, "SmushFont::loadFont() called"); - - File file; - file.open(filename, directory); - if (file.isOpen() == false) { - warning("SmushFont::loadFont() Can't open font file: %s/%s", directory, filename); - return false; - } - - uint32 tag = file.readUint32BE(); - if (tag != 'ANIM') { - debug(8, "SmushFont::loadFont() there is no ANIM chunk in font header"); - return false; - } - - uint32 length = file.readUint32BE(); - byte *dataSrc = (byte *)malloc(length); - file.read(dataSrc, length); - file.close(); - - if (READ_BE_UINT32(dataSrc) != 'AHDR') { - debug(8, "SmushFont::loadFont() there is no AHDR chunk in font header"); - free(dataSrc); - return false; - } - - _nbChars = READ_LE_UINT16(dataSrc + 10); - uint32 offset = READ_BE_UINT32(dataSrc + 4) + 8; - for (int l = 0; l < _nbChars; l++) { - if (READ_BE_UINT32(dataSrc + offset) == 'FRME') { - offset += 8; - if (READ_BE_UINT32(dataSrc + offset) == 'FOBJ') { - _chars[l].width = READ_LE_UINT16(dataSrc + offset + 14); - _chars[l].height = READ_LE_UINT16(dataSrc + offset + 16); - _chars[l].src = new byte[_chars[l].width * _chars[l].height + 1000]; - decodeCodec44(_chars[l].src, dataSrc + offset + 22, READ_BE_UINT32(dataSrc + offset + 4) - 14); - offset += READ_BE_UINT32(dataSrc + offset + 4) + 8; - } else { - debug(8, "SmushFont::loadFont(%s, %s) there is no FOBJ chunk in FRME chunk %d (offset %x)", filename, directory, l, offset); - break; - } - } else { - debug(8, "SmushFont::loadFont(%s, %s) there is no FRME chunk %d (offset %x)", filename, directory, l, offset); - break; - } - } - - free(dataSrc); - return true; -} - -int SmushFont::getCharWidth(byte c) { - if(c >= 0x80 && g_scumm->_CJKMode) { - if(g_scumm->_gameId == GID_CMI) - return 8; - if(g_scumm->_gameId == GID_DIG) - return 6; - return 0; - } - - if(c >= _nbChars) - error("invalid character in SmushFont::charWidth : %d (%d)", c, _nbChars); - - return _chars[c].width; -} - -int SmushFont::getCharHeight(byte c) { - if(c >= 0x80 && g_scumm->_CJKMode) { - if(g_scumm->_gameId == GID_CMI) - return 16; - if(g_scumm->_gameId == GID_DIG) - return 10; +int SmushFont::getStringWidth(const char *str) { + if (!_loaded) { + warning("SmushFont::getStringWidth() Font is not loaded"); return 0; } - if(c >= _nbChars) - error("invalid character in SmushFont::charHeight : %d (%d)", c, _nbChars); - - return _chars[c].height; -} - -int SmushFont::getStringWidth(const char *str) { int width = 0; - while(*str) { width += getCharWidth(*str++); } - return width; } int SmushFont::getStringHeight(const char *str) { - int ret = 0; - - for(int i = 0; str[i] != 0; i++) { - int h = getCharHeight(str[i]); - ret = MAX(ret, h); + if (!_loaded) { + warning("SmushFont::getStringHeight() Font is not loaded"); + return 0; } - return ret; -} - -void SmushFont::decodeCodec44(byte *dst, const byte *src, int length) { - byte val; - uint16 size_line, num; - - do { - size_line = READ_LE_UINT16(src); - src += 2; - length -= 2; - - while (size_line != 0) { - num = *src++; - val = *src++; - memset(dst, val, num); - dst += num; - length -= 2; - size_line -= 2; - if (size_line != 0) { - num = READ_LE_UINT16(src) + 1; - src += 2; - memcpy(dst, src, num); - dst += num; - src += num; - length -= num + 2; - size_line -= num + 2; - } - } - dst--; - - } while (length > 1); + int height = 0; + while(*str) { + int charHeight = getCharHeight(*str++); + if (height < charHeight) + height = charHeight; + } + return height; } int SmushFont::drawChar(byte *buffer, int dst_width, int x, int y, byte chr) { diff --git a/scumm/smush/smush_font.h b/scumm/smush/smush_font.h index c410b0405e..540df96662 100644 --- a/scumm/smush/smush_font.h +++ b/scumm/smush/smush_font.h @@ -23,35 +23,25 @@ #define SMUSH_FONT_H #include "common/scummsys.h" +#include "scumm/nut_renderer.h" -class SmushFont { +class SmushFont : public NutRenderer { protected: int _nbChars; int16 _color; bool _new_colors; bool _original; - struct { - int width; - int height; - byte *src; - } _chars[256]; - - int getCharWidth(byte c); int getStringWidth(const char *str); - int getCharHeight(byte c); int getStringHeight(const char *str); int draw2byte(byte *buffer, int dst_width, int x, int y, int idx); int drawChar(byte *buffer, int dst_width, int x, int y, byte chr); void drawSubstring(const char *str, byte *buffer, int dst_width, int x, int y); - void decodeCodec44(byte *dst, const byte *src, int length); public: SmushFont(bool use_original_colors, bool new_colors); - ~SmushFont(); - bool loadFont(const char *filename, const char *directory); void setColor(byte c) { _color = c; } void drawStringCentered(const char *str, byte *buffer, int dst_width, int dst_height, int y, int xmin, int width, int offset); void drawStringWrap(const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, int width); |