Skip to content

Commit

Permalink
- added internationalized fonts.
Browse files Browse the repository at this point in the history
This still needs a bit of fixing and tweaking but most is working.
  • Loading branch information
coelckers committed May 31, 2021
1 parent cd56fd6 commit 42b70a7
Show file tree
Hide file tree
Showing 2,102 changed files with 382 additions and 231 deletions.
26 changes: 15 additions & 11 deletions source/common/fonts/font.cpp
Expand Up @@ -85,9 +85,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
Cursor = '_';
SpaceWidth = 0;
FontHeight = 0;
uint8_t pp = 0;
for (auto &p : PatchRemap) p = pp++;
translateUntranslated = false;
int FixedWidth = 0;

TMap<int, FGameTexture*> charMap;
Expand Down Expand Up @@ -126,6 +123,11 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
sc.MustGetValue(false);
GlobalKerning = sc.Number;
}
if (sc.Compare("Altfont"))
{
sc.MustGetString();
AltFontName = sc.String;
}
else if (sc.Compare("Scale"))
{
sc.MustGetValue(true);
Expand Down Expand Up @@ -154,6 +156,16 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
sc.MustGetValue(false);
FontHeight = sc.Number;
}
else if (sc.Compare("minluminosity"))
{
sc.MustGetValue(false);
MinLum = (int16_t)clamp(sc.Number, 0, 255);
}
else if (sc.Compare("maxluminosity"))
{
sc.MustGetValue(false);
MaxLum = (int16_t)clamp(sc.Number, 0, 255);
}
else if (sc.Compare("Translationtype"))
{
sc.MustGetToken(TK_Identifier);
Expand Down Expand Up @@ -302,7 +314,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
auto count = maxchar - minchar + 1;
Chars.Resize(count);
int fontheight = 0;
int asciiheight = 0;

for (i = 0; i < count; i++)
{
Expand All @@ -320,10 +331,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
{
fontheight = height;
}
if (height > asciiheight && FirstChar + 1 < 128)
{
asciiheight = height;
}
}

auto orig = pic->GetTexture();
Expand Down Expand Up @@ -359,7 +366,6 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
}
}
if (FontHeight == 0) FontHeight = fontheight;
if (AsciiHeight == 0) AsciiHeight = asciiheight;

FixXMoves();
}
Expand Down Expand Up @@ -1005,8 +1011,6 @@ FFont::FFont (int lump)
FontName = NAME_None;
Cursor = '_';
noTranslate = false;
uint8_t pp = 0;
for (auto &p : PatchRemap) p = pp++;
}

//==========================================================================
Expand Down
4 changes: 1 addition & 3 deletions source/common/fonts/hexfont.cpp
Expand Up @@ -292,8 +292,7 @@ class FHexFont : public FFont
FontHeight = 16;
SpaceWidth = 9;
GlobalKerning = 0;
translateUntranslated = true;


Chars.Resize(LastChar - FirstChar + 1);
for (int i = FirstChar; i <= LastChar; i++)
{
Expand Down Expand Up @@ -360,7 +359,6 @@ class FHexFont2 : public FFont
FontHeight = 18;
SpaceWidth = 9;
GlobalKerning = -1;
translateUntranslated = true;
Chars.Resize(LastChar - FirstChar + 1);
for (int i = FirstChar; i <= LastChar; i++)
{
Expand Down
1 change: 0 additions & 1 deletion source/common/fonts/singlelumpfont.cpp
Expand Up @@ -227,7 +227,6 @@ void FSingleLumpFont::LoadFON1 (int lump, const uint8_t *data)
FirstChar = 0;
LastChar = 255; // This is to allow LoadTranslations to function. The way this is all set up really needs to be changed.
GlobalKerning = 0;
translateUntranslated = true;
LastChar = 0x2122;

// Move the Windows-1252 characters to their proper place.
Expand Down
7 changes: 7 additions & 0 deletions source/common/fonts/v_font.cpp
Expand Up @@ -103,6 +103,13 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
if (font) return font;
}

// This is only temporary until virtual fonts get implemented
if (!stricmp(name, "BIGFONT"))
{
font = FFont::FindFont("BIGFONT15");
if (font) return font;
}

int lump = -1;
int folderfile = -1;

Expand Down
6 changes: 3 additions & 3 deletions source/common/fonts/v_font.h
Expand Up @@ -127,6 +127,7 @@ class FFont
char GetCursor() const { return Cursor; }
void SetCursor(char c) { Cursor = c; }
void SetKerning(int c) { GlobalKerning = c; }
void SetHeight(int c) { FontHeight = c; }
bool NoTranslate() const { return noTranslate; }
virtual void RecordAllTextureColors(uint32_t *usedcolors);
void CheckCase();
Expand All @@ -145,16 +146,16 @@ class FFont
void ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale);

EFontType Type = EFontType::Unknown;
FName AltFontName = NAME_None;
int FirstChar, LastChar;
int SpaceWidth;
int FontHeight;
int AsciiHeight = 0;
int GlobalKerning;
int TranslationType = 0;
int Displacement = 0;
int16_t MinLum = -1, MaxLum = -1;
char Cursor;
bool noTranslate = false;
bool translateUntranslated;
bool MixedCase = false;
bool forceremap = false;
struct CharData
Expand All @@ -164,7 +165,6 @@ class FFont
};
TArray<CharData> Chars;
TArray<int> Translations;
uint8_t PatchRemap[256];

int Lump;
FName FontName = NAME_None;
Expand Down
34 changes: 19 additions & 15 deletions source/games/blood/src/view.cpp
Expand Up @@ -59,11 +59,8 @@ int gScreenTilt;

FFont* DigiFont;

void FontSet(int id, int tile, int space)
FFont* FontSet(const char* name, int tile, int space)
{
if (id < 0 || id >= kFontNum || tile < 0 || tile >= kMaxTiles)
return;

GlyphSet glyphs;
for (int i = 1; i < 96; i++)
{
Expand All @@ -75,12 +72,14 @@ void FontSet(int id, int tile, int space)
}

}
const char *names[] = { "smallfont", "bigfont", "gothfont", "smallfont2", "digifont"};
const char *defs[] = { "defsmallfont", "defbigfont", nullptr, "defsmallfont2", nullptr};
FFont ** ptrs[] = { &SmallFont, &BigFont, nullptr, &SmallFont2, &DigiFont};
auto fnt = new ::FFont(names[id], nullptr, defs[id], 0, 0, 0, 0, tileWidth(tile), false, false, false, &glyphs);
fnt->SetKerning(space);
if (ptrs[id]) *ptrs[id] = fnt;
auto fnt = V_GetFont(name);
if (!fnt)
{
fnt = new ::FFont(name, nullptr, nullptr, 0, 0, 0, 0, tileWidth(tile), false, false, false, &glyphs);
fnt->SetKerning(space);

}
return fnt;
}

void viewBackupView(int nPlayer)
Expand Down Expand Up @@ -165,11 +164,16 @@ extern int dword_172CE0[16][3];
void viewInit(void)
{
Printf("Initializing status bar\n");
FontSet(0, 4096, 0);
FontSet(1, 4192, 1);
FontSet(2, 4288, 1);
FontSet(3, 4384, 1);
FontSet(4, 4480, 0);

FontSet("tilesmallfont", 4096, 0);
FontSet("tilebigfont", 4192, 1);
FontSet("gothfont", 4288, 1);
SmallFont2 = FontSet("smallfont2", 4384, 1);
DigiFont = FontSet("digifont", 4480, 0);

BigFont = V_GetFont("BIGFONT");
SmallFont = V_GetFont("SMALLFONT");


lensdata = fileSystem.LoadFile("lens.dat");
assert(lensdata.Size() == kLensSize * kLensSize * sizeof(int));
Expand Down
148 changes: 85 additions & 63 deletions source/games/duke/src/2d_d.cpp
Expand Up @@ -55,81 +55,103 @@ void InitFonts_d()
{
GlyphSet fontdata;

// Small font
for (int i = 0; i < 95; i++)
if (!V_GetFont("TileSmallFont"))
{
auto tile = tileGetTexture(STARTALPHANUM + i);
if (tile && tile->isValid() && tile->GetTexelWidth() > 0 && tile->GetTexelHeight() > 0)
// Small font
for (int i = 0; i < 95; i++)
{
if (i >= 'a' && i <= 'z' && tileEqualTo(i, i - 32)) continue;
fontdata.Insert('!' + i, tile);
tile->SetOffsetsNotForFont();
auto tile = tileGetTexture(STARTALPHANUM + i);
if (tile && tile->isValid() && tile->GetTexelWidth() > 0 && tile->GetTexelHeight() > 0)
{
if (i >= 'a' && i <= 'z' && tileEqualTo(i, i - 32)) continue;
fontdata.Insert('!' + i, tile);
tile->SetOffsetsNotForFont();
}
}
new ::FFont("TileSmallFont", nullptr, nullptr, 0, 0, 0, -1, 5, false, false, false, &fontdata);
fontdata.Clear();
}
SmallFont = new ::FFont("SmallFont", nullptr, "defsmallfont", 0, 0, 0, -1, 5, false, false, false, &fontdata);
fontdata.Clear();

// Big font

// This font is VERY messy...
fontdata.Insert('_', tileGetTexture(BIGALPHANUM - 11));
fontdata.Insert('-', tileGetTexture(BIGALPHANUM - 11));
for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, tileGetTexture(BIGALPHANUM - 10 + i));
for (int i = 0; i < 26; i++) fontdata.Insert('A' + i, tileGetTexture(BIGALPHANUM + i));
fontdata.Insert('.', tileGetTexture(BIGPERIOD));
fontdata.Insert(',', tileGetTexture(BIGCOMMA));
fontdata.Insert('!', tileGetTexture(BIGX));
fontdata.Insert('?', tileGetTexture(BIGQ));
fontdata.Insert(';', tileGetTexture(BIGSEMI));
fontdata.Insert(':', tileGetTexture(BIGCOLIN));
fontdata.Insert('\\', tileGetTexture(BIGALPHANUM + 68));
fontdata.Insert('/', tileGetTexture(BIGALPHANUM + 68));
fontdata.Insert('%', tileGetTexture(BIGALPHANUM + 69));
fontdata.Insert('`', tileGetTexture(BIGAPPOS));
fontdata.Insert('"', tileGetTexture(BIGAPPOS));
fontdata.Insert('\'', tileGetTexture(BIGAPPOS));
// The texture offsets in this font are useless for font printing. This should only apply to these glyphs, not for international extensions, though.
GlyphSet::Iterator it(fontdata);
GlyphSet::Pair* pair;
while (it.NextPair(pair)) pair->Value->SetOffsetsNotForFont();
BigFont = new ::FFont("BigFont", nullptr, "defbigfont", 0, 0, 0, -1, 5, false, false, false, &fontdata);
fontdata.Clear();

// Tiny font
for (int i = 0; i < 95; i++)
if (!V_GetFont("TileBigFont"))
{
auto tile = tileGetTexture(MINIFONT + i);
if (tile && tile->isValid() && tile->GetTexelWidth() > 0 && tile->GetTexelHeight() > 0)
// This font is VERY messy...
fontdata.Insert('_', tileGetTexture(BIGALPHANUM - 11));
fontdata.Insert('-', tileGetTexture(BIGALPHANUM - 11));
for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, tileGetTexture(BIGALPHANUM - 10 + i));
for (int i = 0; i < 26; i++) fontdata.Insert('A' + i, tileGetTexture(BIGALPHANUM + i));
fontdata.Insert('.', tileGetTexture(BIGPERIOD));
fontdata.Insert(',', tileGetTexture(BIGCOMMA));
fontdata.Insert('!', tileGetTexture(BIGX));
fontdata.Insert('?', tileGetTexture(BIGQ));
fontdata.Insert(';', tileGetTexture(BIGSEMI));
fontdata.Insert(':', tileGetTexture(BIGCOLIN));
fontdata.Insert('\\', tileGetTexture(BIGALPHANUM + 68));
fontdata.Insert('/', tileGetTexture(BIGALPHANUM + 68));
fontdata.Insert('%', tileGetTexture(BIGALPHANUM + 69));
fontdata.Insert('`', tileGetTexture(BIGAPPOS));
fontdata.Insert('"', tileGetTexture(BIGAPPOS));
fontdata.Insert('\'', tileGetTexture(BIGAPPOS));
// The texture offsets in this font are useless for font printing. This should only apply to these glyphs, not for international extensions, though.
GlyphSet::Iterator it(fontdata);
GlyphSet::Pair* pair;
while (it.NextPair(pair)) pair->Value->SetOffsetsNotForFont();
new ::FFont("TileBigFont", nullptr, nullptr, 0, 0, 0, -1, 5, false, false, false, &fontdata);
fontdata.Clear();
}

SmallFont2 = V_GetFont("SmallFont2");
if (!SmallFont2)
{
// Tiny font
for (int i = 0; i < 95; i++)
{
if (i >= 'a' && i <= 'z' && tileEqualTo(i, i - 32)) continue;
fontdata.Insert('!' + i, tile);
tile->SetOffsetsNotForFont();
auto tile = tileGetTexture(MINIFONT + i);
if (tile && tile->isValid() && tile->GetTexelWidth() > 0 && tile->GetTexelHeight() > 0)
{
if (i >= 'a' && i <= 'z' && tileEqualTo(i, i - 32)) continue;
fontdata.Insert('!' + i, tile);
tile->SetOffsetsNotForFont();
}
}
fontdata.Insert(1, TexMan.FindGameTexture("TINYBLAK")); // this is only here to widen the color range of the font to produce a better translation.
SmallFont2 = new ::FFont("SmallFont2", nullptr, nullptr, 0, 0, 0, -1, 3, false, false, false, &fontdata);
SmallFont2->SetKerning(1);
fontdata.Clear();
}

IndexFont = V_GetFont("IndexFont");
if (!IndexFont)
{
// SBAR index font
for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, tileGetTexture(THREEBYFIVE0 + i));
fontdata.Insert(':', tileGetTexture(THREEBYFIVE0 + 10));
fontdata.Insert('/', tileGetTexture(THREEBYFIVE0 + 11));
fontdata.Insert('%', tileGetTexture(MINIFONT + '%' - '!'));
fontdata.Insert(1, TexMan.FindGameTexture("TINYBLAK")); // this is only here to widen the color range of the font to produce a better translation.
GlyphSet::Iterator iti(fontdata);
GlyphSet::Pair* pair;
while (iti.NextPair(pair)) pair->Value->SetOffsetsNotForFont();
IndexFont = new ::FFont("IndexFont", nullptr, nullptr, 0, 0, 0, -1, -1, false, false, false, &fontdata);
fontdata.Clear();
}

DigiFont = V_GetFont("DigiFont");
if (!DigiFont)
{
// digital font
for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, tileGetTexture(DIGITALNUM + i));
fontdata.Insert(1, TexMan.FindGameTexture("TINYBLAK")); // this is only here to widen the color range of the font to produce a better translation.
GlyphSet::Iterator itd(fontdata);
GlyphSet::Pair* pair;
while (itd.NextPair(pair)) pair->Value->SetOffsetsNotForFont();
DigiFont = new ::FFont("DigiFont", nullptr, nullptr, 0, 0, 0, -1, -1, false, false, false, &fontdata);
}
fontdata.Insert(1, TexMan.FindGameTexture("TINYBLAK")); // this is only here to widen the color range of the font to produce a better translation.
SmallFont2 = new ::FFont("SmallFont2", nullptr, "defsmallfont2", 0, 0, 0, -1, 3, false, false, false, &fontdata);
SmallFont2->SetKerning(1);
fontdata.Clear();

// SBAR index font
for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, tileGetTexture(THREEBYFIVE0 + i));
fontdata.Insert(':', tileGetTexture(THREEBYFIVE0 + 10));
fontdata.Insert('/', tileGetTexture(THREEBYFIVE0 + 11));
fontdata.Insert('%', tileGetTexture(MINIFONT + '%' - '!'));
fontdata.Insert(1, TexMan.FindGameTexture("TINYBLAK")); // this is only here to widen the color range of the font to produce a better translation.
GlyphSet::Iterator iti(fontdata);
while (iti.NextPair(pair)) pair->Value->SetOffsetsNotForFont();
IndexFont = new ::FFont("IndexFont", nullptr, nullptr, 0, 0, 0, -1, -1, false, false, false, &fontdata);

fontdata.Clear();

// digital font
for (int i = 0; i < 10; i++) fontdata.Insert('0' + i, tileGetTexture(DIGITALNUM + i));
fontdata.Insert(1, TexMan.FindGameTexture("TINYBLAK")); // this is only here to widen the color range of the font to produce a better translation.
GlyphSet::Iterator itd(fontdata);
while (itd.NextPair(pair)) pair->Value->SetOffsetsNotForFont();
DigiFont = new ::FFont("DigiFont", nullptr, nullptr, 0, 0, 0, -1, -1, false, false, false, &fontdata);

// Todo: virtualize this;
BigFont = V_GetFont("BIGFONT");
SmallFont = V_GetFont("SMALLFONT");
}


Expand Down

0 comments on commit 42b70a7

Please sign in to comment.