- the font character substitution logic needed more fixes.

The ZScript DrawChar function was incomplete and FFont::GetChar did not always return the proper texture.
To make things clearer the OriginalPic is now only used in the few cases where substitution takes place and nothing else.
This commit is contained in:
Christoph Oelckers 2018-12-15 23:32:49 +01:00
parent e6e4f0f305
commit 87b0567cd7
3 changed files with 30 additions and 40 deletions

View file

@ -381,20 +381,19 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
if (charLumps[i] != nullptr) if (charLumps[i] != nullptr)
{ {
Chars[i].OriginalPic = charLumps[i];
if (!noTranslate) if (!noTranslate)
{ {
Chars[i].OriginalPic = charLumps[i];
Chars[i].TranslatedPic = new FImageTexture(new FFontChar1 (charLumps[i]->GetImage()), ""); Chars[i].TranslatedPic = new FImageTexture(new FFontChar1 (charLumps[i]->GetImage()), "");
TexMan.AddTexture(Chars[i].TranslatedPic); TexMan.AddTexture(Chars[i].TranslatedPic);
} }
else Chars[i].TranslatedPic = charLumps[i]; else Chars[i].TranslatedPic = charLumps[i];
Chars[i].XMove = Chars[i].OriginalPic->GetDisplayWidth(); Chars[i].XMove = Chars[i].TranslatedPic->GetDisplayWidth();
} }
else else
{ {
Chars[i].TranslatedPic = Chars[i].OriginalPic = nullptr; Chars[i].TranslatedPic = nullptr;
Chars[i].XMove = INT_MIN; Chars[i].XMove = INT_MIN;
} }
} }
@ -403,7 +402,7 @@ FFont::FFont (const char *name, const char *nametemplate, int first, int count,
{ {
SpaceWidth = spacewidth; SpaceWidth = spacewidth;
} }
else if ('N'-first >= 0 && 'N'-first < count && Chars['N' - first].OriginalPic != nullptr) else if ('N'-first >= 0 && 'N'-first < count && Chars['N' - first].TranslatedPic != nullptr)
{ {
SpaceWidth = (Chars['N' - first].XMove + 1) / 2; SpaceWidth = (Chars['N' - first].XMove + 1) / 2;
} }
@ -706,7 +705,7 @@ int FFont::GetCharCode(int code, bool needpic) const
// regular chars turn negative when the 8th bit is set. // regular chars turn negative when the 8th bit is set.
code &= 255; code &= 255;
} }
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].OriginalPic != nullptr)) if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].TranslatedPic != nullptr))
{ {
return code; return code;
} }
@ -714,7 +713,7 @@ int FFont::GetCharCode(int code, bool needpic) const
if (myislower(code)) if (myislower(code))
{ {
code -= 32; code -= 32;
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].OriginalPic != nullptr)) if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].TranslatedPic != nullptr))
{ {
return code; return code;
} }
@ -724,7 +723,7 @@ int FFont::GetCharCode(int code, bool needpic) const
if (newcode != code) if (newcode != code)
{ {
code = newcode; code = newcode;
if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].OriginalPic != nullptr)) if (code >= FirstChar && code <= LastChar && (!needpic || Chars[code - FirstChar].TranslatedPic != nullptr))
{ {
return code; return code;
} }
@ -747,7 +746,7 @@ FTexture *FFont::GetChar (int code, int translation, int *const width, bool *red
{ {
code -= FirstChar; code -= FirstChar;
xmove = Chars[code].XMove; xmove = Chars[code].XMove;
if (Chars[code].OriginalPic == nullptr) if (Chars[code].TranslatedPic == nullptr)
{ {
code = GetCharCode(code + FirstChar, true); code = GetCharCode(code + FirstChar, true);
if (code >= 0) if (code >= 0)
@ -766,9 +765,10 @@ FTexture *FFont::GetChar (int code, int translation, int *const width, bool *red
if (translation == CR_UNTRANSLATED) if (translation == CR_UNTRANSLATED)
{ {
if (redirected) bool redirect = Chars[code].OriginalPic && Chars[code].OriginalPic != Chars[code].TranslatedPic;
*redirected = Chars[code].OriginalPic != Chars[code].TranslatedPic; if (redirected) *redirected = redirect;
return Chars[code].OriginalPic; if (redirect)
return Chars[code].OriginalPic;
} }
if (redirected) *redirected = false; if (redirected) *redirected = false;
return Chars[code].TranslatedPic; return Chars[code].TranslatedPic;
@ -963,7 +963,7 @@ void FSingleLumpFont::CreateFontFromPic (FTextureID picnum)
FirstChar = LastChar = 'A'; FirstChar = LastChar = 'A';
Chars.Resize(1); Chars.Resize(1);
Chars[0].TranslatedPic = Chars[0].OriginalPic = pic; Chars[0].TranslatedPic = pic;
// Only one color range. Don't bother with the others. // Only one color range. Don't bother with the others.
ActiveColors = 0; ActiveColors = 0;
@ -1040,10 +1040,6 @@ void FSingleLumpFont::LoadFON1 (int lump, const uint8_t *data)
LastChar = 255; LastChar = 255;
GlobalKerning = 0; GlobalKerning = 0;
translateUntranslated = true; translateUntranslated = true;
for(unsigned int i = 0;i < 256;++i)
Chars[i].TranslatedPic = Chars[i].OriginalPic = nullptr;
LoadTranslations(); LoadTranslations();
} }
@ -1128,12 +1124,12 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data)
Chars[i].XMove = widths2[i]; Chars[i].XMove = widths2[i];
if (destSize <= 0) if (destSize <= 0)
{ {
Chars[i].TranslatedPic = Chars[i].OriginalPic = nullptr; Chars[i].TranslatedPic = nullptr;
} }
else else
{ {
Chars[i].TranslatedPic = Chars[i].OriginalPic = new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)); Chars[i].TranslatedPic = new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight));
TexMan.AddTexture(Chars[i].OriginalPic); TexMan.AddTexture(Chars[i].TranslatedPic);
do do
{ {
int8_t code = *data_p++; int8_t code = *data_p++;
@ -1216,12 +1212,6 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data)
} }
count = LastChar - FirstChar + 1; count = LastChar - FirstChar + 1;
Chars.Resize(count); Chars.Resize(count);
for (i = 0; i < count; ++i)
{
Chars[i].TranslatedPic = Chars[i].OriginalPic = nullptr;
Chars[i].XMove = INT_MIN;
}
// BMF palettes are only six bits per component. Fix that. // BMF palettes are only six bits per component. Fix that.
for (i = 0; i < ActiveColors*3; ++i) for (i = 0; i < ActiveColors*3; ++i)
{ {
@ -1273,7 +1263,7 @@ void FSingleLumpFont::LoadBMF(int lump, const uint8_t *data)
-(int8_t)chardata[chari+3], // x offset -(int8_t)chardata[chari+3], // x offset
-(int8_t)chardata[chari+4] // y offset -(int8_t)chardata[chari+4] // y offset
)); ));
Chars[chardata[chari] - FirstChar].TranslatedPic = Chars[chardata[chari] - FirstChar].OriginalPic = tex; Chars[chardata[chari] - FirstChar].TranslatedPic = tex;
TexMan.AddTexture(tex); TexMan.AddTexture(tex);
} }
@ -1337,13 +1327,12 @@ void FSingleLumpFont::CheckFON1Chars (double *luminosity)
{ {
int destSize = SpaceWidth * FontHeight; int destSize = SpaceWidth * FontHeight;
if(!Chars[i].OriginalPic) if(!Chars[i].TranslatedPic)
{ {
Chars[i].OriginalPic = new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight)); Chars[i].TranslatedPic = new FImageTexture(new FFontChar2 (Lump, int(data_p - data), SpaceWidth, FontHeight));
Chars[i].XMove = SpaceWidth; Chars[i].XMove = SpaceWidth;
TexMan.AddTexture(Chars[i].OriginalPic); TexMan.AddTexture(Chars[i].TranslatedPic);
} }
Chars[i].TranslatedPic = Chars[i].OriginalPic;
// Advance to next char's data and count the used colors. // Advance to next char's data and count the used colors.
do do
@ -1552,24 +1541,24 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FTexture **l
if (charlumps[i] != nullptr) if (charlumps[i] != nullptr)
{ {
Chars[i].OriginalPic = charlumps[i];
if (!noTranslate) if (!noTranslate)
{ {
Chars[i].TranslatedPic = new FImageTexture(new FFontChar1 (charlumps[i]->GetImage()), ""); Chars[i].TranslatedPic = new FImageTexture(new FFontChar1 (charlumps[i]->GetImage()), "");
TexMan.AddTexture(Chars[i].TranslatedPic); TexMan.AddTexture(Chars[i].TranslatedPic);
} }
else Chars[i].TranslatedPic = charlumps[i]; else Chars[i].TranslatedPic = charlumps[i];
Chars[i].OriginalPic = Chars[i].TranslatedPic; Chars[i].XMove = Chars[i].TranslatedPic->GetDisplayWidth();
Chars[i].XMove = Chars[i].OriginalPic->GetDisplayWidth();
} }
else else
{ {
Chars[i].TranslatedPic = Chars[i].OriginalPic = nullptr; Chars[i].TranslatedPic = nullptr;
Chars[i].XMove = INT_MIN; Chars[i].XMove = INT_MIN;
} }
} }
// Special fonts normally don't have all characters so be careful here! // Special fonts normally don't have all characters so be careful here!
if ('N'-first >= 0 && 'N'-first < count && Chars['N' - first].OriginalPic != nullptr) if ('N'-first >= 0 && 'N'-first < count && Chars['N' - first].TranslatedPic != nullptr)
{ {
SpaceWidth = (Chars['N' - first].XMove + 1) / 2; SpaceWidth = (Chars['N' - first].XMove + 1) / 2;
} }

View file

@ -123,9 +123,9 @@ protected:
bool translateUntranslated; bool translateUntranslated;
struct CharData struct CharData
{ {
FTexture *TranslatedPic; // Texture for use with font translations. FTexture *TranslatedPic = nullptr; // Texture for use with font translations.
FTexture *OriginalPic; // Texture for use with CR_UNTRANSLATED or font colorization. FTexture *OriginalPic = nullptr; // Texture for use with CR_UNTRANSLATED or font colorization.
int XMove; int XMove = INT_MIN;
}; };
TArray<CharData> Chars; TArray<CharData> Chars;
int ActiveColors; int ActiveColors;

View file

@ -169,15 +169,16 @@ void DFrameBuffer::DrawChar(FFont *font, int normalcolor, double x, double y, in
FTexture *pic; FTexture *pic;
int dummy; int dummy;
bool redirected;
if (NULL != (pic = font->GetChar(character, normalcolor, &dummy))) if (NULL != (pic = font->GetChar(character, normalcolor, &dummy, &redirected)))
{ {
DrawParms parms; DrawParms parms;
uint32_t tag = ListGetInt(args); uint32_t tag = ListGetInt(args);
bool res = ParseDrawTextureTags(pic, x, y, tag, args, &parms, false); bool res = ParseDrawTextureTags(pic, x, y, tag, args, &parms, false);
if (!res) return; if (!res) return;
PalEntry color = 0xffffffff; PalEntry color = 0xffffffff;
parms.remap = font->GetColorTranslation((EColorRange)normalcolor, &color); parms.remap = redirected ? nullptr : font->GetColorTranslation((EColorRange)normalcolor, &color);
parms.color = PalEntry((color.a * parms.color.a) / 255, (color.r * parms.color.r) / 255, (color.g * parms.color.g) / 255, (color.b * parms.color.b) / 255); parms.color = PalEntry((color.a * parms.color.a) / 255, (color.r * parms.color.r) / 255, (color.g * parms.color.g) / 255, (color.b * parms.color.b) / 255);
DrawTextureParms(pic, parms); DrawTextureParms(pic, parms);
} }