aboutsummaryrefslogtreecommitdiff
path: root/engines/glk/screen.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2018-11-25 11:42:00 -0800
committerPaul Gilbert2018-12-08 19:05:59 -0800
commitfb7dbffd59b797ed00785a2d3762355f9dbb9f7d (patch)
tree51660ec9b613aeeaca7d34295b81d05f7266f1bd /engines/glk/screen.cpp
parent5cc3d40c2831ef9d0760178b091e668f5b46195f (diff)
downloadscummvm-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/screen.cpp')
-rw-r--r--engines/glk/screen.cpp129
1 files changed, 129 insertions, 0 deletions
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