void FontRenderer::computeSize(Common::String origText, int32 *retX, int32 *retY) { debugC(4, kDebugFont, "computeSize(%s, retX, retY)", origText.c_str()); int32 lineWidth = 0; int32 lineHeight = 0; int32 totalHeight = 0; int32 totalWidth = 0; const byte *text = (const byte *)origText.c_str(); while (*text) { byte curChar = *text; if (curChar < 32) { text++; continue; } else if (curChar == 13) { totalWidth = MAX(totalWidth, lineWidth); totalHeight += lineHeight; lineHeight = 0; lineWidth = 0; } else { curChar = textToFont(curChar); int32 charWidth = _currentFont->getFrameWidth(curChar) - 1; int32 charHeight = _currentFont->getFrameHeight(curChar); lineWidth += charWidth; lineHeight = MAX(lineHeight, charHeight); } text++; } totalHeight += lineHeight; totalWidth = MAX(totalWidth, lineWidth); *retX = totalWidth; *retY = totalHeight; }
void FontRenderer::computeSize(const Common::String &origText, int16 *retX, int16 *retY) { debugC(4, kDebugFont, "computeSize(%s, retX, retY)", origText.c_str()); int16 lineWidth = 0; int16 lineHeight = 0; int16 totalHeight = 0; int16 totalWidth = 0; int16 lastLineHeight = 0; const byte *text = (const byte *)origText.c_str(); while (*text) { byte curChar = *text; if (curChar == 13) { totalWidth = MAX(totalWidth, lineWidth); totalHeight += lineHeight; lineHeight = 0; lineWidth = 0; lastLineHeight = 0; } else if (curChar < 32) { text++; continue; } else { curChar = textToFont(curChar); int16 charWidth = _currentFont->getFrameWidth(curChar) - 1; int16 charHeight = _currentFont->getFrameHeight(curChar); lineWidth += charWidth; lineHeight = MAX(lineHeight, charHeight); // The character may be offset, so the height doesn't // really tell how far it will stick out. For now, // assume we only need to take the lower bound into // consideration. Common::Rect charRect = _currentFont->getFrameRect(curChar); lastLineHeight = MAX(lastLineHeight, charRect.bottom); } text++; } totalHeight += lastLineHeight; totalWidth = MAX(totalWidth, lineWidth); *retX = totalWidth; *retY = totalHeight; }
void FontRenderer::renderText(int16 x, int16 y, const Common::String &origText, int32 mode) { debugC(5, kDebugFont, "renderText(%d, %d, %s, %d)", x, y, origText.c_str(), mode); int16 xx, yy; computeSize(origText, &xx, &yy); if (mode & 2) { y -= yy / 2; } else if (mode & 4) { y -= yy; } if (mode & 1) { x -= xx / 2; } _vm->addDirtyRect(x, y, x + xx, y + yy); int16 curX = x; int16 curY = y; int32 height = 0; const byte *text = (const byte *)origText.c_str(); while (*text) { byte curChar = *text; if (curChar == 13) { curY = curY + height; height = 0; curX = x; } else { curChar = textToFont(curChar); _currentFont->drawFontFrame(_vm->getMainSurface(), curChar, curX, curY, _currentFontColor); curX = curX + _currentFont->getFrameWidth(curChar) - 1; height = MAX<int32>(height, _currentFont->getFrameHeight(curChar)); } text++; } }
void FontRenderer::renderMultiLineText(int16 x, int16 y, const Common::String &origText, int32 mode) { debugC(5, kDebugFont, "renderMultiLineText(%d, %d, %s, %d)", x, y, origText.c_str(), mode); // divide the text in several lines // based on number of characters or size of lines. byte text[1024]; Common::strlcpy((char *)text, origText.c_str(), 1024); byte *lines[16]; int32 lineSize[16]; int32 numLines = 0; byte *it = text; int16 maxWidth = 0; int16 curWidth = 0; while (true) { byte *lastLine = it; byte *lastSpace = it; int32 lastSpaceX = 0; int32 curLetterNr = 0; curWidth = 0; while (*it && curLetterNr < 50 && curWidth < 580) { byte curChar = *it; if (curChar == 32) { lastSpace = it; lastSpaceX = curWidth; } else curChar = textToFont(curChar); int width = _currentFont->getFrameWidth(curChar); curWidth += MAX(width - 2, 0); it++; curLetterNr++; } if (*lastLine == 0) break; lines[numLines] = lastLine; if (*it == 0) lineSize[numLines] = curWidth; else lineSize[numLines] = lastSpaceX; if (lineSize[numLines] > maxWidth) maxWidth = lineSize[numLines]; lastLine = lastSpace + 1; numLines++; if (*it == 0) break; it = lastLine; *lastSpace = 0; if (numLines >= 16) break; } if (curWidth > maxWidth) { maxWidth = curWidth; } //numLines++; // get font height (assumed to be constant) int16 height = _currentFont->getHeight(); int32 textSize = (height - 2) * numLines; y = y - textSize; if (y < 30) y = 30; if (y + textSize > 370) y = 370 - textSize; x -= _vm->state()->_currentScrollValue; // adapt x if (x - 30 - maxWidth / 2 < 0) x = maxWidth / 2 + 30; if (x + 30 + (maxWidth / 2) > TOON_SCREEN_WIDTH) x = TOON_SCREEN_WIDTH - (maxWidth / 2) - 30; // we have good coordinates now, we can render the multi line int16 curX = x; int16 curY = y; for (int32 i = 0; i < numLines; i++) { const byte *line = lines[i]; curX = x - lineSize[i] / 2; _vm->addDirtyRect(curX + _vm->state()->_currentScrollValue, curY, curX + lineSize[i] + _vm->state()->_currentScrollValue + 2, curY + height); while (*line) { byte curChar = textToFont(*line); if (curChar != 32) _currentFont->drawFontFrame(_vm->getMainSurface(), curChar, curX + _vm->state()->_currentScrollValue, curY, _currentFontColor); curX = curX + MAX<int32>(_currentFont->getFrameWidth(curChar) - 2, 0); //height = MAX(height, _currentFont->getFrameHeight(curChar)); line++; } curY += height; } }