@@ -27,7 +27,7 @@ FT_Library CFreeTypeFont::m_Library;
27
27
28
28
29
29
CFreeTypeFont::CFreeTypeFont () : CBaseFont(),
30
- face(), m_szRealFontFile()
30
+ face()
31
31
{
32
32
33
33
}
@@ -36,94 +36,27 @@ CFreeTypeFont::~CFreeTypeFont()
36
36
{
37
37
}
38
38
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
-
90
39
bool CFreeTypeFont::FindFontDataFile ( const char *name, int tall, int weight, int flags, char *dataFile, int dataFileChars )
91
40
{
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" ))
115
47
{
116
- bRet = true ;
117
- Q_strncpy ( dataFile, ( char *)filename, dataFileChars ) ;
48
+ Q_strncpy ( dataFile, " gfx/fonts/tahoma.ttf " , dataFileChars ) ;
49
+ return true ;
118
50
}
119
- else bRet = false ;
120
51
121
- FcPatternDestroy ( pattern );
122
- return bRet;
52
+ return false ;
123
53
}
124
54
125
55
bool CFreeTypeFont::Create (const char *name, int tall, int weight, int blur, float brighten, int outlineSize, int scanlineOffset, float scanlineScale, int flags)
126
56
{
57
+ char font_face_path[256 ];
58
+ int font_face_length;
59
+
127
60
Q_strncpy ( m_szName, name, sizeof ( m_szName ) );
128
61
m_iTall = tall;
129
62
m_iWeight = weight;
@@ -137,15 +70,24 @@ bool CFreeTypeFont::Create(const char *name, int tall, int weight, int blur, flo
137
70
m_iScanlineOffset = scanlineOffset;
138
71
m_fScanlineScale = scanlineScale;
139
72
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 )) )
141
74
{
142
75
Con_Printf ( " Unable to find font named %s\n " , name );
143
76
m_szName[0 ] = 0 ;
144
77
return false ;
145
78
}
146
79
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 ))
148
89
{
90
+ Con_Printf ( " Unable to create font %s!\n " , font_face_path );
149
91
return false ;
150
92
}
151
93
0 commit comments