- made adjustments to the text placement on the summary screen.

With extended fonts much of the old code did not work anymore, this needed more precise checks for the sources of the printed texts.

Without the adjustments, just added GetMaxAscender for compatibility. (drfrag)

# Conflicts:
#	src/gamedata/fonts/font.cpp
#	src/scripting/vmthunks.cpp
#	wadsrc/static/zscript/ui/statscreen/statscreen.zs
This commit is contained in:
Christoph Oelckers 2019-07-30 10:52:24 +02:00 committed by drfrag
parent 31b823a796
commit 070dde2e2b
4 changed files with 64 additions and 0 deletions

View file

@ -1947,6 +1947,19 @@ DEFINE_ACTION_FUNCTION_NATIVE(FFont, StringWidth, StringWidth)
ACTION_RETURN_INT(StringWidth(self, str));
}
static int GetMaxAscender(FFont* font, const FString& str)
{
const char* txt = str[0] == '$' ? GStrings(&str[1]) : str.GetChars();
return font->GetMaxAscender(txt);
}
DEFINE_ACTION_FUNCTION_NATIVE(FFont, GetMaxAscender, GetMaxAscender)
{
PARAM_SELF_STRUCT_PROLOGUE(FFont);
PARAM_STRING(str);
ACTION_RETURN_INT(GetMaxAscender(self, str));
}
static int CanPrint(FFont *font, const FString &str) // hack hack
{
return 1;

View file

@ -1807,6 +1807,53 @@ int FFont::StringWidth(const uint8_t *string) const
return MAX(maxw, w);
}
//==========================================================================
//
// Get the largest ascender in the first line of this text.
//
//==========================================================================
int FFont::GetMaxAscender(const uint8_t* string) const
{
int retval = 0;
while (*string)
{
auto chr = GetCharFromString(string);
if (chr == TEXTCOLOR_ESCAPE)
{
// We do not need to check for UTF-8 in here.
if (*string == '[')
{
while (*string != '\0' && *string != ']')
{
++string;
}
}
if (*string != '\0')
{
++string;
}
continue;
}
else if (chr == '\n')
{
break;
}
else
{
auto ctex = GetChar(chr, nullptr);
if (ctex)
{
auto offs = int(ctex->GetScaledTopOffset());
if (offs > retval) retval = offs;
}
}
}
return retval;
}
//==========================================================================
//
// FFont :: LoadTranslations

View file

@ -101,6 +101,9 @@ public:
int GetSpaceWidth () const { return SpaceWidth; }
int GetHeight () const { return FontHeight; }
int GetDefaultKerning () const { return GlobalKerning; }
int GetMaxAscender(const uint8_t* text) const;
int GetMaxAscender(const char* text) const { return GetMaxAscender((uint8_t*)text); }
int GetMaxAscender(const FString &text) const { return GetMaxAscender((uint8_t*)text.GetChars()); }
virtual void LoadTranslations();
void Preload() const;
FName GetName() const { return FontName; }

View file

@ -307,6 +307,7 @@ struct Font native
native int GetCharWidth(int code);
native int StringWidth(String code);
native int GetMaxAscender(String code);
native bool CanPrint(String code);
native int GetHeight();
int GetDisplacement() { return 0; } // hack hack