From 8b1757eee2c32c1250ef71251b81c536a7bb281f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 24 May 2021 19:27:07 +0200 Subject: [PATCH] - 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. --- source/common/2d/v_drawtext.cpp | 15 +++--- source/common/fonts/font.cpp | 57 ++++---------------- source/common/fonts/hexfont.cpp | 10 ++-- source/common/fonts/singlelumpfont.cpp | 18 +++---- source/common/fonts/singlepicfont.cpp | 5 +- source/common/fonts/specialfont.cpp | 16 ++---- source/common/fonts/v_font.h | 5 +- source/common/textures/formats/fontchars.cpp | 42 --------------- source/common/textures/formats/fontchars.h | 16 ------ source/core/statusbar2.cpp | 7 +-- 10 files changed, 36 insertions(+), 155 deletions(-) diff --git a/source/common/2d/v_drawtext.cpp b/source/common/2d/v_drawtext.cpp index 9a778eb13..97d418fd7 100644 --- a/source/common/2d/v_drawtext.cpp +++ b/source/common/2d/v_drawtext.cpp @@ -173,9 +173,8 @@ void DrawChar(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double FGameTexture* pic; int dummy; - bool redirected; - if (NULL != (pic = font->GetChar(character, normalcolor, &dummy, &redirected))) + if (NULL != (pic = font->GetChar(character, normalcolor, &dummy))) { DrawParms parms; 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); 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); drawer->AddTexture(pic, parms); } @@ -204,9 +203,8 @@ void DrawChar(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double FGameTexture *pic; int dummy; - bool redirected; - if (NULL != (pic = font->GetChar(character, normalcolor, &dummy, &redirected))) + if (NULL != (pic = font->GetChar(character, normalcolor, &dummy))) { DrawParms parms; uint32_t tag = ListGetInt(args); @@ -214,7 +212,7 @@ void DrawChar(F2DDrawer *drawer, FFont *font, int normalcolor, double x, double if (!res) return; bool palettetrans = (normalcolor == CR_UNDEFINED && parms.TranslationId != 0); 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); drawer->AddTexture(pic, parms); } @@ -316,11 +314,10 @@ void DrawTextCommon(F2DDrawer *drawer, FFont *font, int normalcolor, double x, d continue; } - bool redirected = false; - if (NULL != (pic = font->GetChar(c, currentcolor, &w, &redirected))) + if (NULL != (pic = font->GetChar(c, currentcolor, &w))) { // 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); if (parms.cellx) { diff --git a/source/common/fonts/font.cpp b/source/common/fonts/font.cpp index 2f1016b19..e4ae656cf 100644 --- a/source/common/fonts/font.cpp +++ b/source/common/fonts/font.cpp @@ -333,23 +333,13 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla TexMan.AddGameTexture(tex); Chars[i].OriginalPic = tex; - if (!noTranslate) - { - 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); + if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].OriginalPic); - Chars[i].XMove = (int)Chars[i].TranslatedPic->GetDisplayWidth(); + Chars[i].XMove = (int)Chars[i].OriginalPic->GetDisplayWidth(); } else { - Chars[i].TranslatedPic = nullptr; + Chars[i].OriginalPic = nullptr; Chars[i].XMove = INT_MIN; } } @@ -360,7 +350,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla { 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; } @@ -444,11 +434,7 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height Chars[i].OriginalPic = (*lump)->GetUseType() == ETextureType::FontChar? (*lump) : MakeGameTexture(pic, nullptr, ETextureType::FontChar); Chars[i].OriginalPic->SetUseType(ETextureType::FontChar); 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); - TexMan.AddGameTexture(Chars[i].TranslatedPic); } Chars[i].XMove = width; } @@ -596,16 +582,10 @@ void FFont::RecordAllTextureColors(uint32_t *usedcolors) { for (unsigned int i = 0; i < Chars.Size(); i++) { - if (Chars[i].TranslatedPic) + if (Chars[i].OriginalPic) { - FFontChar1 *pic = static_cast(Chars[i].TranslatedPic->GetTexture()->GetImage()); - if (pic) - { - // 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); - } + auto pic = Chars[i].OriginalPic->GetTexture()->GetImage(); + if (pic) RecordTextureColors(pic, usedcolors); } } } @@ -772,7 +752,6 @@ int FFont::GetColorTranslation (EColorRange range, PalEntry *color) const return -1; else if (range >= NumTextColors) range = CR_UNTRANSLATED; - //if (range == CR_UNTRANSLATED && !translateUntranslated) return nullptr; 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); int xmove = SpaceWidth; @@ -885,24 +864,8 @@ FGameTexture *FFont::GetChar (int code, int translation, int *const width, bool 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); - 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; + assert(Chars[code].OriginalPic->GetUseType() == ETextureType::FontChar); + return Chars[code].OriginalPic; } //========================================================================== diff --git a/source/common/fonts/hexfont.cpp b/source/common/fonts/hexfont.cpp index 3912de8d0..9dd7738c4 100644 --- a/source/common/fonts/hexfont.cpp +++ b/source/common/fonts/hexfont.cpp @@ -301,10 +301,9 @@ public: { auto offset = hexdata.glyphmap[i]; 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 = Chars[i - FirstChar].TranslatedPic; + Chars[i - FirstChar].OriginalPic = MakeGameTexture(new FImageTexture(new FHexFontChar(&hexdata.glyphdata[offset + 1], size, size * 9, 16)), nullptr, ETextureType::FontChar); Chars[i - FirstChar].XMove = size * spacing; - TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); + TexMan.AddGameTexture(Chars[i - FirstChar].OriginalPic); } else Chars[i - FirstChar].XMove = spacing; @@ -369,10 +368,9 @@ public: { auto offset = hexdata.glyphmap[i]; 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 = Chars[i - FirstChar].TranslatedPic; + Chars[i - FirstChar].OriginalPic = MakeGameTexture(new FImageTexture(new FHexFontChar2(&hexdata.glyphdata[offset + 1], size, 2 + size * 8, 18)), nullptr, ETextureType::FontChar); Chars[i - FirstChar].XMove = size * spacing; - TexMan.AddGameTexture(Chars[i - FirstChar].TranslatedPic); + TexMan.AddGameTexture(Chars[i - FirstChar].OriginalPic); } else Chars[i - FirstChar].XMove = spacing; diff --git a/source/common/fonts/singlelumpfont.cpp b/source/common/fonts/singlelumpfont.cpp index 56b2b7f14..ce5bb19fc 100644 --- a/source/common/fonts/singlelumpfont.cpp +++ b/source/common/fonts/singlelumpfont.cpp @@ -188,8 +188,8 @@ void FSingleLumpFont::LoadTranslations() for(unsigned int i = 0;i < count;++i) { - if(Chars[i].TranslatedPic) - static_cast(Chars[i].TranslatedPic->GetTexture()->GetImage())->SetSourceRemap(Palette); + if(Chars[i].OriginalPic) + static_cast(Chars[i].OriginalPic->GetTexture()->GetImage())->SetSourceRemap(Palette); } Translations.Resize(NumTextColors); @@ -325,14 +325,12 @@ void FSingleLumpFont::LoadFON2 (int lump, const uint8_t *data) Chars[i].XMove = widths2[i]; if (destSize <= 0) { - Chars[i].TranslatedPic = nullptr; Chars[i].OriginalPic = nullptr; } else { - Chars[i].TranslatedPic = 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].TranslatedPic); + Chars[i].OriginalPic = MakeGameTexture(new FImageTexture(new FFontChar2 (lump, int(data_p - data), widths2[i], FontHeight)), nullptr, ETextureType::FontChar); + TexMan.AddGameTexture(Chars[i].OriginalPic); do { 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+4] // y offset )), nullptr, ETextureType::FontChar); - Chars[chardata[chari] - FirstChar].TranslatedPic = tex; Chars[chardata[chari] - FirstChar].OriginalPic = tex; TexMan.AddGameTexture(tex); } @@ -488,12 +485,11 @@ void FSingleLumpFont::CheckFON1Chars() { 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 = Chars[i].TranslatedPic; + Chars[i].OriginalPic = MakeGameTexture(new FImageTexture(new FFontChar2(Lump, int(data_p - data), SpaceWidth, FontHeight)), nullptr, ETextureType::FontChar); 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. diff --git a/source/common/fonts/singlepicfont.cpp b/source/common/fonts/singlepicfont.cpp index aefede946..17dfd2691 100644 --- a/source/common/fonts/singlepicfont.cpp +++ b/source/common/fonts/singlepicfont.cpp @@ -45,7 +45,7 @@ public: FSinglePicFont(const char *picname); // 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; 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; - if (redirected) *redirected = false; if (code == 'a' || code == 'A') { return TexMan.GetGameTexture(PicNum, true); diff --git a/source/common/fonts/specialfont.cpp b/source/common/fonts/specialfont.cpp index f5ddba1e7..a8c4d7157 100644 --- a/source/common/fonts/specialfont.cpp +++ b/source/common/fonts/specialfont.cpp @@ -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->CopySize(pic, true); TexMan.AddGameTexture(Chars[i].OriginalPic); - - if (!noTranslate) - { - 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); + Chars[i].XMove = (int)Chars[i].OriginalPic->GetDisplayWidth(); + if (sysCallbacks.FontCharCreated) sysCallbacks.FontCharCreated(pic, Chars[i].OriginalPic, Chars[i].OriginalPic); } else { - Chars[i].TranslatedPic = nullptr; + Chars[i].OriginalPic = nullptr; Chars[i].XMove = INT_MIN; } } // 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; } diff --git a/source/common/fonts/v_font.h b/source/common/fonts/v_font.h index 222e82748..f90b3e593 100644 --- a/source/common/fonts/v_font.h +++ b/source/common/fonts/v_font.h @@ -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); 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; int GetColorTranslation (EColorRange range, PalEntry *color = nullptr) const; int GetLump() const { return Lump; } @@ -159,8 +159,7 @@ protected: bool forceremap = false; struct CharData { - FGameTexture *TranslatedPic = nullptr; // Texture for use with font translations. - FGameTexture *OriginalPic = nullptr; // Texture for use with CR_UNTRANSLATED or font colorization. + FGameTexture *OriginalPic = nullptr; int XMove = INT_MIN; }; TArray Chars; diff --git a/source/common/textures/formats/fontchars.cpp b/source/common/textures/formats/fontchars.cpp index a4aa9e55e..44a72ca6e 100644 --- a/source/common/textures/formats/fontchars.cpp +++ b/source/common/textures/formats/fontchars.cpp @@ -41,48 +41,6 @@ #include "fontchars.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 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 diff --git a/source/common/textures/formats/fontchars.h b/source/common/textures/formats/fontchars.h index 3562b0e7a..79baf4a2b 100644 --- a/source/common/textures/formats/fontchars.h +++ b/source/common/textures/formats/fontchars.h @@ -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 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. class FFontChar2 : public FImageSource { diff --git a/source/core/statusbar2.cpp b/source/core/statusbar2.cpp index 6c4c6eb29..9f9fb6b57 100644 --- a/source/core/statusbar2.cpp +++ b/source/core/statusbar2.cpp @@ -191,12 +191,7 @@ void UpdateStatusBar(SummaryInfo* info) for (int i = 0; i < NumTextColors; 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, 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); + DrawText(twod, BigFont, i, 340, i * 15, buffer, DTA_FullscreenScale, FSMode_Fit640x400, TAG_DONE); } #endif