void Text::makeTextSprite(uint8 slot, uint8 *text, uint16 maxWidth, uint8 pen) { LineInfo lines[MAX_LINES]; uint16 numLines = analyzeSentence(text, maxWidth, lines); uint16 sprWidth = 0; uint16 lineCnt; for (lineCnt = 0; lineCnt < numLines; lineCnt++) if (lines[lineCnt].width > sprWidth) sprWidth = lines[lineCnt].width; uint16 sprHeight = _charHeight * numLines; uint32 sprSize = sprWidth * sprHeight; assert(!_textBlocks[slot]); // if this triggers, the speechDriver failed to call Text::releaseText. _textBlocks[slot] = (FrameHeader*)malloc(sprSize + sizeof(FrameHeader)); memcpy(_textBlocks[slot]->runTimeComp, "Nu ", 4); _textBlocks[slot]->compSize = 0; _textBlocks[slot]->width = _resMan->toUint16(sprWidth); _textBlocks[slot]->height = _resMan->toUint16(sprHeight); _textBlocks[slot]->offsetX = 0; _textBlocks[slot]->offsetY = 0; uint8 *linePtr = ((uint8*)_textBlocks[slot]) + sizeof(FrameHeader); memset(linePtr, NO_COL, sprSize); for (lineCnt = 0; lineCnt < numLines; lineCnt++) { uint8 *sprPtr = linePtr + (sprWidth - lines[lineCnt].width) / 2; // center the text for (uint16 pos = 0; pos < lines[lineCnt].length; pos++) sprPtr += copyChar(*text++, sprPtr, sprWidth, pen) - OVERLAP; text++; // skip space at the end of the line if(SwordEngine::isPsx()) //Chars are half height in psx version linePtr += (_charHeight / 2) * sprWidth; else linePtr += _charHeight * sprWidth; } }
byte *FontRenderer::makeTextSprite(byte *sentence, uint16 maxWidth, uint8 pen, uint32 fontRes, uint8 border) { debug(5, "makeTextSprite(\"%s\", maxWidth=%u)", sentence, maxWidth); _borderPen = border; // Line- and character spacing are hard-wired, rather than being part // of the resource. if (fontRes == _vm->_speechFontId) { if (Sword2Engine::isPsx()) _lineSpacing = -4; // Text would be unreadable with psx font if linespacing is higher else _lineSpacing = -6; _charSpacing = -3; } else if (fontRes == CONSOLE_FONT_ID) { _lineSpacing = 0; _charSpacing = 1; } else { _lineSpacing = 0; _charSpacing = 0; } // Allocate memory for array of lineInfo structures byte *line = (byte *)malloc(MAX_LINES * sizeof(LineInfo)); // Get details of sentence breakdown into array of LineInfo structures // and get the number of lines involved uint16 noOfLines = analyzeSentence(sentence, maxWidth, fontRes, (LineInfo *)line); // Construct the sprite based on the info gathered - returns floating // mem block byte *textSprite = buildTextSprite(sentence, fontRes, pen, (LineInfo *)line, noOfLines); free(line); return textSprite; }