mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-01-31 12:30:32 +00:00
- Fixed loading of folder based fonts and added a config lump per font.
This is done by putting a font.inf file into the folder. Current options are "Kerning", "Scale", "FontHeight" and "SpaceWidth"
This commit is contained in:
parent
32f0e650fa
commit
ef050d700c
3 changed files with 103 additions and 36 deletions
|
@ -482,6 +482,10 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetScaledSize(int fitwidth, int fitheight);
|
void SetScaledSize(int fitwidth, int fitheight);
|
||||||
|
void SetScale(const DVector2 &scale)
|
||||||
|
{
|
||||||
|
Scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint16_t Width, Height;
|
uint16_t Width, Height;
|
||||||
|
|
|
@ -1315,7 +1315,7 @@ unsigned FWadCollection::GetLumpsInFolder(const char *inpath, TArray<FolderEntry
|
||||||
// Delete everything from older files.
|
// Delete everything from older files.
|
||||||
for (int i = result.Size() - 1; i >= 0; i--)
|
for (int i = result.Size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if ((int)result[i].lumpnum != maxfile) result.Delete(i);
|
if (Wads.GetLumpFile(result[i].lumpnum) != maxfile) result.Delete(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qsort(result.Data(), result.Size(), sizeof(FolderEntry), folderentrycmp);
|
qsort(result.Data(), result.Size(), sizeof(FolderEntry), folderentrycmp);
|
||||||
|
|
|
@ -1000,7 +1000,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname)
|
||||||
}
|
}
|
||||||
if (folderdata.Size() > 0)
|
if (folderdata.Size() > 0)
|
||||||
{
|
{
|
||||||
return new FFont(name, nullptr, path, HU_FONTSTART, HU_FONTSIZE, 1, -1);
|
return new FFont(name, nullptr, name, HU_FONTSTART, HU_FONTSIZE, 1, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return font;
|
return font;
|
||||||
|
@ -1020,7 +1020,8 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
||||||
FTextureID lump;
|
FTextureID lump;
|
||||||
char buffer[12];
|
char buffer[12];
|
||||||
int maxyoffs;
|
int maxyoffs;
|
||||||
bool doomtemplate = gameinfo.gametype & GAME_DoomChex ? strncmp (nametemplate, "STCFN", 5) == 0 : false;
|
bool doomtemplate = (nametemplate && (gameinfo.gametype & GAME_DoomChex)) ? strncmp (nametemplate, "STCFN", 5) == 0 : false;
|
||||||
|
DVector2 Scale = { 1, 1 };
|
||||||
|
|
||||||
noTranslate = notranslate;
|
noTranslate = notranslate;
|
||||||
Lump = fdlump;
|
Lump = fdlump;
|
||||||
|
@ -1031,6 +1032,8 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
||||||
FirstFont = this;
|
FirstFont = this;
|
||||||
Cursor = '_';
|
Cursor = '_';
|
||||||
ActiveColors = 0;
|
ActiveColors = 0;
|
||||||
|
SpaceWidth = 0;
|
||||||
|
FontHeight = 0;
|
||||||
uint8_t pp = 0;
|
uint8_t pp = 0;
|
||||||
for (auto &p : PatchRemap) p = pp++;
|
for (auto &p : PatchRemap) p = pp++;
|
||||||
translateUntranslated = false;
|
translateUntranslated = false;
|
||||||
|
@ -1040,6 +1043,66 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
||||||
TMap<int, FTexture*> charMap;
|
TMap<int, FTexture*> charMap;
|
||||||
int minchar = INT_MAX;
|
int minchar = INT_MAX;
|
||||||
int maxchar = INT_MIN;
|
int maxchar = INT_MIN;
|
||||||
|
|
||||||
|
// Read the font's configuration.
|
||||||
|
// This will not be done for the default fonts, because they are not atomic and the default content does not need it.
|
||||||
|
|
||||||
|
TArray<FolderEntry> folderdata;
|
||||||
|
if (filetemplate != nullptr)
|
||||||
|
{
|
||||||
|
FStringf path("fonts/%s/", filetemplate);
|
||||||
|
// If a name template is given, collect data from all resource files.
|
||||||
|
// For anything else, each folder is being treated as an atomic, self-contained unit and mixing from different glyph sets is blocked.
|
||||||
|
Wads.GetLumpsInFolder(path, folderdata, nametemplate == nullptr);
|
||||||
|
|
||||||
|
if (nametemplate == nullptr)
|
||||||
|
{
|
||||||
|
// Only take font.inf from the actual folder we are processing but not from an older folder that may have been superseded.
|
||||||
|
FStringf infpath("fonts/%s/font.inf", filetemplate);
|
||||||
|
|
||||||
|
unsigned index = folderdata.FindEx([=](const FolderEntry &entry)
|
||||||
|
{
|
||||||
|
return infpath.CompareNoCase(entry.name) == 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (index < folderdata.Size())
|
||||||
|
{
|
||||||
|
FScanner sc;
|
||||||
|
sc.OpenLumpNum(folderdata[index].lumpnum);
|
||||||
|
while (sc.GetToken())
|
||||||
|
{
|
||||||
|
sc.TokenMustBe(TK_Identifier);
|
||||||
|
if (sc.Compare("Kerning"))
|
||||||
|
{
|
||||||
|
sc.MustGetValue(false);
|
||||||
|
GlobalKerning = sc.Number;
|
||||||
|
}
|
||||||
|
else if (sc.Compare("Scale"))
|
||||||
|
{
|
||||||
|
sc.MustGetValue(true);
|
||||||
|
Scale.Y = Scale.X = sc.Float;
|
||||||
|
if (sc.CheckToken(','))
|
||||||
|
{
|
||||||
|
sc.MustGetValue(true);
|
||||||
|
Scale.Y = sc.Float;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sc.Compare("SpaceWidth"))
|
||||||
|
{
|
||||||
|
sc.MustGetValue(false);
|
||||||
|
SpaceWidth = sc.Number;
|
||||||
|
}
|
||||||
|
else if (sc.Compare("FontHeight"))
|
||||||
|
{
|
||||||
|
sc.MustGetValue(false);
|
||||||
|
FontHeight = sc.Number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (nametemplate != nullptr)
|
if (nametemplate != nullptr)
|
||||||
{
|
{
|
||||||
for (i = 0; i < lcount; i++)
|
for (i = 0; i < lcount; i++)
|
||||||
|
@ -1069,13 +1132,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (filetemplate != nullptr)
|
if (folderdata.Size() > 0)
|
||||||
{
|
|
||||||
TArray<FolderEntry> folderdata;
|
|
||||||
FStringf path("fonts/%s/", filetemplate);
|
|
||||||
// If a name template is given, collect data from all resource files.
|
|
||||||
// For anything else, each folder is being treated as an atomic, self-contained unit and mixing from different glyph sets is blocked.
|
|
||||||
if (Wads.GetLumpsInFolder(path, folderdata, nametemplate == nullptr))
|
|
||||||
{
|
{
|
||||||
// all valid lumps must be named with a hex number that represents its Unicode character index.
|
// all valid lumps must be named with a hex number that represents its Unicode character index.
|
||||||
for (auto &entry : folderdata)
|
for (auto &entry : folderdata)
|
||||||
|
@ -1090,8 +1147,9 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
||||||
{
|
{
|
||||||
if ((int)position < minchar) minchar = (int)position;
|
if ((int)position < minchar) minchar = (int)position;
|
||||||
if ((int)position > maxchar) maxchar = (int)position;
|
if ((int)position > maxchar) maxchar = (int)position;
|
||||||
charMap.Insert((int)position, TexMan.GetTexture(lump));
|
auto tex = TexMan.GetTexture(lump);
|
||||||
}
|
tex->SetScale(Scale);
|
||||||
|
charMap.Insert((int)position, tex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1101,6 +1159,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
||||||
LastChar = maxchar;
|
LastChar = maxchar;
|
||||||
auto count = maxchar - minchar + 1;
|
auto count = maxchar - minchar + 1;
|
||||||
Chars.Resize(count);
|
Chars.Resize(count);
|
||||||
|
int fontheight = 0;
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
|
@ -1118,9 +1177,9 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
||||||
maxyoffs = yoffs;
|
maxyoffs = yoffs;
|
||||||
}
|
}
|
||||||
height += abs(yoffs);
|
height += abs(yoffs);
|
||||||
if (height > FontHeight)
|
if (height > fontheight)
|
||||||
{
|
{
|
||||||
FontHeight = height;
|
fontheight = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1147,6 +1206,8 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SpaceWidth == 0) // An explicit override from the .inf file must always take precedence
|
||||||
|
{
|
||||||
if (spacewidth != -1)
|
if (spacewidth != -1)
|
||||||
{
|
{
|
||||||
SpaceWidth = spacewidth;
|
SpaceWidth = spacewidth;
|
||||||
|
@ -1159,6 +1220,8 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla
|
||||||
{
|
{
|
||||||
SpaceWidth = 4;
|
SpaceWidth = 4;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (FontHeight == 0) FontHeight = fontheight;
|
||||||
|
|
||||||
FixXMoves();
|
FixXMoves();
|
||||||
|
|
||||||
|
@ -2430,7 +2493,7 @@ void FFont::FixXMoves()
|
||||||
// Try an uppercase character.
|
// Try an uppercase character.
|
||||||
if (myislower(i + FirstChar))
|
if (myislower(i + FirstChar))
|
||||||
{
|
{
|
||||||
int upper = i - 32;
|
int upper = upperforlower[FirstChar + i];
|
||||||
if (upper >= 0)
|
if (upper >= 0)
|
||||||
{
|
{
|
||||||
Chars[i].XMove = Chars[upper].XMove;
|
Chars[i].XMove = Chars[upper].XMove;
|
||||||
|
|
Loading…
Reference in a new issue