Skip to content

Commit

Permalink
Merge pull request #1227 from Daggolin/sp_fontfixes
Browse files Browse the repository at this point in the history
[SP] Font fixes
  • Loading branch information
Daggolin committed Apr 7, 2024
2 parents 065d329 + 3909676 commit 2815211
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 32 deletions.
2 changes: 2 additions & 0 deletions code/cgame/cg_local.h
Expand Up @@ -1231,4 +1231,6 @@ void CG_ClearLightStyles( void );
void CG_RunLightStyles( void );
void CG_SetLightstyle( int i );

int CG_MagicFontToReal( int menuFontIndex );

#endif //__CG_LOCAL_H__
39 changes: 38 additions & 1 deletion code/cgame/cg_main.cpp
Expand Up @@ -4353,13 +4353,50 @@ void CG_DrawDataPadForceSelect( void )
const float textScale = 1.0f;

CG_DisplayBoxedText(textboxXPos,textboxYPos,textboxWidth,textboxHeight,va("%s%s",text,text2),
4,
CG_MagicFontToReal(4),
textScale,
colorTable[CT_WHITE]
);
}
}

int CG_MagicFontToReal( int menuFontIndex )
{
// As the engine supports multiple renderers now we can no longer assume the
// order of fontindex values to be the same as it was on vanilla jasp with
// vanilla assets. Sadly the code uses magic numbers in various places that
// no longer match. This function tries to map these magic numbers to the
// fonts the would refer to on vanilla jasp with vanilla assets.

static int fonthandle_aurabesh;
static int fonthandle_ergoec;
static int fonthandle_anewhope;
static int fonthandle_arialnb;

static qboolean fontsRegistered = qfalse;

if ( !fontsRegistered )
{ // Only try registering the fonts once
fonthandle_aurabesh = cgi_R_RegisterFont( "aurabesh" );
fonthandle_ergoec = cgi_R_RegisterFont( "ergoec" );
fonthandle_anewhope = cgi_R_RegisterFont( "anewhope" );
fonthandle_arialnb = cgi_R_RegisterFont( "arialnb" );

fontsRegistered = qtrue;
}

// Default fonts from a clean installation
switch ( menuFontIndex ) {
case 1: return fonthandle_aurabesh;
case 2: return fonthandle_ergoec;
case 3: return fonthandle_anewhope;
case 4: return fonthandle_arialnb;

default:
return cgs.media.qhFontMedium;
}
}

// actually, these are pretty pointless so far in CHC, since in TA codebase they were used only so init some HUD
// function ptrs to allow cinematics in onscreen displays. So far, we don't use those, but here they are anyway...
//
Expand Down
2 changes: 1 addition & 1 deletion code/cgame/cg_weapons.cpp
Expand Up @@ -1685,7 +1685,7 @@ void CG_DrawDataPadWeaponSelect( void )
textboxXPos, textboxYPos,
textboxWidth, textboxHeight,
text,
4,
CG_MagicFontToReal(4),
textScale,
colorTable[CT_WHITE]
);
Expand Down
1 change: 1 addition & 0 deletions code/rd-common/tr_font.cpp
Expand Up @@ -1019,6 +1019,7 @@ CFontInfo::CFontInfo(const char *_fontName)
m_fAltSBCSFontScaleFactor = -1;
#endif
m_bIsFakeAlienLanguage = !strcmp(_fontName,"aurabesh"); // dont try and make SBCS or asian overrides for this
m_isVariant = qfalse;

len = ri.FS_ReadFile(fontName, NULL);
if (len == sizeof(dfontdat_t))
Expand Down
19 changes: 19 additions & 0 deletions code/ui/ui_atoms.cpp
Expand Up @@ -441,6 +441,9 @@ UI_RegisterFont
=================
*/

int registeredFontsCount = 0;
int registeredFonts[MAX_FONTS];

int UI_RegisterFont(const char *fontName)
{
int iFontIndex = ui.R_RegisterFont(fontName);
Expand All @@ -449,6 +452,22 @@ int UI_RegisterFont(const char *fontName)
iFontIndex = ui.R_RegisterFont("ergoec"); // fall back
}

// Store font
if ( iFontIndex )
{
int i;
for ( i = 0; i < registeredFontsCount; i++ )
{
if ( registeredFonts[i] == iFontIndex ) break;
}

if ( i == registeredFontsCount )
{ // It's not in the list: add it
if ( registeredFontsCount >= MAX_FONTS ) Com_Printf( "^3UI_RegisterFont: MAX_FONTS (%i) exceeded\n", MAX_FONTS );
else registeredFonts[registeredFontsCount++] = iFontIndex;
}
}

return iFontIndex;
}

4 changes: 4 additions & 0 deletions code/ui/ui_local.h
Expand Up @@ -246,4 +246,8 @@ void trap_S_StartLocalSound( sfxHandle_t sfx, int channelNum );

void _UI_Refresh( int realtime );

#define MAX_FONTS 64
extern int registeredFontsCount;
extern int registeredFonts[MAX_FONTS];

#endif
44 changes: 14 additions & 30 deletions code/ui/ui_shared.cpp
Expand Up @@ -352,7 +352,7 @@ qboolean MenuParse_font( itemDef_t *item)

if (!DC->Assets.fontRegistered)
{
DC->Assets.qhMediumFont = DC->registerFont(menu->font);
DC->Assets.qhMediumFont = UI_RegisterFont(menu->font);
DC->Assets.fontRegistered = qtrue;
}
return qtrue;
Expand Down Expand Up @@ -3072,35 +3072,19 @@ qboolean ItemParse_name( itemDef_t *item)
return qtrue;
}

int MenuFontToReal( int menuFontIndex )
int UI_MenuFontToReal( int menuFontIndex )
{
static int fonthandle_aurabesh;
static int fonthandle_ergoec;
static int fonthandle_anewhope;
static int fonthandle_arialnb;
// The font array starts at 0, but the valid font indexes start at 1. As the
// original menu files have direct font indexes we need to subtract 1 from
// the given index to get the correct index for our mapping array.
menuFontIndex--;

static qboolean fontsRegistered = qfalse;
// Make sure we don't go out of bound, fallback to medium font
if ( menuFontIndex < 0 || menuFontIndex >= registeredFontsCount )
return DC->Assets.qhMediumFont;

if ( !fontsRegistered )
{ // Only try registering the fonts once
fonthandle_aurabesh = UI_RegisterFont( "aurabesh" );
fonthandle_ergoec = UI_RegisterFont( "ergoec" );
fonthandle_anewhope = UI_RegisterFont( "anewhope" );
fonthandle_arialnb = UI_RegisterFont( "arialnb" );

fontsRegistered = qtrue;
}

// Default fonts from a clean installation
switch ( menuFontIndex ) {
case 1: return fonthandle_aurabesh;
case 2: return fonthandle_ergoec;
case 3: return fonthandle_anewhope;
case 4: return fonthandle_arialnb;

default:
return DC->Assets.qhMediumFont;
}
// Use the mapped index
return registeredFonts[menuFontIndex];
}

qboolean ItemParse_font( itemDef_t *item )
Expand All @@ -3111,7 +3095,7 @@ qboolean ItemParse_font( itemDef_t *item )
}

// Translate to real font
item->font = MenuFontToReal( item->font );
item->font = UI_MenuFontToReal( item->font );

return qtrue;
}
Expand Down Expand Up @@ -8294,7 +8278,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
while (1)
{
// FIXME - add some type of parameter in the menu file like descfont to specify the font for the descriptions for this menu.
textWidth = DC->textWidth(textPtr, fDescScale, MenuFontToReal(4)); // item->font);
textWidth = DC->textWidth(textPtr, fDescScale, UI_MenuFontToReal(4)); // item->font);

if (parent->descAlignment == ITEM_ALIGN_RIGHT)
{
Expand Down Expand Up @@ -8330,7 +8314,7 @@ static qboolean Item_Paint(itemDef_t *item, qboolean bDraw)
}

// FIXME - add some type of parameter in the menu file like descfont to specify the font for the descriptions for this menu.
DC->drawText(xPos, parent->descY + iYadj, fDescScale, parent->descColor, textPtr, 0, parent->descTextStyle, MenuFontToReal(4)); //item->font);
DC->drawText(xPos, parent->descY + iYadj, fDescScale, parent->descColor, textPtr, 0, parent->descTextStyle, UI_MenuFontToReal(4)); //item->font);
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions codemp/rd-common/tr_font.cpp
Expand Up @@ -882,6 +882,7 @@ CFontInfo::CFontInfo(const char *_fontName)
m_iOriginalFontWhenSBCSOverriden = -1;
m_fAltSBCSFontScaleFactor = -1;
m_bIsFakeAlienLanguage = !strcmp(_fontName,"aurabesh"); // dont try and make SBCS or asian overrides for this
m_isVariant = qfalse;

len = ri.FS_ReadFile(fontName, NULL);
if (len == sizeof(dfontdat_t))
Expand Down

0 comments on commit 2815211

Please sign in to comment.