Skip to content

Commit 0a8c033

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 0a28dd5 commit 0a8c033

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
@@ -1071,6 +1071,15 @@ if (BUILD_CLIENT)
10711071
string(APPEND SHADERS_CPP_TEXT "};\n")
10721072

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

10761085
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
@@ -2103,42 +2103,32 @@ bool CL_InitRenderer()
21032103
return false;
21042104
}
21052105

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

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

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

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

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

2141-
FS_FCloseFile( f );
2129+
if ( cls.consoleFont != nullptr )
2130+
{
2131+
cls.useLegacyConsoleFont = false;
21422132
}
21432133

21442134
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)