Fixed breaking long lines instead of using smaller font (which is sometimes not enough)

svn-id: r46101
This commit is contained in:
Robert Špalek 2009-11-23 06:44:40 +00:00
parent a7e6745ba4
commit 95d4c62efb
3 changed files with 44 additions and 7 deletions

View File

@ -715,13 +715,7 @@ void Script::talk(const Common::Array<int> &params) {
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;

View File

@ -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

View File

@ -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;