[Scummvm-cvs-logs] scummvm master -> 41b74a89d2800bd956ae830a77207681e6e9da8b
m-kiewitz
m_kiewitz at users.sourceforge.net
Sun Jun 14 01:09:27 CEST 2015
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
41b74a89d2 SHERLOCK: font class adjustment for int. versions
Commit: 41b74a89d2800bd956ae830a77207681e6e9da8b
https://github.com/scummvm/scummvm/commit/41b74a89d2800bd956ae830a77207681e6e9da8b
Author: Martin Kiewitz (m_kiewitz at users.sourceforge.net)
Date: 2015-06-14T01:05:36+02:00
Commit Message:
SHERLOCK: font class adjustment for int. versions
- allow characters > 0x80
- adjust characters >= 0x80 (Spanish + German didn't do exactly
the same)
- behavior inside SH2 unconfirmed
- makes text in SH1 German+Spanish work
Changed paths:
engines/sherlock/fonts.cpp
engines/sherlock/fonts.h
diff --git a/engines/sherlock/fonts.cpp b/engines/sherlock/fonts.cpp
index c6657cd..c0a6d45 100644
--- a/engines/sherlock/fonts.cpp
+++ b/engines/sherlock/fonts.cpp
@@ -32,10 +32,12 @@ Common::Platform Fonts::_platform;
ImageFile *Fonts::_font;
int Fonts::_fontNumber;
int Fonts::_fontHeight;
+uint16 Fonts::_charCount;
void Fonts::init(Common::Platform platform) {
_font = nullptr;
_platform = platform;
+ _charCount = 0;
}
void Fonts::free() {
@@ -73,13 +75,34 @@ void Fonts::setFont(int fontNum) {
// load font data
_font = new ImageFile3DO(fontFilename, kImageFile3DOType_Font);
}
+
+ _charCount = _font->size();
// Iterate through the frames to find the tallest font character
_fontHeight = 0;
- for (uint idx = 0; idx < _font->size(); ++idx)
+ for (uint idx = 0; idx < _charCount; ++idx)
_fontHeight = MAX((uint16)_fontHeight, (*_font)[idx]._frame.h);
}
+inline byte Fonts::translateChar(byte c) {
+ switch (c) {
+ case ' ':
+ return 0; // translate to first actual character
+ case 225:
+ return 136; // special handling for 0xE1
+ default:
+ if (c >= 0x80) { // German SH1 version did this
+ c--;
+ }
+ // Spanish SH1 did this (reverse engineered code)
+ //if ((c >= 0xA0) && (c <= 0xAD) || (c == 0x82)) {
+ // c--;
+ //}
+ assert(c > 32); // anything above space is allowed
+ return c - 33;
+ }
+}
+
void Fonts::writeString(Surface *surface, const Common::String &str,
const Common::Point &pt, int overrideColor) {
Common::Point charPos = pt;
@@ -87,15 +110,19 @@ void Fonts::writeString(Surface *surface, const Common::String &str,
if (!_font)
return;
- 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;
+ for (const char *curCharPtr = str.c_str(); *curCharPtr; ++curCharPtr) {
+ byte curChar = *curCharPtr;
+
+ if (curChar == ' ') {
+ charPos.x += 5; // hardcoded space
+ continue;
}
+ curChar = translateChar(curChar);
+
+ assert(curChar < _charCount);
+ ImageFrame &frame = (*_font)[curChar];
+ surface->transBlitFrom(frame, charPos, false, overrideColor);
+ charPos.x += frame._frame.w + 1;
}
}
@@ -124,29 +151,32 @@ int Fonts::stringHeight(const Common::String &str) {
}
int Fonts::charWidth(unsigned char c) {
+ byte curChar;
+
if (!_font)
return 0;
- if (c == ' ')
- return 5;
- else if (Common::isPrint(c))
- return (*_font)[c - 33]._frame.w + 1;
- else
- return 0;
+ if (c == ' ') {
+ return 5; // hardcoded space
+ }
+ curChar = translateChar(c);
+
+ if (curChar < _charCount)
+ return (*_font)[curChar]._frame.w + 1;
+ return 0;
}
int Fonts::charHeight(unsigned char c) {
- int idx = c - 33;
+ byte curChar;
if (!_font)
return 0;
- if (c == ' ')
- idx = 0;
- else if (c == 225)
- idx = 136;
+ // Space is supposed to be handled like the first actual character (which is decimal 33)
+ curChar = translateChar(c);
- const ImageFrame &img = (*_font)[idx];
+ assert(curChar < _charCount);
+ const ImageFrame &img = (*_font)[curChar];
return img._height + img._offset.y + 1;
}
diff --git a/engines/sherlock/fonts.h b/engines/sherlock/fonts.h
index 0df427f..1e47007 100644
--- a/engines/sherlock/fonts.h
+++ b/engines/sherlock/fonts.h
@@ -39,9 +39,12 @@ private:
protected:
static int _fontNumber;
static int _fontHeight;
+ static uint16 _charCount;
static void writeString(Surface *surface, const Common::String &str,
const Common::Point &pt, int overrideColor = 0);
+
+ static inline byte translateChar(byte c);
public:
/**
* Initialise the font manager
More information about the Scummvm-git-logs
mailing list