diff options
author | Robert Špalek | 2009-11-23 06:44:40 +0000 |
---|---|---|
committer | Robert Špalek | 2009-11-23 06:44:40 +0000 |
commit | 95d4c62efbf7b083716d1d2c4a0870eb58dcbc74 (patch) | |
tree | 2ed3647f3114c1e8b73cec859a30e09954e2908b /engines | |
parent | a7e6745ba49cf3fd2b0b2556c828d7d6b3202965 (diff) | |
download | scummvm-rg350-95d4c62efbf7b083716d1d2c4a0870eb58dcbc74.tar.gz scummvm-rg350-95d4c62efbf7b083716d1d2c4a0870eb58dcbc74.tar.bz2 scummvm-rg350-95d4c62efbf7b083716d1d2c4a0870eb58dcbc74.zip |
Fixed breaking long lines instead of using smaller font (which is sometimes not enough)
svn-id: r46101
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; |