From 22be26bd2d4c1842ac8343b1ca1b7faf66371060 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 28 May 2021 12:16:07 +0200 Subject: [PATCH] - font system fixes. --- source/common/fonts/font.cpp | 4 ++++ source/common/fonts/specialfont.cpp | 11 +++++++++++ source/common/fonts/v_font.cpp | 7 +++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/source/common/fonts/font.cpp b/source/common/fonts/font.cpp index 8421ab92b..6458836f9 100644 --- a/source/common/fonts/font.cpp +++ b/source/common/fonts/font.cpp @@ -656,6 +656,10 @@ int FFont::GetLuminosity (uint32_t *colorsused, TArray &Luminosity, int* int FFont::GetColorTranslation (EColorRange range, PalEntry *color) const { + // Single pic fonts do not set up their translation table and must always return 0. + if (Translations.Size() == 0) return 0; + assert(Translations.Size() == NumTextColors); + if (noTranslate) { PalEntry retcolor = PalEntry(255, 255, 255, 255); diff --git a/source/common/fonts/specialfont.cpp b/source/common/fonts/specialfont.cpp index 6ceb38b15..22d43187b 100644 --- a/source/common/fonts/specialfont.cpp +++ b/source/common/fonts/specialfont.cpp @@ -141,6 +141,17 @@ void FSpecialFont::LoadTranslations() { FFont::LoadTranslations(); + bool empty = true; + for (auto& c : Chars) + { + if (c.OriginalPic != nullptr) + { + empty = false; + break; + } + } + if (empty) return; // Font has no characters. + bool needsnotrans = false; // exclude the non-translated colors from the translation calculation for (int i = 0; i < 256; i++) diff --git a/source/common/fonts/v_font.cpp b/source/common/fonts/v_font.cpp index 280fd5856..8313b18e5 100644 --- a/source/common/fonts/v_font.cpp +++ b/source/common/fonts/v_font.cpp @@ -714,13 +714,16 @@ static void CalcDefaultTranslation(FFont* base, int index) { int index = int(lum * 255); remap[index] = GPalette.BaseColors[i]; + remap[index].a = 255; } } // todo: fill the gaps. - remap[0] = 0; + //remap[0] = 0; int lowindex = 0; - int highindex = 1; + while (lowindex < 255 && remap[lowindex].a == 0) lowindex++; + lowindex++; + int highindex = lowindex + 1; while (lowindex < 255) {