Skip to content

Commit 6d7ab7d

Browse files
committed
Embed Unifont OTF and use it by default
unifont-17.0.01.otf TODO add license use OTF because: - smaller - unifont stopped releasing TTF embedded font used when cl_consoleFont is the empty string (the new default)
1 parent 483faf8 commit 6d7ab7d

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,15 @@ if (BUILD_CLIENT)
10701070
string(APPEND SHADERS_CPP_TEXT "};\n")
10711071

10721072
daemon_write_generated("shaders.cpp" "${SHADERS_CPP_TEXT}")
1073+
1074+
add_custom_command(
1075+
OUTPUT ${EMBED_INCLUDE_DIR}/daemon_unifont.h
1076+
COMMAND ${CMAKE_COMMAND} "-DINPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/libs/unifont/unifont.otf" "-DOUTPUT_FILE=${EMBED_INCLUDE_DIR}/daemon_unifont.h"
1077+
-DTEXT_MODE=0 -DVARIABLE_NAME=daemon_unifont_bin -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/EmbedText.cmake
1078+
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/libs/unifont/unifont.otf
1079+
)
1080+
set_property(TARGET client-objects APPEND PROPERTY SOURCES ${EMBED_INCLUDE_DIR}/daemon_unifont.h)
1081+
include_directories(${EMBED_INCLUDE_DIR})
10731082
endif()
10741083

10751084
if (BUILD_SERVER)

libs/unifont/unifont.otf

5.07 MB
Binary file not shown.

src/engine/client/cl_main.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,42 +2104,32 @@ bool CL_InitRenderer()
21042104
return false;
21052105
}
21062106

2107-
cl_consoleFont = Cvar_Get( "cl_consoleFont", "fonts/unifont.ttf", CVAR_LATCH );
2107+
cl_consoleFont = Cvar_Get( "cl_consoleFont", "", CVAR_LATCH );
21082108
cl_consoleFontSize = Cvar_Get( "cl_consoleFontSize", "16", CVAR_LATCH );
21092109
cl_consoleFontScaling = Cvar_Get( "cl_consoleFontScaling", "1", CVAR_LATCH );
21102110

21112111
// load character sets
21122112
cls.charSetShader = re.RegisterShader( "gfx/2d/bigchars", RSF_2D );
21132113
cls.useLegacyConsoleFont = cls.useLegacyConsoleFace = true;
21142114

2115-
// Register console font specified by cl_consoleFont, if any
2116-
// filehandle is unused but forces FS_FOpenFileRead() to heed purecheck because it does not when filehandle is nullptr
2117-
if ( cl_consoleFont->string[0] )
2118-
{
2119-
if ( FS_FOpenFileRead( cl_consoleFont->string, &f ) >= 0 )
2120-
{
2121-
if ( cl_consoleFontScaling->value == 0 )
2122-
{
2123-
cls.consoleFont = re.RegisterFont( cl_consoleFont->string, cl_consoleFontSize->integer );
2124-
}
2125-
else
2126-
{
2127-
// This gets 12px on 1920×1080 screen, which is libRocket default for 1em
2128-
int fontScale = std::min(cls.windowConfig.vidWidth, cls.windowConfig.vidHeight) / 90;
2115+
// Register console font specified by cl_consoleFont. Empty string means use the embbed Unifont
21292116

2130-
// fontScale / 12px gets 1px on 1920×1080 screen
2131-
cls.consoleFont = re.RegisterFont( cl_consoleFont->string, cl_consoleFontSize->integer * fontScale / 12 );
2132-
}
2117+
if ( cl_consoleFontScaling->value == 0 )
2118+
{
2119+
cls.consoleFont = re.RegisterFont( cl_consoleFont->string, cl_consoleFontSize->integer );
2120+
}
2121+
else
2122+
{
2123+
// This gets 12px on 1920×1080 screen, which is libRocket default for 1em
2124+
int fontScale = std::min(cls.windowConfig.vidWidth, cls.windowConfig.vidHeight) / 90;
21332125

2134-
if ( cls.consoleFont != nullptr )
2135-
cls.useLegacyConsoleFont = false;
2136-
}
2137-
else
2138-
{
2139-
Log::Warn("Font file '%s' not found", cl_consoleFont->string);
2140-
}
2126+
// fontScale / 12px gets 1px on 1920×1080 screen
2127+
cls.consoleFont = re.RegisterFont( cl_consoleFont->string, cl_consoleFontSize->integer * fontScale / 12 );
2128+
}
21412129

2142-
FS_FCloseFile( f );
2130+
if ( cls.consoleFont != nullptr )
2131+
{
2132+
cls.useLegacyConsoleFont = false;
21432133
}
21442134

21452135
cls.whiteShader = re.RegisterShader( "white", RSF_NOMIP );

src/engine/renderer/tr_font.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Maryland 20850 USA.
3939
#include "qcommon/qcommon.h"
4040
#include "qcommon/q_unicode.h"
4141

42+
#include "daemon_unifont.h"
43+
4244
#include <ft2build.h>
4345
#include FT_FREETYPE_H
4446
#include FT_ERRORS_H
@@ -417,6 +419,12 @@ void RE_RenderChunk( fontInfo_t *font, const int chunk )
417419

418420
static int RE_LoadFontFile( const char *name, void **buffer )
419421
{
422+
if ( !*name )
423+
{
424+
*buffer = (void *)( &daemon_unifont_bin );
425+
return sizeof( daemon_unifont_bin );
426+
}
427+
420428
void *tmp;
421429
int length = ri.FS_ReadFile( name, &tmp );
422430

@@ -436,9 +444,13 @@ static int RE_LoadFontFile( const char *name, void **buffer )
436444

437445
static void RE_FreeFontFile( void *data )
438446
{
439-
Z_Free( data );
447+
if ( data != daemon_unifont_bin )
448+
{
449+
Z_Free( data );
450+
}
440451
}
441452

453+
// If name is the empty string, load the embedded Unifont
442454
fontInfo_t* RE_RegisterFont( const char *fontName, int pointSize )
443455
{
444456
FT_Face face;

0 commit comments

Comments
 (0)