diff options
author | Paul Gilbert | 2018-11-24 21:28:52 -0800 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | 5cc3d40c2831ef9d0760178b091e668f5b46195f (patch) | |
tree | 094044f05c5951a3fb85b16e2d6ca5bd00c8c7d4 /engines/glk | |
parent | c2625264fb4e0a0abde96257ea86c83dde60fad2 (diff) | |
download | scummvm-rg350-5cc3d40c2831ef9d0760178b091e668f5b46195f.tar.gz scummvm-rg350-5cc3d40c2831ef9d0760178b091e668f5b46195f.tar.bz2 scummvm-rg350-5cc3d40c2831ef9d0760178b091e668f5b46195f.zip |
GLK: FROTZ: Adding bitmap font class for Infocom character graphics
Diffstat (limited to 'engines/glk')
-rw-r--r-- | engines/glk/fonts.cpp | 21 | ||||
-rw-r--r-- | engines/glk/frotz/bitmap_font.cpp | 60 | ||||
-rw-r--r-- | engines/glk/frotz/bitmap_font.h | 81 | ||||
-rw-r--r-- | engines/glk/frotz/frotz_types.h | 1 | ||||
-rw-r--r-- | engines/glk/frotz/processor_screen.cpp | 59 | ||||
-rw-r--r-- | engines/glk/module.mk | 1 | ||||
-rw-r--r-- | engines/glk/picture.cpp | 2 |
7 files changed, 186 insertions, 39 deletions
diff --git a/engines/glk/fonts.cpp b/engines/glk/fonts.cpp index bc699aff6e..416496670c 100644 --- a/engines/glk/fonts.cpp +++ b/engines/glk/fonts.cpp @@ -24,10 +24,12 @@ #include "glk/glk_types.h" #include "glk/conf.h" #include "glk/glk.h" +#include "glk/frotz/bitmap_font.h" #include "common/memstream.h" #include "common/unzip.h" #include "graphics/fonts/ttf.h" #include "graphics/fontman.h" +#include "image/bmp.h" namespace Glk { @@ -100,16 +102,27 @@ bool Fonts::loadFonts() { const Graphics::Font *Fonts::loadFont(FACES face, Common::Archive *archive, double size, double aspect, int style) { + Common::File f; const char *const FILENAMES[8] = { "GoMono-Regular.ttf", "GoMono-Bold.ttf", "GoMono-Italic.ttf", "GoMono-Bold-Italic.ttf", "NotoSerif-Regular.ttf", "NotoSerif-Bold.ttf", "NotoSerif-Italic.ttf", "NotoSerif-Bold-Italic.ttf" }; - Common::File f; - if (!f.open(FILENAMES[face], *archive)) - error("Could not load font"); + // TODO: Properly create a derived Fonts manager for the Frotz sub-engine + if (face == MONOZ && g_vm->getInterpreterType() == INTERPRETER_FROTZ) { + if (!f.open("infocom_graphics.bmp", *archive)) + error("Could not load font"); + + Image::BitmapDecoder decoder; + decoder.loadStream(f); + return new Frotz::BitmapFont(*decoder.getSurface()); - return Graphics::loadTTFFont(f, size, Graphics::kTTFSizeModeCharacter); + } else { + if (!f.open(FILENAMES[face], *archive)) + error("Could not load font"); + + return Graphics::loadTTFFont(f, size, Graphics::kTTFSizeModeCharacter); + } } FACES Fonts::getId(const Common::String &name) { diff --git a/engines/glk/frotz/bitmap_font.cpp b/engines/glk/frotz/bitmap_font.cpp new file mode 100644 index 0000000000..91f44a9c0c --- /dev/null +++ b/engines/glk/frotz/bitmap_font.cpp @@ -0,0 +1,60 @@ +/* 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. + * + */ + +#include "glk/frotz/bitmap_font.h" + +namespace Glk { +namespace Frotz { + +BitmapFont::BitmapFont(const Graphics::Surface &src, uint charWidth, + uint charHeight, unsigned char startingChar) : _startingChar(startingChar) { + assert(src.format.bytesPerPixel == 1); + assert((src.w % charWidth) == 0); + assert((src.h % charHeight) == 0); + _surface.copyFrom(src); + + Common::Rect r(charWidth, charHeight); + for (uint y = 0; y < src.h; y += charHeight) { + r.moveTo(0, y); + for (uint x = 0; x < src.w; x += charWidth, r.translate(charWidth, 0)) + _chars.push_back(r); + } +} + +BitmapFont::~BitmapFont() { + _surface.free(); +} + +void BitmapFont::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const { + const Common::Rect &r = _chars[chr - _startingChar]; + for (int yCtr = 0; yCtr < r.height(); ++yCtr) { + const byte *srcP = (const byte *)_surface.getBasePtr(r.left, r.top + yCtr); + + for (int xCtr = 0; xCtr < r.width(); ++xCtr, ++srcP) { + if (*srcP) + dst->hLine(x + xCtr, y + yCtr, x + xCtr, color); + } + } +} + +} // End of namespace Scott +} // End of namespace Glk diff --git a/engines/glk/frotz/bitmap_font.h b/engines/glk/frotz/bitmap_font.h new file mode 100644 index 0000000000..dac716c436 --- /dev/null +++ b/engines/glk/frotz/bitmap_font.h @@ -0,0 +1,81 @@ +/* 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 GLK_FROTZ_FONTS +#define GLK_FROTZ_FONTS + +#include "graphics/font.h" +#include "graphics/surface.h" +#include "common/archive.h" +#include "common/array.h" +#include "common/rect.h" + +namespace Glk { +namespace Frotz { + +/** + * Implements a fixed width font stored as a grid on a passed surface + */ +class BitmapFont : public Graphics::Font { +private: + Graphics::Surface _surface; + Common::Array<Common::Rect> _chars; + size_t _startingChar; +public: + /** + * Constructor + */ + BitmapFont(const Graphics::Surface &src, uint charWidth = 8, uint charHeight = 8, + unsigned char startingChar = ' '); + + /** + * Destructor + */ + ~BitmapFont(); + + /** + * Get the font height + */ + virtual int getFontHeight() const override { return _chars[0].height(); } + + /** + * Get the maximum character width + */ + virtual int getMaxCharWidth() const override { return _chars[0].width(); } + + /** + * Get the width of the given character + */ + virtual int getCharWidth(uint32 chr) const override { + return _chars[chr - _startingChar].width(); + } + + /** + * Draw a character + */ + virtual void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override; +}; + +} // End of namespace Frotz +} // End of namespace Glk + +#endif diff --git a/engines/glk/frotz/frotz_types.h b/engines/glk/frotz/frotz_types.h index bf3067fd04..555a204571 100644 --- a/engines/glk/frotz/frotz_types.h +++ b/engines/glk/frotz/frotz_types.h @@ -183,6 +183,7 @@ enum Style { }; enum FontStyle { + PREVIOUS_FONT = 0, TEXT_FONT = 1, PICTURE_FONT = 2, GRAPHICS_FONT = 3, diff --git a/engines/glk/frotz/processor_screen.cpp b/engines/glk/frotz/processor_screen.cpp index 6ee7f1d071..696ce7822a 100644 --- a/engines/glk/frotz/processor_screen.cpp +++ b/engines/glk/frotz/processor_screen.cpp @@ -302,39 +302,30 @@ void Processor::z_set_font() { zword font = zargs[0]; switch (font) { - case 0: - // previous font - temp_font = curr_font; - curr_font = prev_font; - prev_font = temp_font; - zargs[0] = 0xf000; // tickle tickle! - z_set_text_style(); - store (curr_font); - break; - - case 1: - // normal font - prev_font = curr_font; - curr_font = 1; - zargs[0] = 0xf000; // tickle tickle! - z_set_text_style(); - store (prev_font); - break; - - case 4: - // fixed-pitch font - prev_font = curr_font; - curr_font = 4; - zargs[0] = 0xf000; // tickle tickle! - z_set_text_style(); - store (prev_font); - break; - - case 2: // picture font, undefined per 1.1 - case 3: // character graphics font - default: // unavailable - store (0); - break; + case PREVIOUS_FONT: + // previous font + temp_font = curr_font; + curr_font = prev_font; + prev_font = temp_font; + zargs[0] = 0xf000; // tickle tickle! + z_set_text_style(); + store(curr_font); + break; + + case TEXT_FONT: + case GRAPHICS_FONT: + case FIXED_WIDTH_FONT: + prev_font = curr_font; + curr_font = font; + zargs[0] = 0xf000; // tickle tickle! + z_set_text_style(); + store(prev_font); + break; + + case PICTURE_FONT: // picture font, undefined per 1.1 + default: // unavailable + store(0); + break; } } @@ -361,7 +352,7 @@ void Processor::z_set_text_style() { // not tickle time curstyle |= zargs[0]; - if (h_flags & FIXED_FONT_FLAG || curr_font == 4) + if (h_flags & FIXED_FONT_FLAG || curr_font == FIXED_WIDTH_FONT) style = curstyle | FIXED_WIDTH_STYLE; else style = curstyle; diff --git a/engines/glk/module.mk b/engines/glk/module.mk index 0206643f9b..7c7a85bb91 100644 --- a/engines/glk/module.mk +++ b/engines/glk/module.mk @@ -22,6 +22,7 @@ MODULE_OBJS := \ window_pair.o \ window_text_buffer.o \ window_text_grid.o \ + frotz/bitmap_font.o \ frotz/config.o \ frotz/detection.o \ frotz/frotz.o \ diff --git a/engines/glk/picture.cpp b/engines/glk/picture.cpp index 34043152a5..4422e46710 100644 --- a/engines/glk/picture.cpp +++ b/engines/glk/picture.cpp @@ -106,7 +106,7 @@ Picture *Pictures::load(uint32 id) { RawDecoder raw; const Graphics::Surface *img; const byte *palette = nullptr; - int palCount = 0; + uint palCount = 0; Picture *pic; // Check if the picture is already in the store |