diff options
author | Paul Gilbert | 2018-11-25 11:42:00 -0800 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | fb7dbffd59b797ed00785a2d3762355f9dbb9f7d (patch) | |
tree | 51660ec9b613aeeaca7d34295b81d05f7266f1bd /engines/glk | |
parent | 5cc3d40c2831ef9d0760178b091e668f5b46195f (diff) | |
download | scummvm-rg350-fb7dbffd59b797ed00785a2d3762355f9dbb9f7d.tar.gz scummvm-rg350-fb7dbffd59b797ed00785a2d3762355f9dbb9f7d.tar.bz2 scummvm-rg350-fb7dbffd59b797ed00785a2d3762355f9dbb9f7d.zip |
GLK: Merge Fonts class into Screen class
Diffstat (limited to 'engines/glk')
-rw-r--r-- | engines/glk/conf.cpp | 7 | ||||
-rw-r--r-- | engines/glk/conf.h | 3 | ||||
-rw-r--r-- | engines/glk/fonts.cpp | 170 | ||||
-rw-r--r-- | engines/glk/fonts.h | 118 | ||||
-rw-r--r-- | engines/glk/frotz/screen.cpp (renamed from engines/glk/frotz/bitmap_font.cpp) | 2 | ||||
-rw-r--r-- | engines/glk/frotz/screen.h (renamed from engines/glk/frotz/bitmap_font.h) | 0 | ||||
-rw-r--r-- | engines/glk/module.mk | 3 | ||||
-rw-r--r-- | engines/glk/screen.cpp | 129 | ||||
-rw-r--r-- | engines/glk/screen.h | 76 | ||||
-rw-r--r-- | engines/glk/windows.h | 2 |
10 files changed, 208 insertions, 302 deletions
diff --git a/engines/glk/conf.cpp b/engines/glk/conf.cpp index 4775f26621..ee2fd9bc21 100644 --- a/engines/glk/conf.cpp +++ b/engines/glk/conf.cpp @@ -21,7 +21,6 @@ */ #include "glk/conf.h" -#include "glk/fonts.h" #include "glk/utils.h" #include "glk/windows.h" #include "common/config-manager.h" @@ -197,9 +196,9 @@ Conf::Conf(InterpreterType interpType) { char *font = strtok(buffer, "\r\n\t "); if (tg == 0) - _tStyles[style].font = Fonts::getId(font); + _tStyles[style].font = Screen::getFontId(font); else - _gStyles[style].font = Fonts::getId(font); + _gStyles[style].font = Screen::getFontId(font); } } @@ -231,7 +230,7 @@ void Conf::get(const Common::String &key, bool &field, bool defaultVal) { } void Conf::get(const Common::String &key, FACES &field, FACES defaultFont) { - field = ConfMan.hasKey(key) ? Fonts::getId(ConfMan.get(key)) : defaultFont; + field = ConfMan.hasKey(key) ? Screen::getFontId(ConfMan.get(key)) : defaultFont; } void Conf::get(const Common::String &key, double &field, double defaultVal) { diff --git a/engines/glk/conf.h b/engines/glk/conf.h index bf68e343f9..ca9de2ed08 100644 --- a/engines/glk/conf.h +++ b/engines/glk/conf.h @@ -24,13 +24,10 @@ #define GLK_CONF_H #include "glk/glk_types.h" -#include "glk/fonts.h" #include "glk/windows.h" namespace Glk { - - /** * Engine configuration */ diff --git a/engines/glk/fonts.cpp b/engines/glk/fonts.cpp deleted file mode 100644 index 416496670c..0000000000 --- a/engines/glk/fonts.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/* 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/fonts.h" -#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 { - -#define FONTS_VERSION 1.0 -#define FONTS_FILENAME "fonts.dat" - -Fonts::Fonts(Graphics::ManagedSurface *surface) : _surface(surface), _fontsMissing(false) { - if (!loadFonts()) - error("Could not load data file"); - - // TODO: See if there's any better way for getting the leading and baseline - Common::Rect r1 = _fontTable[7]->getBoundingBox('o'); - Common::Rect r2 = _fontTable[7]->getBoundingBox('y'); - double baseLine = (double)r1.bottom; - double leading = (double)r2.bottom + 2; - - g_conf->_leading = MAX((double)g_conf->_leading, leading); - g_conf->_baseLine = MAX((double)g_conf->_baseLine, baseLine); - g_conf->_cellW = _fontTable[0]->getStringWidth("0"); - g_conf->_cellH = g_conf->_leading; -} - -Fonts::~Fonts() { - for (int idx = 0; idx < FONTS_TOTAL; ++idx) - delete _fontTable[idx]; -} - -bool Fonts::loadFonts() { - Common::Archive *archive = nullptr; - - if (!Common::File::exists(FONTS_FILENAME) || (archive = Common::makeZipArchive(FONTS_FILENAME)) == nullptr) - return false; - - // Open the version.txt file within it to validate the version - Common::File f; - if (!f.open("version.txt", *archive)) { - delete archive; - return false; - } - - // Validate the version - char buffer[4]; - f.read(buffer, 3); - buffer[3] = '\0'; - - if (Common::String(buffer) != "1.0") { - delete archive; - return false; - } - - // R ead in the fonts - double monoAspect = g_conf->_monoAspect; - double propAspect = g_conf->_propAspect; - double monoSize = g_conf->_monoSize; - double propSize = g_conf->_propSize; - - _fontTable[0] = loadFont(MONOR, archive, monoSize, monoAspect, FONTR); - _fontTable[1] = loadFont(MONOB, archive, monoSize, monoAspect, FONTB); - _fontTable[2] = loadFont(MONOI, archive, monoSize, monoAspect, FONTI); - _fontTable[3] = loadFont(MONOZ, archive, monoSize, monoAspect, FONTZ); - - _fontTable[4] = loadFont(PROPR, archive, propSize, propAspect, FONTR); - _fontTable[5] = loadFont(PROPB, archive, propSize, propAspect, FONTB); - _fontTable[6] = loadFont(PROPI, archive, propSize, propAspect, FONTI); - _fontTable[7] = loadFont(PROPZ, archive, propSize, propAspect, FONTZ); - - delete archive; - return true; -} - -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" - }; - - // 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()); - - } 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) { - if (name == "monor") return MONOR; - if (name == "monob") return MONOB; - if (name == "monoi") return MONOI; - if (name == "monoz") return MONOZ; - if (name == "propr") return PROPR; - if (name == "propb") return PROPB; - if (name == "propi") return PROPI; - if (name == "propz") return PROPZ; - return MONOR; -} - -int Fonts::drawString(const Point &pos, int fontIdx, const byte *rgb, const Common::String &text, int spw) { - Point pt(pos.x / GLI_SUBPIX, pos.y - g_conf->_baseLine); - const Graphics::Font *font = _fontTable[fontIdx]; - const uint32 color = _surface->format.RGBToColor(rgb[0], rgb[1], rgb[2]); - font->drawString(_surface, text, pt.x, pt.y, _surface->w - pt.x, color); - - pt.x += font->getStringWidth(text); - return MIN((int)pt.x, (int)_surface->w) * GLI_SUBPIX; -} - -int Fonts::drawStringUni(const Point &pos, int fontIdx, const byte *rgb, const Common::U32String &text, int spw) { - Point pt(pos.x / GLI_SUBPIX, pos.y - g_conf->_baseLine); - const Graphics::Font *font = _fontTable[fontIdx]; - const uint32 color = _surface->format.RGBToColor(rgb[0], rgb[1], rgb[2]); - font->drawString(_surface, text, pt.x, pt.y, _surface->w - pt.x, color); - - pt.x += font->getStringWidth(text); - return MIN((int)pt.x, (int)_surface->w) * GLI_SUBPIX; -} - -size_t Fonts::stringWidth(int fontIdx, const Common::String &text, int spw) { - const Graphics::Font *font = _fontTable[fontIdx]; - return font->getStringWidth(text) * GLI_SUBPIX; -} - -size_t Fonts::stringWidthUni(int fontIdx, const Common::U32String &text, int spw) { - const Graphics::Font *font = _fontTable[fontIdx]; - return font->getStringWidth(text) * GLI_SUBPIX; -} - -} // End of namespace Glk diff --git a/engines/glk/fonts.h b/engines/glk/fonts.h deleted file mode 100644 index 364b0239be..0000000000 --- a/engines/glk/fonts.h +++ /dev/null @@ -1,118 +0,0 @@ -/* 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_FONTS_H -#define GLK_FONTS_H - -#include "glk/glk_types.h" -#include "glk/utils.h" -#include "common/archive.h" -#include "common/array.h" -#include "common/file.h" -#include "common/str.h" -#include "common/ustr.h" -#include "graphics/font.h" - -namespace Glk { - -#define FONTS_TOTAL 8 - -enum FACES { MONOR, MONOB, MONOI, MONOZ, PROPR, PROPB, PROPI, PROPZ }; -enum TYPES { MONOF, PROPF }; -enum STYLES { FONTR, FONTB, FONTI, FONTZ }; - -/** - * Fonts manager - */ -class Fonts { -private: - Graphics::ManagedSurface *_surface; - const Graphics::Font *_fontTable[FONTS_TOTAL]; - bool _fontsMissing; -private: - /** - * Load all the fonts - */ - bool loadFonts(); - - /** - * Load a single font - */ - const Graphics::Font *loadFont(FACES face, Common::Archive *archive, double size, double aspect, int style); -public: - /** - * Get the index/id of a font by name - */ - static FACES getId(const Common::String &name); -public: - /** - * Constructor - */ - Fonts(Graphics::ManagedSurface *surface); - - /** - * Destructor - */ - virtual ~Fonts(); - - /** - * Draws a string using the specified font at the given co-ordinates - * @param pos Position for the bottom-left corner the text will be drawn with - * @param fontIdx Which font to use - * @param rgb RGB tuplet specifying the text color - * @param text The text to draw - * @param spw ?? - */ - int drawString(const Point &pos, int fontIdx, const byte *rgb, const Common::String &text, int spw = 0); - - /** - * Draws a unicode string using the specified font at the given co-ordinates - * @param pos Position for the bottom-left corner the text will be drawn with - * @param fontIdx Which font to use - * @param rgb RGB tuplet specifying the text color - * @param text The text to draw - * @param spw ?? - */ - int drawStringUni(const Point &pos, int fontIdx, const byte *rgb, const Common::U32String &text, int spw = 0); - - /** - * Get the width in pixels of a string - * @param fontIdx Which font to use - * @param text Text to get the width of - * @param spw Delta X - * @returns Width of string multiplied by GLI_SUBPIX - */ - size_t stringWidth(int fontIdx, const Common::String &text, int spw = 0); - - /** - * Get the width in pixels of a unicode string - * @param fontIdx Which font to use - * @param text Text to get the width of - * @param spw Delta X - * @returns Width of string multiplied by GLI_SUBPIX - */ - size_t stringWidthUni(int fontIdx, const Common::U32String &text, int spw = 0); -}; - -} // End of namespace Glk - -#endif diff --git a/engines/glk/frotz/bitmap_font.cpp b/engines/glk/frotz/screen.cpp index 91f44a9c0c..eef6d6118d 100644 --- a/engines/glk/frotz/bitmap_font.cpp +++ b/engines/glk/frotz/screen.cpp @@ -20,7 +20,7 @@ * */ -#include "glk/frotz/bitmap_font.h" +#include "glk/frotz/screen.h" namespace Glk { namespace Frotz { diff --git a/engines/glk/frotz/bitmap_font.h b/engines/glk/frotz/screen.h index dac716c436..dac716c436 100644 --- a/engines/glk/frotz/bitmap_font.h +++ b/engines/glk/frotz/screen.h diff --git a/engines/glk/module.mk b/engines/glk/module.mk index 7c7a85bb91..4112a9f020 100644 --- a/engines/glk/module.mk +++ b/engines/glk/module.mk @@ -5,7 +5,6 @@ MODULE_OBJS := \ conf.o \ detection.o \ events.o \ - fonts.o \ glk.o \ glk_api.o \ picture.o \ @@ -22,7 +21,6 @@ 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 \ @@ -42,6 +40,7 @@ MODULE_OBJS := \ frotz/processor_text.o \ frotz/processor_variables.o \ frotz/quetzal.o \ + frotz/screen.o \ scott/detection.o \ scott/scott.o diff --git a/engines/glk/screen.cpp b/engines/glk/screen.cpp index 1a76ac8382..cfe8cde84f 100644 --- a/engines/glk/screen.cpp +++ b/engines/glk/screen.cpp @@ -22,9 +22,38 @@ #include "glk/screen.h" #include "glk/conf.h" +#include "common/unzip.h" +#include "image/bmp.h" +#include "graphics/fonts/ttf.h" +#include "graphics/fontman.h" namespace Glk { + +#define FONTS_VERSION 1.0 +#define FONTS_FILENAME "fonts.dat" + +Screen::Screen() { + if (!loadFonts()) + error("Could not load data file"); + + // TODO: See if there's any better way for getting the leading and baseline + Common::Rect r1 = _fonts[7]->getBoundingBox('o'); + Common::Rect r2 = _fonts[7]->getBoundingBox('y'); + double baseLine = (double)r1.bottom; + double leading = (double)r2.bottom + 2; + + g_conf->_leading = MAX((double)g_conf->_leading, leading); + g_conf->_baseLine = MAX((double)g_conf->_baseLine, baseLine); + g_conf->_cellW = _fonts[0]->getStringWidth("0"); + g_conf->_cellH = g_conf->_leading; +} + +Screen::~Screen() { + for (int idx = 0; idx < FONTS_TOTAL; ++idx) + delete _fonts[idx]; +} + void Screen::fill(const byte *rgb) { uint color = format.RGBToColor(rgb[0], rgb[1], rgb[2]); clear(color); @@ -69,4 +98,104 @@ void Screen::drawCaret(const Point &pos) { } } +bool Screen::loadFonts() { + Common::Archive *archive = nullptr; + _fonts.resize(FONTS_TOTAL); + + if (!Common::File::exists(FONTS_FILENAME) || (archive = Common::makeZipArchive(FONTS_FILENAME)) == nullptr) + return false; + + // Open the version.txt file within it to validate the version + Common::File f; + if (!f.open("version.txt", *archive)) { + delete archive; + return false; + } + + // Validate the version + char buffer[4]; + f.read(buffer, 3); + buffer[3] = '\0'; + + if (Common::String(buffer) != "1.0") { + delete archive; + return false; + } + + // R ead in the fonts + double monoAspect = g_conf->_monoAspect; + double propAspect = g_conf->_propAspect; + double monoSize = g_conf->_monoSize; + double propSize = g_conf->_propSize; + + _fonts[0] = loadFont(MONOR, archive, monoSize, monoAspect, FONTR); + _fonts[1] = loadFont(MONOB, archive, monoSize, monoAspect, FONTB); + _fonts[2] = loadFont(MONOI, archive, monoSize, monoAspect, FONTI); + _fonts[3] = loadFont(MONOZ, archive, monoSize, monoAspect, FONTZ); + + _fonts[4] = loadFont(PROPR, archive, propSize, propAspect, FONTR); + _fonts[5] = loadFont(PROPB, archive, propSize, propAspect, FONTB); + _fonts[6] = loadFont(PROPI, archive, propSize, propAspect, FONTI); + _fonts[7] = loadFont(PROPZ, archive, propSize, propAspect, FONTZ); + + delete archive; + return true; +} + +const Graphics::Font *Screen::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" + }; + + if (!f.open(FILENAMES[face], *archive)) + error("Could not load font"); + + return Graphics::loadTTFFont(f, size, Graphics::kTTFSizeModeCharacter); +} + +FACES Screen::getFontId(const Common::String &name) { + if (name == "monor") return MONOR; + if (name == "monob") return MONOB; + if (name == "monoi") return MONOI; + if (name == "monoz") return MONOZ; + if (name == "propr") return PROPR; + if (name == "propb") return PROPB; + if (name == "propi") return PROPI; + if (name == "propz") return PROPZ; + return MONOR; +} + +int Screen::drawString(const Point &pos, int fontIdx, const byte *rgb, const Common::String &text, int spw) { + Point pt(pos.x / GLI_SUBPIX, pos.y - g_conf->_baseLine); + const Graphics::Font *font = _fonts[fontIdx]; + const uint32 color = format.RGBToColor(rgb[0], rgb[1], rgb[2]); + font->drawString(this, text, pt.x, pt.y, w - pt.x, color); + + pt.x += font->getStringWidth(text); + return MIN((int)pt.x, (int)w) * GLI_SUBPIX; +} + +int Screen::drawStringUni(const Point &pos, int fontIdx, const byte *rgb, const Common::U32String &text, int spw) { + Point pt(pos.x / GLI_SUBPIX, pos.y - g_conf->_baseLine); + const Graphics::Font *font = _fonts[fontIdx]; + const uint32 color = format.RGBToColor(rgb[0], rgb[1], rgb[2]); + font->drawString(this, text, pt.x, pt.y, w - pt.x, color); + + pt.x += font->getStringWidth(text); + return MIN((int)pt.x, (int)w) * GLI_SUBPIX; +} + +size_t Screen::stringWidth(int fontIdx, const Common::String &text, int spw) { + const Graphics::Font *font = _fonts[fontIdx]; + return font->getStringWidth(text) * GLI_SUBPIX; +} + +size_t Screen::stringWidthUni(int fontIdx, const Common::U32String &text, int spw) { + const Graphics::Font *font = _fonts[fontIdx]; + return font->getStringWidth(text) * GLI_SUBPIX; +} + } // End of namespace Glk diff --git a/engines/glk/screen.h b/engines/glk/screen.h index 0020d86f19..541e9e190e 100644 --- a/engines/glk/screen.h +++ b/engines/glk/screen.h @@ -23,24 +23,56 @@ #ifndef GLK_DRAW_H #define GLK_DRAW_H +#include "common/archive.h" +#include "common/array.h" #include "graphics/screen.h" -#include "glk/fonts.h" +#include "graphics/font.h" +#include "glk/utils.h" namespace Glk { +#define FONTS_TOTAL 8 + enum CaretShape { SMALL_DOT = 0, FAT_DOT = 1, THIN_LINE = 2, FAT_LINE = 3, BLOCK = 4 }; +enum FACES { MONOR, MONOB, MONOI, MONOZ, PROPR, PROPB, PROPI, PROPZ }; +enum TYPES { MONOF, PROPF }; +enum STYLES { FONTR, FONTB, FONTI, FONTZ }; + /** * Screen surface class */ -class Screen : public Graphics::Screen, public Fonts { +class Screen : public Graphics::Screen { +private: + Common::Array<const Graphics::Font *> _fonts; +private: + /** + * Load all the fonts + */ + bool loadFonts(); + + /** + * Load a single font + */ + const Graphics::Font *loadFont(FACES face, Common::Archive *archive, + double size, double aspect, int style); +public: + /** + * Return the font Id for a given name + */ + static FACES getFontId(const Common::String &name); public: /** * Constructor */ - Screen() : Graphics::Screen(), Fonts(this) {} + Screen(); + + /** + * Destructor + */ + virtual ~Screen(); /** * Fills the screen with a given rgb color @@ -58,6 +90,44 @@ public: * and the X position is in multiples of GLI_SUBPIX */ void drawCaret(const Point &pos); + + /** + * Draws a string using the specified font at the given co-ordinates + * @param pos Position for the bottom-left corner the text will be drawn with + * @param fontIdx Which font to use + * @param rgb RGB tuplet specifying the text color + * @param text The text to draw + * @param spw ?? + */ + int drawString(const Point &pos, int fontIdx, const byte *rgb, const Common::String &text, int spw = 0); + + /** + * Draws a unicode string using the specified font at the given co-ordinates + * @param pos Position for the bottom-left corner the text will be drawn with + * @param fontIdx Which font to use + * @param rgb RGB tuplet specifying the text color + * @param text The text to draw + * @param spw ?? + */ + int drawStringUni(const Point &pos, int fontIdx, const byte *rgb, const Common::U32String &text, int spw = 0); + + /** + * Get the width in pixels of a string + * @param fontIdx Which font to use + * @param text Text to get the width of + * @param spw Delta X + * @returns Width of string multiplied by GLI_SUBPIX + */ + size_t stringWidth(int fontIdx, const Common::String &text, int spw = 0); + + /** + * Get the width in pixels of a unicode string + * @param fontIdx Which font to use + * @param text Text to get the width of + * @param spw Delta X + * @returns Width of string multiplied by GLI_SUBPIX + */ + size_t stringWidthUni(int fontIdx, const Common::U32String &text, int spw = 0); }; } // End of namespace Glk diff --git a/engines/glk/windows.h b/engines/glk/windows.h index 7abb9e5ff5..27380fa23e 100644 --- a/engines/glk/windows.h +++ b/engines/glk/windows.h @@ -29,7 +29,7 @@ #include "graphics/screen.h" #include "glk/events.h" #include "glk/glk_types.h" -#include "glk/fonts.h" +#include "glk/screen.h" #include "glk/selection.h" #include "glk/streams.h" |