void FFont::LoadTranslations() { unsigned int count = LastChar - FirstChar + 1; uint32_t usedcolors[256] = {}; uint8_t identity[256]; TArray<double> Luminosity; for (unsigned int i = 0; i < count; i++) { if (Chars[i].TranslatedPic) { FFontChar1 *pic = static_cast<FFontChar1 *>(Chars[i].TranslatedPic->GetImage()); if (pic) { pic->SetSourceRemap(nullptr); // Force the FFontChar1 to return the same pixels as the base texture RecordTextureColors(pic, usedcolors); } } } ActiveColors = SimpleTranslation (usedcolors, PatchRemap, identity, Luminosity); for (unsigned int i = 0; i < count; i++) { if(Chars[i].TranslatedPic) static_cast<FFontChar1 *>(Chars[i].TranslatedPic->GetImage())->SetSourceRemap(PatchRemap); } BuildTranslations (Luminosity.Data(), identity, &TranslationParms[TranslationType][0], ActiveColors, nullptr); }
void FFont::RecordAllTextureColors(uint32_t *usedcolors) { for (unsigned int i = 0; i < Chars.Size(); i++) { if (Chars[i].TranslatedPic) { FFontChar1 *pic = static_cast<FFontChar1 *>(Chars[i].TranslatedPic->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); } } } }
FFont::FFont (const char *name, const char *nametemplate, int first, int count, int start) { int i, lump; char buffer[12]; int *charlumps; BYTE usedcolors[256], identity[256]; double *luminosity; int maxyoffs; bool doomtemplate = gameinfo.gametype == GAME_Doom ? strncmp (nametemplate, "STCFN", 5) == 0 : false; Chars = new CharData[count]; charlumps = new int[count]; PatchRemap = new BYTE[256]; Ranges = NULL; FirstChar = first; LastChar = first + count - 1; FontHeight = 0; GlobalKerning = false; memset (usedcolors, 0, 256); Name = copystring (name); Next = FirstFont; FirstFont = this; maxyoffs = 0; for (i = 0; i < count; i++) { sprintf (buffer, nametemplate, i + start); lump = Wads.CheckNumForName (buffer, ns_graphics); if (doomtemplate && lump >= 0 && i + start == 121) { // HACKHACK: Don't load STCFN121 in doom(2), because // it's not really a lower-case 'y' but an upper-case 'I'. // Because a lot of wads with their own font seem to foolishly // copy STCFN121 and make it an 'I' themselves, wads must // provide STCFN120 (x) and STCFN122 (z) for STCFN121 to load. if (Wads.CheckNumForName ("STCFN120", ns_graphics) == -1 || Wads.CheckNumForName ("STCFN122", ns_graphics) == -1) { lump = -1; } } charlumps[i] = lump; if (lump >= 0) { FTexture *pic = TexMan[TexMan.AddPatch (buffer)]; int height = pic->GetScaledHeight(); int yoffs = pic->GetScaledTopOffset(); if (yoffs > maxyoffs) { maxyoffs = yoffs; } height += abs (yoffs); if (height > FontHeight) { FontHeight = height; } RecordTextureColors (pic, usedcolors); } } ActiveColors = SimpleTranslation (usedcolors, PatchRemap, identity, &luminosity); for (i = 0; i < count; i++) { if (charlumps[i] >= 0) { Chars[i].Pic = new FFontChar1 (charlumps[i], PatchRemap); } else { Chars[i].Pic = NULL; } } if ('N'-first>=0 && 'N'-first<count && Chars['N' - first].Pic) { SpaceWidth = (Chars['N' - first].Pic->GetScaledWidth() + 1) / 2; } else { SpaceWidth = 4; } BuildTranslations (luminosity, identity, &TranslationParms[0][0]); delete[] luminosity; delete[] charlumps; }