2017-05-26 05:24:38 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-06-05 19:10:47 +02:00
|
|
|
#include "sludge/allfiles.h"
|
|
|
|
#include "sludge/stringy.h"
|
|
|
|
#include "sludge/sprites.h"
|
|
|
|
#include "sludge/fonttext.h"
|
|
|
|
#include "sludge/newfatal.h"
|
|
|
|
#include "sludge/moreio.h"
|
2017-07-06 22:05:13 +02:00
|
|
|
#include "sludge/utf8.h"
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-05-26 21:25:11 +02:00
|
|
|
namespace Sludge {
|
|
|
|
|
2017-05-26 05:24:38 +02:00
|
|
|
spriteBank theFont;
|
|
|
|
int fontHeight = 0, numFontColours, loadedFontNum;
|
2017-07-10 23:52:11 +02:00
|
|
|
UTF8Converter fontOrder;
|
2017-07-10 21:44:14 +02:00
|
|
|
int16 fontSpace = -1;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-06-05 19:35:03 +02:00
|
|
|
uint32 *fontTable = NULL;
|
2017-07-06 22:05:13 +02:00
|
|
|
uint fontTableSize = 0;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-06-05 19:35:03 +02:00
|
|
|
#define fontInTable(x) ((x<fontTableSize) ? fontTable[(uint32) x] : 0)
|
2017-05-26 05:24:38 +02:00
|
|
|
|
|
|
|
extern float cameraZoom;
|
|
|
|
|
|
|
|
bool isInFont(char *theText) {
|
2017-05-29 08:02:59 +02:00
|
|
|
if (!fontTableSize)
|
|
|
|
return 0;
|
|
|
|
if (!theText[0])
|
|
|
|
return 0;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-07-06 22:05:13 +02:00
|
|
|
Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
|
|
|
|
|
2017-05-26 05:24:38 +02:00
|
|
|
// We don't want to compare strings. Only single characters allowed!
|
2017-07-06 22:05:13 +02:00
|
|
|
if (str32.size() > 1)
|
2017-05-29 08:02:59 +02:00
|
|
|
return false;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-07-06 22:05:13 +02:00
|
|
|
uint32 c = str32[0];
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-07-06 22:05:13 +02:00
|
|
|
// check if font order contains the utf8 char
|
2017-07-10 23:52:11 +02:00
|
|
|
return fontOrder.getU32String().contains(c);
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int stringLength(char *theText) {
|
2017-07-06 22:05:13 +02:00
|
|
|
Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
|
|
|
|
return str32.size();
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int stringWidth(char *theText) {
|
|
|
|
int xOff = 0;
|
|
|
|
|
2017-05-29 08:02:59 +02:00
|
|
|
if (!fontTableSize)
|
|
|
|
return 0;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-07-06 22:05:13 +02:00
|
|
|
Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
|
|
|
|
|
|
|
|
for (uint i = 0; i < str32.size(); ++i) {
|
|
|
|
uint32 c = str32[i];
|
2017-06-01 00:57:24 +02:00
|
|
|
xOff += theFont.sprites[fontInTable(c)].surface.w + fontSpace;
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return xOff;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pasteString(char *theText, int xOff, int y, spritePalette &thePal) {
|
2017-05-29 08:02:59 +02:00
|
|
|
if (!fontTableSize)
|
|
|
|
return;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-06-05 11:49:19 +02:00
|
|
|
xOff += (int)((float)(fontSpace >> 1) / cameraZoom);
|
2017-07-06 22:05:13 +02:00
|
|
|
|
|
|
|
Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
|
|
|
|
|
|
|
|
for (uint32 i = 0; i < str32.size(); ++i) {
|
|
|
|
uint32 c = str32[i];
|
|
|
|
sprite *mySprite = &theFont.sprites[fontInTable(c)];
|
2017-05-29 08:02:59 +02:00
|
|
|
fontSprite(xOff, y, *mySprite, thePal);
|
2017-06-05 11:49:19 +02:00
|
|
|
xOff += (int)((double)(mySprite->surface.w + fontSpace) / cameraZoom);
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 11:49:19 +02:00
|
|
|
void pasteStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) {
|
2017-05-29 08:02:59 +02:00
|
|
|
if (!fontTableSize)
|
|
|
|
return;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-07-06 22:05:13 +02:00
|
|
|
Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
|
|
|
|
|
2017-05-26 05:24:38 +02:00
|
|
|
xOff += fontSpace >> 1;
|
2017-07-06 22:05:13 +02:00
|
|
|
for (uint32 i = 0; i < str32.size(); ++i) {
|
|
|
|
uint32 c = str32[i];
|
|
|
|
sprite *mySprite = &theFont.sprites[fontInTable(c)];
|
2017-05-29 08:02:59 +02:00
|
|
|
pasteSpriteToBackDrop(xOff, y, *mySprite, thePal);
|
2017-06-01 00:57:24 +02:00
|
|
|
xOff += mySprite->surface.w + fontSpace;
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-05 11:49:19 +02:00
|
|
|
void burnStringToBackdrop(char *theText, int xOff, int y, spritePalette &thePal) {
|
2017-05-29 08:02:59 +02:00
|
|
|
if (!fontTableSize)
|
|
|
|
return;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-07-06 22:05:13 +02:00
|
|
|
Common::U32String str32 = UTF8Converter::convertUtf8ToUtf32(theText);
|
|
|
|
|
2017-05-26 05:24:38 +02:00
|
|
|
xOff += fontSpace >> 1;
|
2017-07-06 22:05:13 +02:00
|
|
|
for (uint i = 0; i < str32.size(); ++i) {
|
|
|
|
uint32 c = str32[i];
|
|
|
|
sprite *mySprite = &theFont.sprites[fontInTable(c)];
|
2017-05-29 08:02:59 +02:00
|
|
|
burnSpriteToBackDrop(xOff, y, *mySprite, thePal);
|
2017-06-01 00:57:24 +02:00
|
|
|
xOff += mySprite->surface.w + fontSpace;
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void fixFont(spritePalette &spal) {
|
|
|
|
#if 0
|
|
|
|
delete [] spal.tex_names;
|
|
|
|
delete [] spal.burnTex_names;
|
|
|
|
delete [] spal.tex_h;
|
|
|
|
delete [] spal.tex_w;
|
|
|
|
|
|
|
|
spal.numTextures = theFont.myPalette.numTextures;
|
|
|
|
|
|
|
|
spal.tex_names = new GLuint [spal.numTextures];
|
|
|
|
if (! checkNew(spal.tex_names)) return;
|
|
|
|
spal.burnTex_names = new GLuint [spal.numTextures];
|
|
|
|
if (! checkNew(spal.burnTex_names)) return;
|
|
|
|
spal.tex_w = new int [spal.numTextures];
|
|
|
|
if (! checkNew(spal.tex_w)) return;
|
|
|
|
spal.tex_h = new int [spal.numTextures];
|
|
|
|
if (! checkNew(spal.tex_h)) return;
|
|
|
|
|
|
|
|
for (int i = 0; i < theFont.myPalette.numTextures; i++) {
|
|
|
|
spal.tex_names[i] = theFont.myPalette.tex_names[i];
|
|
|
|
spal.burnTex_names[i] = theFont.myPalette.burnTex_names[i];
|
|
|
|
spal.tex_w[i] = theFont.myPalette.tex_w[i];
|
|
|
|
spal.tex_h[i] = theFont.myPalette.tex_h[i];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFontColour(spritePalette &sP, byte r, byte g, byte b) {
|
|
|
|
sP.originalRed = r;
|
|
|
|
sP.originalGreen = g;
|
|
|
|
sP.originalBlue = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool loadFont(int filenum, const char *charOrder, int h) {
|
2017-07-10 23:52:11 +02:00
|
|
|
fontOrder.setUTF8String(charOrder);
|
2017-05-26 05:24:38 +02:00
|
|
|
|
|
|
|
forgetSpriteBank(theFont);
|
|
|
|
|
|
|
|
loadedFontNum = filenum;
|
|
|
|
|
2017-07-06 22:05:13 +02:00
|
|
|
// get max value among all utf8 chars
|
2017-07-10 23:52:11 +02:00
|
|
|
Common::U32String fontOrderString = fontOrder.getU32String();
|
2017-05-26 05:24:38 +02:00
|
|
|
fontTableSize = 0;
|
2017-07-06 22:05:13 +02:00
|
|
|
for (uint32 i = 0; i < fontOrderString.size(); ++i) {
|
|
|
|
uint32 c = fontOrderString[i];
|
2017-05-29 08:02:59 +02:00
|
|
|
if (c > fontTableSize)
|
|
|
|
fontTableSize = c;
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
fontTableSize++;
|
|
|
|
|
2017-07-06 22:05:13 +02:00
|
|
|
// create an index table from utf8 char to the index
|
2017-05-29 08:02:59 +02:00
|
|
|
delete[] fontTable;
|
2017-06-05 19:35:03 +02:00
|
|
|
fontTable = new uint32[fontTableSize];
|
2017-05-29 08:02:59 +02:00
|
|
|
if (!checkNew(fontTable))
|
|
|
|
return false;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-07-06 22:05:13 +02:00
|
|
|
for (uint i = 0; i < fontTableSize; i++) {
|
|
|
|
fontTable[i] = 0;
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
2017-07-06 22:05:13 +02:00
|
|
|
|
|
|
|
for (uint i = 0; i < fontOrderString.size(); ++i) {
|
|
|
|
uint32 c = fontOrderString[i];
|
2017-05-26 05:24:38 +02:00
|
|
|
fontTable[c] = i;
|
|
|
|
}
|
|
|
|
|
2017-05-29 08:02:59 +02:00
|
|
|
if (!loadSpriteBank(filenum, theFont, true)) {
|
2017-05-26 05:24:38 +02:00
|
|
|
fatal("Can't load font");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
numFontColours = theFont.myPalette.total;
|
|
|
|
fontHeight = h;
|
|
|
|
return true;
|
|
|
|
}
|
2017-05-26 21:25:11 +02:00
|
|
|
|
|
|
|
} // End of namespace Sludge
|