diff options
author | Paul Gilbert | 2015-06-10 19:46:14 -0400 |
---|---|---|
committer | Paul Gilbert | 2015-06-10 19:46:14 -0400 |
commit | 1dda0f6c406524e1b998da27743631d2ba227505 (patch) | |
tree | 5f87c83e88b9c4a364008a18d463d9652f11befc /engines/sherlock/fonts.cpp | |
parent | d7544b696c69b43c37b13e663d395f95adb212af (diff) | |
download | scummvm-rg350-1dda0f6c406524e1b998da27743631d2ba227505.tar.gz scummvm-rg350-1dda0f6c406524e1b998da27743631d2ba227505.tar.bz2 scummvm-rg350-1dda0f6c406524e1b998da27743631d2ba227505.zip |
SHERLOCK: Split up font handling into a new Fonts surface base class
This will be needed for Rose Tattoo, which needs to be able to
write text to arbitrary surfaces
Diffstat (limited to 'engines/sherlock/fonts.cpp')
-rw-r--r-- | engines/sherlock/fonts.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/engines/sherlock/fonts.cpp b/engines/sherlock/fonts.cpp new file mode 100644 index 0000000000..3ef2082171 --- /dev/null +++ b/engines/sherlock/fonts.cpp @@ -0,0 +1,110 @@ +/* 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 "common/system.h" +#include "sherlock/fonts.h" +#include "sherlock/resources.h" +#include "sherlock/surface.h" + +namespace Sherlock { + +ImageFile *Fonts::_font; +int Fonts::_fontNumber; +int Fonts::_fontHeight; + +void Fonts::init() { + _font = nullptr; +} + +void Fonts::free() { + delete _font; +} + +void Fonts::setFont(int fontNumber) { + _fontNumber = fontNumber; + Common::String fname = Common::String::format("FONT%d.VGS", fontNumber + 1); + + // Discard any previous font and read in new one + delete _font; + _font = new ImageFile(fname); + + // Iterate through the frames to find the tallest font character + _fontHeight = 0; + for (uint idx = 0; idx < _font->size(); ++idx) + _fontHeight = MAX((uint16)_fontHeight, (*_font)[idx]._frame.h); +} + +void Fonts::writeString(Surface *surface, const Common::String &str, + const Common::Point &pt, int overrideColor) { + Common::Point charPos = pt; + + for (const char *c = str.c_str(); *c; ++c) { + if (*c == ' ') + charPos.x += 5; + else { + assert(Common::isPrint(*c)); + ImageFrame &frame = (*_font)[*c - 33]; + surface->transBlitFrom(frame, charPos, false, overrideColor); + charPos.x += frame._frame.w + 1; + } + } +} + +int Fonts::stringWidth(const Common::String &str) { + int width = 0; + + for (const char *c = str.c_str(); *c; ++c) + width += charWidth(*c); + + return width; +} + +int Fonts::stringHeight(const Common::String &str) { + int height = 0; + + for (const char *c = str.c_str(); *c; ++c) + height = MAX(height, charHeight(*c)); + + return height; +} + +int Fonts::charWidth(unsigned char c) { + if (c == ' ') + return 5; + else if (Common::isPrint(c)) + return (*_font)[c - 33]._frame.w + 1; + else + return 0; +} + +int Fonts::charHeight(unsigned char c) { + int idx = c - 33; + if (c == ' ') + idx = 0; + else if (c == 225) + idx = 136; + + const ImageFrame &img = (*_font)[idx]; + return img._height + img._offset.y + 1; +} + +} // End of namespace Sherlock |