Skip to content

Commit 740d1a6

Browse files
committed
Drop fontconfig dependency as we're loading font files from extras.pk3
1 parent 6c1cc6b commit 740d1a6

File tree

4 files changed

+29
-96
lines changed

4 files changed

+29
-96
lines changed

CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ if(MAINUI_USE_CUSTOM_FONT_RENDER)
9898
else()
9999
# Use freetype2
100100
find_package(PkgConfig)
101-
pkg_check_modules(FC REQUIRED fontconfig)
102-
include_directories(${FC_INCLUDE_DIRS})
103-
target_link_libraries(${MAINUI_LIBRARY} ${FC_LIBRARIES})
101+
pkg_check_modules(FT2 REQUIRED freetype2)
102+
include_directories(${FT2_INCLUDE_DIRS})
103+
target_link_libraries(${MAINUI_LIBRARY} ${FT2_LIBRARIES})
104104
add_definitions(-DMAINUI_USE_FREETYPE)
105105
endif()
106106
endif()

font/FreeTypeFont.cpp

+24-82
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ FT_Library CFreeTypeFont::m_Library;
2727

2828

2929
CFreeTypeFont::CFreeTypeFont() : CBaseFont(),
30-
face(), m_szRealFontFile()
30+
face()
3131
{
3232

3333
}
@@ -36,94 +36,27 @@ CFreeTypeFont::~CFreeTypeFont()
3636
{
3737
}
3838

39-
/**
40-
* Find a matching font where @type (one of FC_*) is equal to @value. For a
41-
* list of types, see http://fontconfig.org/fontconfig-devel/x19.html#AEN27.
42-
* The variable arguments are a list of triples, just like the first three
43-
* arguments, and must be NULL terminated.
44-
*
45-
* For example,
46-
* FontMatchString(FC_FILE, FcTypeString, "/usr/share/fonts/myfont.ttf", NULL);
47-
*
48-
* Ripped from skia source code
49-
*/
50-
static FcPattern* FontMatch(const char* type, ...)
51-
{
52-
FcValue fcvalue;
53-
va_list ap;
54-
55-
va_start(ap, type);
56-
57-
FcPattern* pattern = FcPatternCreate();
58-
59-
for (;;) {
60-
// FcType is promoted to int when passed through ...
61-
fcvalue.type = static_cast<FcType>(va_arg(ap, int));
62-
switch (fcvalue.type) {
63-
case FcTypeString:
64-
fcvalue.u.s = va_arg(ap, const FcChar8 *);
65-
break;
66-
case FcTypeInteger:
67-
fcvalue.u.i = va_arg(ap, int);
68-
break;
69-
default:
70-
ASSERT(("FontMatch unhandled type"));
71-
}
72-
FcPatternAdd(pattern, type, fcvalue, FcFalse);
73-
74-
type = va_arg(ap, const char *);
75-
if (!type)
76-
break;
77-
};
78-
va_end(ap);
79-
80-
FcConfigSubstitute(NULL, pattern, FcMatchPattern);
81-
FcDefaultSubstitute(pattern);
82-
83-
FcResult result;
84-
FcPattern* match = FcFontMatch(NULL, pattern, &result);
85-
FcPatternDestroy(pattern);
86-
87-
return match;
88-
}
89-
9039
bool CFreeTypeFont::FindFontDataFile( const char *name, int tall, int weight, int flags, char *dataFile, int dataFileChars )
9140
{
92-
int nFcWeight = weight / 5;
93-
FcPattern *pattern;
94-
FcChar8 *filename;
95-
96-
bool bRet;
97-
98-
if( !FcInit() )
99-
return false;
100-
101-
int slant = FC_SLANT_ROMAN;
102-
if( flags & ( FONT_ITALIC ))
103-
slant = FC_SLANT_ITALIC;
104-
105-
pattern = FontMatch(
106-
FC_FAMILY, FcTypeString, name,
107-
FC_WEIGHT, FcTypeInteger, nFcWeight,
108-
FC_SLANT, FcTypeInteger, slant,
109-
NULL );
110-
111-
if( !pattern )
112-
return false;
113-
114-
if( !FcPatternGetString( pattern, "file", 0, &filename ) )
41+
if( !strcmp( name, "Trebuchet MS" ))
42+
{
43+
Q_strncpy( dataFile, "gfx/fonts/FiraSans-Regular.ttf", dataFileChars );
44+
return true;
45+
}
46+
else if( !strcmp( name, "Tahoma" ))
11547
{
116-
bRet = true;
117-
Q_strncpy( dataFile, (char*)filename, dataFileChars );
48+
Q_strncpy( dataFile, "gfx/fonts/tahoma.ttf", dataFileChars );
49+
return true;
11850
}
119-
else bRet = false;
12051

121-
FcPatternDestroy( pattern );
122-
return bRet;
52+
return false;
12353
}
12454

12555
bool CFreeTypeFont::Create(const char *name, int tall, int weight, int blur, float brighten, int outlineSize, int scanlineOffset, float scanlineScale, int flags)
12656
{
57+
char font_face_path[256];
58+
int font_face_length;
59+
12760
Q_strncpy( m_szName, name, sizeof( m_szName ) );
12861
m_iTall = tall;
12962
m_iWeight = weight;
@@ -137,15 +70,24 @@ bool CFreeTypeFont::Create(const char *name, int tall, int weight, int blur, flo
13770
m_iScanlineOffset = scanlineOffset;
13871
m_fScanlineScale = scanlineScale;
13972

140-
if( !FindFontDataFile( name, tall, weight, flags, m_szRealFontFile, sizeof( m_szRealFontFile ) ) )
73+
if( !FindFontDataFile( name, tall, weight, flags, font_face_path, sizeof( font_face_path )))
14174
{
14275
Con_Printf( "Unable to find font named %s\n", name );
14376
m_szName[0] = 0;
14477
return false;
14578
}
14679

147-
if( FT_New_Face( m_Library, m_szRealFontFile, 0, &face ))
80+
m_pFontData = g_FontMgr->LoadFontDataFile( font_face_path, &font_face_length );
81+
82+
if( !m_pFontData )
83+
{
84+
Con_Printf( "Unable to read font file %s!\n", font_face_path );
85+
return false;
86+
}
87+
88+
if( FT_New_Memory_Face( m_Library, m_pFontData, font_face_length, 0, &face ))
14889
{
90+
Con_Printf( "Unable to create font %s!\n", font_face_path );
14991
return false;
15092
}
15193

font/FreeTypeFont.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ GNU General Public License for more details.
2222

2323
extern "C"
2424
{
25-
#include <fontconfig/fontconfig.h>
2625
#include <ft2build.h>
2726
#include FT_FREETYPE_H
2827
}
@@ -48,7 +47,7 @@ class CFreeTypeFont : public CBaseFont
4847
private:
4948
FT_Face face;
5049
static FT_Library m_Library;
51-
char m_szRealFontFile[4096];
50+
byte *m_pFontData;
5251
bool FindFontDataFile(const char *name, int tall, int weight, int flags, char *dataFile, int dataFileChars);
5352

5453
friend class CFontManager;

wscript

+1-9
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ FT2_CHECK='''extern "C" {
1515
int main() { return FT_Init_FreeType( NULL ); }
1616
'''
1717

18-
FC_CHECK='''extern "C" {
19-
#include <fontconfig/fontconfig.h>
20-
}
21-
22-
int main() { return (int)FcInit(); }
23-
'''
24-
2518
def options(opt):
2619
grp = opt.add_option_group('MainUI C++ options')
2720
grp.add_option('--enable-stbtt', action = 'store_true', dest = 'USE_STBTT', default = False,
@@ -57,7 +50,6 @@ def configure(conf):
5750
if conf.env.DEST_OS != 'win32' and conf.env.DEST_OS != 'dos':
5851
if not conf.options.USE_STBTT and not conf.options.LOW_MEMORY:
5952
conf.check_pkg('freetype2', 'FT2', FT2_CHECK)
60-
conf.check_pkg('fontconfig', 'FC', FC_CHECK)
6153
conf.define('MAINUI_USE_FREETYPE', 1)
6254

6355
def build(bld):
@@ -88,7 +80,7 @@ def build(bld):
8880
source = source,
8981
target = 'menu',
9082
includes = includes,
91-
use = 'werror FT2 FC GDI32 USER32',
83+
use = 'werror FT2 GDI32 USER32',
9284
install_path = bld.env.LIBDIR,
9385
subsystem = bld.env.MSVC_SUBSYSTEM,
9486
cmake_skip = True

0 commit comments

Comments
 (0)