- added an option to define untranslated fonts through FONTDEFS. Note that due to how the fonts work they cannot be colorized AT ALL!

This commit is contained in:
Christoph Oelckers 2017-02-26 19:29:27 +01:00
commit b0eb19bbc8
2 changed files with 31 additions and 14 deletions

View file

@ -163,7 +163,7 @@ protected:
class FSpecialFont : public FFont class FSpecialFont : public FFont
{ {
public: public:
FSpecialFont (const char *name, int first, int count, FTexture **lumplist, const bool *notranslate, int lump); FSpecialFont (const char *name, int first, int count, FTexture **lumplist, const bool *notranslate, int lump, bool donttranslate);
void LoadTranslations(); void LoadTranslations();
@ -357,7 +357,7 @@ DEFINE_ACTION_FUNCTION(FFont, GetFont)
// //
//========================================================================== //==========================================================================
FFont::FFont (const char *name, const char *nametemplate, int first, int count, int start, int fdlump, int spacewidth) FFont::FFont (const char *name, const char *nametemplate, int first, int count, int start, int fdlump, int spacewidth, bool notranslate)
{ {
int i; int i;
FTextureID lump; FTextureID lump;
@ -367,6 +367,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
bool doomtemplate = gameinfo.gametype & GAME_DoomChex ? strncmp (nametemplate, "STCFN", 5) == 0 : false; bool doomtemplate = gameinfo.gametype & GAME_DoomChex ? strncmp (nametemplate, "STCFN", 5) == 0 : false;
bool stcfn121 = false; bool stcfn121 = false;
noTranslate = notranslate;
Lump = fdlump; Lump = fdlump;
Chars = new CharData[count]; Chars = new CharData[count];
charlumps = new FTexture *[count]; charlumps = new FTexture *[count];
@ -430,7 +431,8 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
if (charlumps[i] != NULL) if (charlumps[i] != NULL)
{ {
Chars[i].Pic = new FFontChar1 (charlumps[i]); if (!noTranslate) Chars[i].Pic = new FFontChar1 (charlumps[i]);
else Chars[i].Pic = charlumps[i];
Chars[i].XMove = Chars[i].Pic->GetScaledWidth(); Chars[i].XMove = Chars[i].Pic->GetScaledWidth();
} }
else else
@ -455,7 +457,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
FixXMoves(); FixXMoves();
LoadTranslations(); if (!noTranslate) LoadTranslations();
delete[] charlumps; delete[] charlumps;
} }
@ -472,11 +474,15 @@ FFont::~FFont ()
{ {
int count = LastChar - FirstChar + 1; int count = LastChar - FirstChar + 1;
for (int i = 0; i < count; ++i) // A noTranslate font directly references the original textures.
if (!noTranslate)
{ {
if (Chars[i].Pic != NULL && Chars[i].Pic->Name[0] == 0) for (int i = 0; i < count; ++i)
{ {
delete Chars[i].Pic; if (Chars[i].Pic != NULL && Chars[i].Pic->Name[0] == 0)
{
delete Chars[i].Pic;
}
} }
} }
delete[] Chars; delete[] Chars;
@ -752,7 +758,7 @@ void FFont::BuildTranslations (const double *luminosity, const BYTE *identity,
FRemapTable *FFont::GetColorTranslation (EColorRange range) const FRemapTable *FFont::GetColorTranslation (EColorRange range) const
{ {
if (ActiveColors == 0) if (ActiveColors == 0 || noTranslate)
return NULL; return NULL;
else if (range >= NumTextColors) else if (range >= NumTextColors)
range = CR_UNTRANSLATED; range = CR_UNTRANSLATED;
@ -1005,6 +1011,7 @@ FFont::FFont (int lump)
PatchRemap = NULL; PatchRemap = NULL;
FontName = NAME_None; FontName = NAME_None;
Cursor = '_'; Cursor = '_';
noTranslate = false;
} }
//========================================================================== //==========================================================================
@ -1962,7 +1969,7 @@ void FFontChar2::MakeTexture ()
// //
//========================================================================== //==========================================================================
FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **lumplist, const bool *notranslate, int lump) : FFont(lump) FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **lumplist, const bool *notranslate, int lump, bool donttranslate) : FFont(lump)
{ {
int i; int i;
FTexture **charlumps; FTexture **charlumps;
@ -1971,6 +1978,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l
memcpy(this->notranslate, notranslate, 256*sizeof(bool)); memcpy(this->notranslate, notranslate, 256*sizeof(bool));
noTranslate = donttranslate;
FontName = name; FontName = name;
Chars = new CharData[count]; Chars = new CharData[count];
charlumps = new FTexture*[count]; charlumps = new FTexture*[count];
@ -2005,7 +2013,8 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l
if (charlumps[i] != NULL) if (charlumps[i] != NULL)
{ {
Chars[i].Pic = new FFontChar1 (charlumps[i]); if (!noTranslate) Chars[i].Pic = new FFontChar1 (charlumps[i]);
else Chars[i].Pic = charlumps[i];
Chars[i].XMove = Chars[i].Pic->GetScaledWidth(); Chars[i].XMove = Chars[i].Pic->GetScaledWidth();
} }
else else
@ -2027,7 +2036,7 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l
FixXMoves(); FixXMoves();
LoadTranslations(); if (!noTranslate) LoadTranslations();
delete[] charlumps; delete[] charlumps;
} }
@ -2158,6 +2167,7 @@ void V_InitCustomFonts()
FScanner sc; FScanner sc;
FTexture *lumplist[256]; FTexture *lumplist[256];
bool notranslate[256]; bool notranslate[256];
bool donttranslate;
FString namebuffer, templatebuf; FString namebuffer, templatebuf;
int i; int i;
int llump,lastlump=0; int llump,lastlump=0;
@ -2175,6 +2185,7 @@ void V_InitCustomFonts()
{ {
memset (lumplist, 0, sizeof(lumplist)); memset (lumplist, 0, sizeof(lumplist));
memset (notranslate, 0, sizeof(notranslate)); memset (notranslate, 0, sizeof(notranslate));
donttranslate = false;
namebuffer = sc.String; namebuffer = sc.String;
format = 0; format = 0;
start = 33; start = 33;
@ -2226,6 +2237,10 @@ void V_InitCustomFonts()
spacewidth = sc.Number; spacewidth = sc.Number;
format = 1; format = 1;
} }
else if (sc.Compare("DONTTRANSLATE"))
{
donttranslate = true;
}
else if (sc.Compare ("NOTRANSLATION")) else if (sc.Compare ("NOTRANSLATION"))
{ {
if (format == 1) goto wrong; if (format == 1) goto wrong;
@ -2256,7 +2271,7 @@ void V_InitCustomFonts()
} }
if (format == 1) if (format == 1)
{ {
FFont *fnt = new FFont (namebuffer, templatebuf, first, count, start, llump, spacewidth); FFont *fnt = new FFont (namebuffer, templatebuf, first, count, start, llump, spacewidth, donttranslate);
fnt->SetCursor(cursor); fnt->SetCursor(cursor);
} }
else if (format == 2) else if (format == 2)
@ -2279,7 +2294,7 @@ void V_InitCustomFonts()
} }
if (count > 0) if (count > 0)
{ {
FFont *fnt = new FSpecialFont (namebuffer, first, count, &lumplist[first], notranslate, llump); FFont *fnt = new FSpecialFont (namebuffer, first, count, &lumplist[first], notranslate, llump, donttranslate);
fnt->SetCursor(cursor); fnt->SetCursor(cursor);
} }
} }

View file

@ -75,7 +75,7 @@ extern int NumTextColors;
class FFont class FFont
{ {
public: public:
FFont (const char *fontname, const char *nametemplate, int first, int count, int base, int fdlump, int spacewidth=-1); FFont (const char *fontname, const char *nametemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false);
virtual ~FFont (); virtual ~FFont ();
virtual FTexture *GetChar (int code, int *const width) const; virtual FTexture *GetChar (int code, int *const width) const;
@ -100,6 +100,7 @@ public:
int GetCharCode(int code, bool needpic) const; int GetCharCode(int code, bool needpic) const;
char GetCursor() const { return Cursor; } char GetCursor() const { return Cursor; }
void SetCursor(char c) { Cursor = c; } void SetCursor(char c) { Cursor = c; }
bool NoTranslate() const { return noTranslate; }
protected: protected:
FFont (int lump); FFont (int lump);
@ -116,6 +117,7 @@ protected:
int FontHeight; int FontHeight;
int GlobalKerning; int GlobalKerning;
char Cursor; char Cursor;
bool noTranslate;
struct CharData struct CharData
{ {
FTexture *Pic; FTexture *Pic;