- got rid of most of the font system's baggage that's no longer needed.

Mainly this means that it's no longer necessary to reorder the palette to get working translated glyphs, so the FFontChar1 class and the TranslatedPic member and its invasive handling could all be cleaned out.
All font operations now take place on true color data, with the sole execption of FSpecialFont's 'notranslate' handling.
This commit is contained in:
Christoph Oelckers 2021-05-24 19:27:07 +02:00
parent 9769f346ec
commit 8b1757eee2
10 changed files with 36 additions and 155 deletions

View file

@ -173,9 +173,8 @@ void DrawChar(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double
FGameTexture* pic; FGameTexture* pic;
int dummy; int dummy;
bool redirected;
if (NULL != (pic = font->GetChar(character, normalcolor, &dummy, &redirected))) if (NULL != (pic = font->GetChar(character, normalcolor, &dummy)))
{ {
DrawParms parms; DrawParms parms;
Va_List tags; Va_List tags;
@ -188,7 +187,7 @@ void DrawChar(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double
} }
bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0); bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0);
PalEntry color = 0xffffffff; PalEntry color = 0xffffffff;
if (!palettetrans) parms.TranslationId = redirected ? -1 : font->GetColorTranslation((EColorRange)normalcolor, &color); if (!palettetrans) parms.TranslationId = 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);
drawer->AddTexture(pic, parms); drawer->AddTexture(pic, parms);
} }
@ -204,9 +203,8 @@ void DrawChar(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double
FGameTexture *pic; FGameTexture *pic;
int dummy; int dummy;
bool redirected;
if (NULL != (pic = font->GetChar(character, normalcolor, &dummy, &redirected))) if (NULL != (pic = font->GetChar(character, normalcolor, &dummy)))
{ {
DrawParms parms; DrawParms parms;
uint32_t tag = ListGetInt(args); uint32_t tag = ListGetInt(args);
@ -214,7 +212,7 @@ void DrawChar(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double
if (!res) return; if (!res) return;
bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0); bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0);
PalEntry color = 0xffffffff; PalEntry color = 0xffffffff;
if (!palettetrans) parms.TranslationId = redirected ? -1 : font->GetColorTranslation((EColorRange)normalcolor, &color); if (!palettetrans) parms.TranslationId = 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);
drawer->AddTexture(pic, parms); drawer->AddTexture(pic, parms);
} }
@ -316,11 +314,10 @@ void DrawTextCommon(F2DDrawer *drawer, FFont *font, int normalcolor, double x, d
continue; continue;
} }
bool redirected = false; if (NULL != (pic = font->GetChar(c, currentcolor, &w)))
if (NULL != (pic = font->GetChar(c, currentcolor, &w, &redirected)))
{ {
// if palette translation is used, font colors will be ignored. // if palette translation is used, font colors will be ignored.
if (!palettetrans) parms.TranslationId = redirected? -1 : trans; if (!palettetrans) parms.TranslationId = trans;
SetTextureParms(drawer, &parms, pic, cx, cy); SetTextureParms(drawer, &parms, pic, cx, cy);
if (parms.cellx) if (parms.cellx)
{ {

View file

@ -333,23 +333,13 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
TexMan.AddGameTexture(tex); TexMan.AddGameTexture(tex);
Chars[i].OriginalPic = tex; Chars[i].OriginalPic = tex;
if (!noTranslate) if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].OriginalPic);
{
Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(orig->GetImage())), nullptr, ETextureType::FontChar);
Chars[i].TranslatedPic->CopySize(pic, true);
TexMan.AddGameTexture(Chars[i].TranslatedPic);
}
else
{
Chars[i].TranslatedPic = tex;
}
if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].TranslatedPic);
Chars[i].XMove = (int)Chars[i].TranslatedPic->GetDisplayWidth(); Chars[i].XMove = (int)Chars[i].OriginalPic->GetDisplayWidth();
} }
else else
{ {
Chars[i].TranslatedPic = nullptr; Chars[i].OriginalPic = nullptr;
Chars[i].XMove = INT_MIN; Chars[i].XMove = INT_MIN;
} }
} }
@ -360,7 +350,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
{ {
SpaceWidth = spacewidth; SpaceWidth = spacewidth;
} }
else if ('N' - FirstChar >= 0 && 'N' - FirstChar < count && Chars['N' - FirstChar].TranslatedPic != nullptr) else if ('N' - FirstChar >= 0 && 'N' - FirstChar < count && Chars['N' - FirstChar].OriginalPic != nullptr)
{ {
SpaceWidth = (Chars['N' - FirstChar].XMove + 1) / 2; SpaceWidth = (Chars['N' - FirstChar].XMove + 1) / 2;
} }
@ -444,11 +434,7 @@ void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height
Chars[i].OriginalPic = (*lump)->GetUseType() == ETextureType::FontChar? (*lump) : MakeGameTexture(pic, nullptr, ETextureType::FontChar); Chars[i].OriginalPic = (*lump)->GetUseType() == ETextureType::FontChar? (*lump) : MakeGameTexture(pic, nullptr, ETextureType::FontChar);
Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); Chars[i].OriginalPic->SetUseType(ETextureType::FontChar);
Chars[i].OriginalPic->CopySize(*lump, true); Chars[i].OriginalPic->CopySize(*lump, true);
Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1(pic->GetImage())), nullptr, ETextureType::FontChar);
Chars[i].TranslatedPic->CopySize(*lump, true);
Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar);
if (Chars[i].OriginalPic != *lump) TexMan.AddGameTexture(Chars[i].OriginalPic); if (Chars[i].OriginalPic != *lump) TexMan.AddGameTexture(Chars[i].OriginalPic);
TexMan.AddGameTexture(Chars[i].TranslatedPic);
} }
Chars[i].XMove = width; Chars[i].XMove = width;
} }
@ -596,16 +582,10 @@ void FFont::RecordAllTextureColors(uint32_t *usedcolors)
{ {
for (unsigned int i = 0; i < Chars.Size(); i++) for (unsigned int i = 0; i < Chars.Size(); i++)
{ {
if (Chars[i].TranslatedPic) if (Chars[i].OriginalPic)
{ {
FFontChar1 *pic = static_cast<FFontChar1 *>(Chars[i].TranslatedPic->GetTexture()->GetImage()); auto pic = Chars[i].OriginalPic->GetTexture()->GetImage();
if (pic) if (pic) RecordTextureColors(pic, usedcolors);
{
// The remap must be temporarily reset here because this can be called on an initialized font.
auto sr = pic->ResetSourceRemap();
RecordTextureColors(pic, usedcolors);
pic->SetSourceRemap(sr);
}
} }
} }
} }
@ -772,7 +752,6 @@ int FFont::GetColorTranslation (EColorRange range, PalEntry *color) const
return -1; return -1;
else if (range >= NumTextColors) else if (range >= NumTextColors)
range = CR_UNTRANSLATED; range = CR_UNTRANSLATED;
//if (range == CR_UNTRANSLATED && !translateUntranslated) return nullptr;
return Translations[range]; return Translations[range];
} }
@ -867,7 +846,7 @@ int FFont::GetCharCode(int code, bool needpic) const
// //
//========================================================================== //==========================================================================
FGameTexture *FFont::GetChar (int code, int translation, int *const width, bool *redirected) const FGameTexture *FFont::GetChar (int code, int translation, int *const width) const
{ {
code = GetCharCode(code, true); code = GetCharCode(code, true);
int xmove = SpaceWidth; int xmove = SpaceWidth;
@ -885,24 +864,8 @@ FGameTexture *FFont::GetChar (int code, int translation, int *const width, bool
if (code < 0) return nullptr; if (code < 0) return nullptr;
if ((translation == CR_UNTRANSLATED || translation == CR_UNDEFINED || translation >= NumTextColors) && !forceremap)
{
bool redirect = Chars[code].OriginalPic && Chars[code].OriginalPic != Chars[code].TranslatedPic;
if (redirected) *redirected = redirect;
if (redirect)
{
assert(Chars[code].OriginalPic->GetUseType() == ETextureType::FontChar); assert(Chars[code].OriginalPic->GetUseType() == ETextureType::FontChar);
return Chars[code].OriginalPic; return Chars[code].OriginalPic;
}
}
if (redirected) *redirected = false;
if (IsLuminosityTranslation(Translations[translation]))
{
assert(Chars[code].OriginalPic->GetUseType() == ETextureType::FontChar);
return Chars[code].OriginalPic;
}
assert(Chars[code].TranslatedPic->GetUseType() == ETextureType::FontChar);
return Chars[code].TranslatedPic;
} }
//========================================================================== //==========================================================================

View file

@ -301,10 +301,9 @@ public:
{ {
auto offset = hexdata.glyphmap[i]; auto offset = hexdata.glyphmap[i];
int size = hexdata.glyphdata[offset] / 16; int size = hexdata.glyphdata[offset] / 16;
Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar(&hexdata.glyphdata[offset + 1], size, size * 9, 16)), nullptr, ETextureType::FontChar); Chars[i - FirstChar].OriginalPic = MakeGameTexture(new FImageTexture(new FHexFontChar(&hexdata.glyphdata[offset + 1], size, size * 9, 16)), nullptr, ETextureType::FontChar);
Chars[i - FirstChar].OriginalPic = Chars[i - FirstChar].TranslatedPic;
Chars[i - FirstChar].XMove = size * spacing; Chars[i - FirstChar].XMove = size * spacing;
TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); TexMan.AddGameTexture(Chars[i - FirstChar].OriginalPic);
} }
else Chars[i - FirstChar].XMove = spacing; else Chars[i - FirstChar].XMove = spacing;
@ -369,10 +368,9 @@ public:
{ {
auto offset = hexdata.glyphmap[i]; auto offset = hexdata.glyphmap[i];
int size = hexdata.glyphdata[offset] / 16; int size = hexdata.glyphdata[offset] / 16;
Chars[i - FirstChar].TranslatedPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), nullptr, ETextureType::FontChar); Chars[i - FirstChar].OriginalPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), nullptr, ETextureType::FontChar);
Chars[i - FirstChar].OriginalPic = Chars[i - FirstChar].TranslatedPic;
Chars[i - FirstChar].XMove = size * spacing; Chars[i - FirstChar].XMove = size * spacing;
TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); TexMan.AddGameTexture(Chars[i - FirstChar].OriginalPic);
} }
else Chars[i - FirstChar].XMove = spacing; else Chars[i - FirstChar].XMove = spacing;

View file

@ -188,8 +188,8 @@ void FSingleLumpFont::LoadTranslations()
for(unsigned int i = 0;i < count;++i) for(unsigned int i = 0;i < count;++i)
{ {
if(Chars[i].TranslatedPic) if(Chars[i].OriginalPic)
static_cast<FFontChar2*>(Chars[i].TranslatedPic->GetTexture()->GetImage())->SetSourceRemap(Palette); static_cast<FFontChar2*>(Chars[i].OriginalPic->GetTexture()->GetImage())->SetSourceRemap(Palette);
} }
Translations.Resize(NumTextColors); Translations.Resize(NumTextColors);
@ -325,14 +325,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 = nullptr;
Chars[i].OriginalPic = nullptr; Chars[i].OriginalPic = nullptr;
} }
else else
{ {
Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)), nullptr, ETextureType::FontChar); Chars[i].OriginalPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)), nullptr, ETextureType::FontChar);
Chars[i].OriginalPic = Chars[i].TranslatedPic; TexMan.AddGameTexture(Chars[i].OriginalPic);
TexMan.AddGameTexture(Chars[i].TranslatedPic);
do do
{ {
int8_t code = *data_p++; int8_t code = *data_p++;
@ -445,7 +443,6 @@ 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
)), nullptr, ETextureType::FontChar); )), nullptr, ETextureType::FontChar);
Chars[chardata[chari] - FirstChar].TranslatedPic = tex;
Chars[chardata[chari] - FirstChar].OriginalPic = tex; Chars[chardata[chari] - FirstChar].OriginalPic = tex;
TexMan.AddGameTexture(tex); TexMan.AddGameTexture(tex);
} }
@ -488,12 +485,11 @@ void FSingleLumpFont::CheckFON1Chars()
{ {
int destSize = SpaceWidth * FontHeight; int destSize = SpaceWidth * FontHeight;
if (!Chars[i].TranslatedPic) if (!Chars[i].OriginalPic)
{ {
Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar2(Lump, int(data_p - data), SpaceWidth, FontHeight)), nullptr, ETextureType::FontChar); Chars[i].OriginalPic = MakeGameTexture(new FImageTexture(new FFontChar2(Lump, int(data_p - data), SpaceWidth, FontHeight)), nullptr, ETextureType::FontChar);
Chars[i].OriginalPic = Chars[i].TranslatedPic;
Chars[i].XMove = SpaceWidth; Chars[i].XMove = SpaceWidth;
TexMan.AddGameTexture(Chars[i].TranslatedPic); TexMan.AddGameTexture(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.

View file

@ -45,7 +45,7 @@ public:
FSinglePicFont(const char *picname); FSinglePicFont(const char *picname);
// FFont interface // FFont interface
FGameTexture *GetChar(int code, int translation, int *const width, bool *redirected = nullptr) const override; FGameTexture *GetChar(int code, int translation, int *const width) const override;
int GetCharWidth (int code) const override; int GetCharWidth (int code) const override;
protected: protected:
@ -94,10 +94,9 @@ FSinglePicFont::FSinglePicFont(const char *picname) :
// //
//========================================================================== //==========================================================================
FGameTexture *FSinglePicFont::GetChar (int code, int translation, int *const width, bool *redirected) const FGameTexture *FSinglePicFont::GetChar (int code, int translation, int *const width) const
{ {
*width = SpaceWidth; *width = SpaceWidth;
if (redirected) *redirected = false;
if (code == 'a' || code == 'A') if (code == 'a' || code == 'A')
{ {
return TexMan.GetGameTexture(PicNum, true); return TexMan.GetGameTexture(PicNum, true);

View file

@ -108,26 +108,18 @@ FSpecialFont::FSpecialFont (const char *name, int first, int count, FGameTexture
Chars[i].OriginalPic = MakeGameTexture(pic->GetTexture(), nullptr, ETextureType::FontChar); Chars[i].OriginalPic = MakeGameTexture(pic->GetTexture(), nullptr, ETextureType::FontChar);
Chars[i].OriginalPic->CopySize(pic, true); Chars[i].OriginalPic->CopySize(pic, true);
TexMan.AddGameTexture(Chars[i].OriginalPic); TexMan.AddGameTexture(Chars[i].OriginalPic);
Chars[i].XMove = (int)Chars[i].OriginalPic->GetDisplayWidth();
if (!noTranslate) if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].OriginalPic);
{
Chars[i].TranslatedPic = MakeGameTexture(new FImageTexture(new FFontChar1 (charlumps[i]->GetTexture()->GetImage())), nullptr, ETextureType::FontChar);
Chars[i].TranslatedPic->CopySize(charlumps[i], true);
TexMan.AddGameTexture(Chars[i].TranslatedPic);
}
else Chars[i].TranslatedPic = Chars[i].OriginalPic;
Chars[i].XMove = (int)Chars[i].TranslatedPic->GetDisplayWidth();
if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].TranslatedPic);
} }
else else
{ {
Chars[i].TranslatedPic = nullptr; Chars[i].OriginalPic = 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].TranslatedPic != nullptr) if ('N'-first >= 0 && 'N'-first < count && Chars['N' - first].OriginalPic != nullptr)
{ {
SpaceWidth = (Chars['N' - first].XMove + 1) / 2; SpaceWidth = (Chars['N' - first].XMove + 1) / 2;
} }

View file

@ -97,7 +97,7 @@ public:
FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false, bool doomtemplate = false, GlyphSet *baseGlpyphs = nullptr); FFont (const char *fontname, const char *nametemplate, const char *filetemplate, int first, int count, int base, int fdlump, int spacewidth=-1, bool notranslate = false, bool iwadonly = false, bool doomtemplate = false, GlyphSet *baseGlpyphs = nullptr);
virtual ~FFont (); virtual ~FFont ();
virtual FGameTexture *GetChar (int code, int translation, int *const width, bool *redirected = nullptr) const; virtual FGameTexture *GetChar (int code, int translation, int *const width) const;
virtual int GetCharWidth (int code) const; virtual int GetCharWidth (int code) const;
int GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const; int GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const;
int GetLump() const { return Lump; } int GetLump() const { return Lump; }
@ -159,8 +159,7 @@ protected:
bool forceremap = false; bool forceremap = false;
struct CharData struct CharData
{ {
FGameTexture *TranslatedPic = nullptr; // Texture for use with font translations. FGameTexture *OriginalPic = nullptr;
FGameTexture *OriginalPic = nullptr; // Texture for use with CR_UNTRANSLATED or font colorization.
int XMove = INT_MIN; int XMove = INT_MIN;
}; };
TArray<CharData> Chars; TArray<CharData> Chars;

View file

@ -41,48 +41,6 @@
#include "fontchars.h" #include "fontchars.h"
#include "engineerrors.h" #include "engineerrors.h"
//==========================================================================
//
// FFontChar1 :: FFontChar1
//
// Used by fonts made from textures.
//
//==========================================================================
FFontChar1::FFontChar1(FImageSource* sourcelump)
: BaseTexture(sourcelump), SourceRemap(nullptr)
{
// now copy all the properties from the base texture
assert(BaseTexture != nullptr);
CopySize(*BaseTexture);
bUseGamePalette = false;
}
//==========================================================================
//
// FFontChar1 :: GetPixels
//
// Render style is not relevant for fonts. This must not use it!
//
//==========================================================================
TArray<uint8_t> FFontChar1::CreatePalettedPixels(int)
{
// Make the texture as normal, then remap it so that all the colors
// are at the low end of the palette
// Why? It only creates unnecessary work!
auto Pixels = BaseTexture->GetPalettedPixels(normal);
if (SourceRemap)
{
for (int x = 0; x < Width * Height; ++x)
{
Pixels[x] = SourceRemap[Pixels[x]];
}
}
return Pixels;
}
//========================================================================== //==========================================================================
// //
// FFontChar2 :: FFontChar2 // FFontChar2 :: FFontChar2

View file

@ -1,21 +1,5 @@
// This is a font character that loads a texture and recolors it.
class FFontChar1 : public FImageSource
{
public:
FFontChar1 (FImageSource *sourcelump);
TArray<uint8_t> CreatePalettedPixels(int conversion) override;
void SetSourceRemap(const uint8_t *sourceremap) { SourceRemap = sourceremap; }
const uint8_t *ResetSourceRemap() { auto p = SourceRemap; SourceRemap = nullptr; return p; }
FImageSource *GetBase() const { return BaseTexture; }
protected:
FImageSource *BaseTexture;
const uint8_t *SourceRemap;
};
// This is a font character that reads RLE compressed data. // This is a font character that reads RLE compressed data.
class FFontChar2 : public FImageSource class FFontChar2 : public FImageSource
{ {

View file

@ -191,12 +191,7 @@ void UpdateStatusBar(SummaryInfo* info)
for (int i = 0; i < NumTextColors; i++) for (int i = 0; i < NumTextColors; i++)
{ {
FStringf buffer("This is font color %d", i); FStringf buffer("This is font color %d", i);
//DrawText(twod, SmallFont, i, 40, i * 15, buffer, DTA_FullscreenScale, FSMode_Fit640x400, TAG_DONE); DrawText(twod, BigFont, i, 340, i * 15, buffer, DTA_FullscreenScale, FSMode_Fit640x400, TAG_DONE);
//DrawText(twod, V_GetFont("doomfont"), i, 40, i * 15, buffer, DTA_FullscreenScale, FSMode_Fit640x400, TAG_DONE);
//DrawText(twod, NewSmallFont, i, 340, i * 15, buffer, DTA_FullscreenScale, FSMode_Fit640x400, TAG_DONE);
DrawText(twod, V_GetFont("condfont"), i, 40, i * 15, buffer, DTA_FullscreenScale, FSMode_Fit640x400, TAG_DONE);
DrawText(twod, NewConsoleFont, i, 340, i * 15, buffer, DTA_FullscreenScale, FSMode_Fit640x400, TAG_DONE);
} }
#endif #endif