diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/draci/script.cpp | 8 | ||||
-rw-r--r-- | engines/draci/sprite.cpp | 39 | ||||
-rw-r--r-- | engines/draci/sprite.h | 4 |
3 files changed, 44 insertions, 7 deletions
diff --git a/engines/draci/script.cpp b/engines/draci/script.cpp index 6adef11778..4c89cfba7d 100644 --- a/engines/draci/script.cpp +++ b/engines/draci/script.cpp @@ -715,13 +715,7 @@ void Script::talk(const Common::Array<int> ¶ms) { speechFrame->setText(""); } speechFrame->setColour(person->_fontColour); - - // HACK: Some strings in the English data files are too long to fit the screen - // This is a temporary resolution. - speechFrame->setFont(_vm->_bigFont); - if (speechFrame->getWidth() >= kScreenWidth) { - speechFrame->setFont(_vm->_smallFont); - } + speechFrame->repeatedlySplitLongLines(kScreenWidth); // Speak the dubbing if possible uint dubbingDuration = 0; diff --git a/engines/draci/sprite.cpp b/engines/draci/sprite.cpp index 5acf0a347a..a41c77dadd 100644 --- a/engines/draci/sprite.cpp +++ b/engines/draci/sprite.cpp @@ -313,5 +313,44 @@ void Text::setFont(const Font *font) { _height = _font->getStringHeight(_text); } +void Text::repeatedlySplitLongLines(uint maxWidth) { + while (_width > maxWidth) { + splitLinesLongerThan(maxWidth); + _width = _font->getStringWidth(_text, _spacing); + _height = _font->getStringHeight(_text); + } +} + +void Text::splitLinesLongerThan(uint maxWidth) { + char *start = const_cast<char*> (_text.c_str()); // hacky + while (1) { + char *end = strchr(start, '|'); + if (end) { + *end = 0; + } + uint lineWidth = _font->getStringWidth(start, _spacing); + if (lineWidth > maxWidth) { + int middle = end ? (end - start) / 2 : strlen(start) / 2; + for (int i = 0; ; ++i) { + if (start[middle + i] == ' ') { + start[middle + i] = '|'; + break; + } + if (start[middle - i] == ' ') { + start[middle - i] = '|'; + break; + } + } + debugC(2, kDraciGeneralDebugLevel, "Long line of width %d split into %s\n", lineWidth, start); + } + if (end) { + *end = '|'; + start = end + 1; + } else { + break; + } + } +} + } // End of namespace Draci diff --git a/engines/draci/sprite.h b/engines/draci/sprite.h index ef9f570e06..cc50ada477 100644 --- a/engines/draci/sprite.h +++ b/engines/draci/sprite.h @@ -144,6 +144,8 @@ public: void setSpacing(uint spacing) { _spacing = spacing; } void setFont(const Font *font); + void repeatedlySplitLongLines(uint maxWidth); + uint getLength() const { return _length; } void draw(Surface *surface, bool markDirty, int relX, int relY) const; @@ -155,6 +157,8 @@ public: DrawableType getType() const { return kDrawableText; } private: + void splitLinesLongerThan(uint maxWidth); + Common::String _text; uint _length; uint8 _colour; |