- a few more exports from FFont.

This commit is contained in:
Christoph Oelckers 2017-02-05 13:55:05 +01:00
parent ef871ec09f
commit d8a1ce88b0
4 changed files with 70 additions and 53 deletions

View file

@ -94,6 +94,7 @@ The FON2 header is followed by variable length data:
#include "r_data/r_translate.h" #include "r_data/r_translate.h"
#include "colormatcher.h" #include "colormatcher.h"
#include "v_palette.h" #include "v_palette.h"
#include "v_text.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
@ -845,6 +846,65 @@ int FFont::GetCharWidth (int code) const
return (code < 0) ? SpaceWidth : Chars[code - FirstChar].XMove; return (code < 0) ? SpaceWidth : Chars[code - FirstChar].XMove;
} }
DEFINE_ACTION_FUNCTION(FFont, GetCharWidth)
{
PARAM_SELF_STRUCT_PROLOGUE(FFont);
PARAM_INT(code);
ACTION_RETURN_INT(self->GetCharWidth(code));
}
//==========================================================================
//
// Find string width using this font
//
//==========================================================================
int FFont::StringWidth(const BYTE *string) const
{
int w = 0;
int maxw = 0;
while (*string)
{
if (*string == TEXTCOLOR_ESCAPE)
{
++string;
if (*string == '[')
{
while (*string != '\0' && *string != ']')
{
++string;
}
}
if (*string != '\0')
{
++string;
}
continue;
}
else if (*string == '\n')
{
if (w > maxw)
maxw = w;
w = 0;
++string;
}
else
{
w += GetCharWidth(*string++) + GlobalKerning;
}
}
return MAX(maxw, w);
}
DEFINE_ACTION_FUNCTION(FFont, StringWidth)
{
PARAM_SELF_STRUCT_PROLOGUE(FFont);
PARAM_STRING(str);
ACTION_RETURN_INT(self->StringWidth(str));
}
//========================================================================== //==========================================================================
// //
// FFont :: LoadTranslations // FFont :: LoadTranslations
@ -2492,6 +2552,13 @@ EColorRange V_FindFontColor (FName name)
return CR_UNTRANSLATED; return CR_UNTRANSLATED;
} }
DEFINE_ACTION_FUNCTION(FFont, FindFontColor)
{
PARAM_SELF_STRUCT_PROLOGUE(FFont);
PARAM_NAME(code);
ACTION_RETURN_INT((int)V_FindFontColor(code));
}
//========================================================================== //==========================================================================
// //
// V_LogColorFromColorRange // V_LogColorFromColorRange
@ -2666,12 +2733,3 @@ void V_ClearFonts()
SmallFont = SmallFont2 = BigFont = ConFont = IntermissionFont = NULL; SmallFont = SmallFont2 = BigFont = ConFont = IntermissionFont = NULL;
} }
void V_RetranslateFonts()
{
FFont *font = FFont::FirstFont;
while(font)
{
font->LoadTranslations();
font = font->Next;
}
}

View file

@ -134,7 +134,6 @@ protected:
friend struct FontsDeleter; friend struct FontsDeleter;
friend void V_ClearFonts(); friend void V_ClearFonts();
friend void V_RetranslateFonts();
}; };
@ -147,6 +146,5 @@ PalEntry V_LogColorFromColorRange (EColorRange range);
EColorRange V_ParseFontColor (const BYTE *&color_value, int normalcolor, int boldcolor); EColorRange V_ParseFontColor (const BYTE *&color_value, int normalcolor, int boldcolor);
FFont *V_GetFont(const char *); FFont *V_GetFont(const char *);
void V_InitFontColors(); void V_InitFontColors();
void V_RetranslateFonts();
#endif //__V_FONT_H__ #endif //__V_FONT_H__

View file

@ -167,48 +167,6 @@ void DCanvas::DrawText(FFont *font, int normalcolor, int x, int y, const char *s
} }
//
// Find string width using this font
//
int FFont::StringWidth (const BYTE *string) const
{
int w = 0;
int maxw = 0;
while (*string)
{
if (*string == TEXTCOLOR_ESCAPE)
{
++string;
if (*string == '[')
{
while (*string != '\0' && *string != ']')
{
++string;
}
}
if (*string != '\0')
{
++string;
}
continue;
}
else if (*string == '\n')
{
if (w > maxw)
maxw = w;
w = 0;
++string;
}
else
{
w += GetCharWidth (*string++) + GlobalKerning;
}
}
return MAX (maxw, w);
}
// //
// Break long lines of text into multiple lines no longer than maxwidth pixels // Break long lines of text into multiple lines no longer than maxwidth pixels
// //

View file

@ -70,6 +70,9 @@ struct Screen native
struct Font native struct Font native
{ {
native int GetCharWidth(int code);
native int StringWidth(String code);
native static int FindFontColor(Name color);
native static Font FindFont(Name fontname); native static Font FindFont(Name fontname);
native static Font GetFont(Name fontname); native static Font GetFont(Name fontname);
} }