- refinement of font substitution logic.

This commit is contained in:
Christoph Oelckers 2019-04-22 10:23:28 +02:00
parent e6ab678515
commit 6f3982865f
10 changed files with 20 additions and 22 deletions

View file

@ -581,11 +581,6 @@ CUSTOM_CVAR (Int, msgmidcolor2, 4, CVAR_ARCHIVE)
setmsgcolor (PRINTLEVELS+1, self);
}
EColorRange C_GetDefaultFontColor()
{
return CR_UNTRANSLATED;
}
FFont * C_GetDefaultHUDFont()
{
return generic_ui? NewSmallFont : SmallFont;

View file

@ -197,7 +197,14 @@ DHUDMessage::DHUDMessage (FFont *font, const char *text, float x, float y, int h
Top = y;
HoldTics = (int)(holdTime * TICRATE);
Tics = -1; // -1 to compensate for one additional Tick the message will receive.
Font = font? font : generic_ui? NewSmallFont : AlternativeSmallFont;
// Try to find the optimal font if none is specified. Prefer SmallFont, but if that cannot handle this text use the IWAD's SmallFont and if that doesn't work either, use the VGA font.
if (font) Font = font;
else if (generic_ui) Font = NewSmallFont;
else if (SmallFont->CanPrint(text)) Font = SmallFont;
else if (OriginalSmallFont->CanPrint(text)) Font = OriginalSmallFont;
else Font = NewSmallFont;
TextColor = textColor;
State = 0;
SourceText = copystring (text);

View file

@ -609,6 +609,7 @@ void DBaseStatusBar::DoDrawAutomapHUD(int crdefault, int highlight)
if (!generic_ui)
{
// If the original font does not have accents this will strip them - but a fallback to the VGA font is not desirable here for such cases.
if (!font->CanPrint(GStrings("AM_MONSTERS")) || !font->CanPrint(GStrings("AM_SECRETS")) || !font->CanPrint(GStrings("AM_ITEMS"))) font2 = OriginalSmallFont;
}

View file

@ -1019,6 +1019,7 @@ double GetBottomAlignOffset(FFont *font, int c)
bool FFont::CanPrint(const uint8_t *string) const
{
if (!string) return true;
while (*string)
{
auto chr = GetCharFromString(string);
@ -1042,7 +1043,7 @@ bool FFont::CanPrint(const uint8_t *string) const
else if (chr != '\n')
{
int cc = GetCharCode(chr, true);
if (chr != cc)
if (chr != cc && iswalpha(chr))
{
return false;
}

View file

@ -1601,6 +1601,10 @@ void V_InitFonts()
{
BigFont = NewSmallFont;
}
if (OriginalSmallFont == nullptr)
{
OriginalSmallFont = SmallFont;
}
AlternativeSmallFont = OriginalSmallFont;
UpdateGenericUI(false);
}

View file

@ -183,7 +183,6 @@ EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int
FFont *V_GetFont(const char *fontname, const char *fontlumpname = nullptr);
void V_InitFontColors();
EColorRange C_GetDefaultFontColor();
FFont * C_GetDefaultHUDFont();

View file

@ -181,10 +181,6 @@ void DFrameBuffer::DrawChar (FFont *font, int normalcolor, double x, double y, i
int dummy;
bool redirected;
// Workaround until this can be automated.
if (font == NewSmallFont && normalcolor == CR_UNTRANSLATED)
normalcolor = C_GetDefaultFontColor();
if (NULL != (pic = font->GetChar (character, normalcolor, &dummy, &redirected)))
{
DrawParms parms;
@ -215,11 +211,6 @@ void DFrameBuffer::DrawChar(FFont *font, int normalcolor, double x, double y, in
int dummy;
bool redirected;
// Workaround until this can be automated.
if (font == NewSmallFont && normalcolor == CR_UNTRANSLATED)
normalcolor = C_GetDefaultFontColor();
if (NULL != (pic = font->GetChar(character, normalcolor, &dummy, &redirected)))
{
DrawParms parms;
@ -274,10 +265,6 @@ void DFrameBuffer::DrawTextCommon(FFont *font, int normalcolor, double x, double
int kerning;
FTexture *pic;
// Workaround until this can be automated.
if (font == NewSmallFont && normalcolor == CR_UNTRANSLATED)
normalcolor = C_GetDefaultFontColor();
if (parms.celly == 0) parms.celly = font->GetHeight() + 1;
parms.celly *= parms.scaley;

View file

@ -914,6 +914,7 @@ DEFINE_GLOBAL(ConFont)
DEFINE_GLOBAL(NewConsoleFont)
DEFINE_GLOBAL(NewSmallFont)
DEFINE_GLOBAL(AlternativeSmallFont)
DEFINE_GLOBAL(OriginalSmallFont)
DEFINE_GLOBAL(IntermissionFont)
DEFINE_GLOBAL(CleanXfac)
DEFINE_GLOBAL(CleanYfac)

View file

@ -25,6 +25,7 @@ struct _ native // These are the global variables, the struct is only here to av
native readonly Font NewConsoleFont;
native readonly Font NewSmallFont;
native readonly Font AlternativeSmallFont;
native readonly Font OriginalSmallFont;
native readonly Font intermissionfont;
native readonly int CleanXFac;
native readonly int CleanYFac;

View file

@ -62,7 +62,7 @@ class MessageBoxMenu : Menu
mMouseLeft = 140;
mMouseY = 0x80000000;
if (generic_ui)
//if (generic_ui)
{
arrowFont = textFont = NewSmallFont;
int factor = (CleanXfac+1) / 2;
@ -70,6 +70,7 @@ class MessageBoxMenu : Menu
destHeight = screen.GetHeight() / factor;
selector = "▶";
}
/*
else
{
textFont = AlternativeSmallFont;
@ -78,6 +79,7 @@ class MessageBoxMenu : Menu
destHeight = CleanHeight;
selector = "\xd";
}
*/
int mr1 = destWidth/2 + 10 + textFont.StringWidth(Stringtable.Localize("$TXT_YES"));
int mr2 = destWidth/2 + 10 + textFont.StringWidth(Stringtable.Localize("$TXT_NO"));