@@ -32,6 +32,14 @@ struct f_fontHeight_s {
32
32
int height;
33
33
int numGlyph;
34
34
f_glyph_s glyphs[128 ];
35
+ f_glyph_s defGlyph{0.0 , 0.0 , 0.0 , 0.0 , 0 , 0 , 0 };
36
+
37
+ f_glyph_s const & Glyph (char ch) const {
38
+ if ((unsigned char )ch >= numGlyph) {
39
+ return defGlyph;
40
+ }
41
+ return glyphs[(unsigned char )ch];
42
+ }
35
43
};
36
44
37
45
// ===========
@@ -126,11 +134,13 @@ int r_font_c::StringWidthInternal(f_fontHeight_s* fh, const char* str)
126
134
if (escLen) {
127
135
str+= escLen;
128
136
} else if (*str == ' \t ' ) {
129
- int spWidth = fh->glyphs [' ' ].width + fh->glyphs [' ' ].spLeft + fh->glyphs [' ' ].spRight ;
130
- width+= spWidth << 2 ;
137
+ auto & glyph = fh->Glyph (' ' );
138
+ int spWidth = glyph.width + glyph.spLeft + glyph.spRight ;
139
+ width += spWidth << 2 ;
131
140
str++;
132
141
} else {
133
- width+= fh->glyphs [*str].width + fh->glyphs [*str].spLeft + fh->glyphs [*str].spRight ;
142
+ auto & glyph = fh->Glyph (*str);
143
+ width+= glyph.width + glyph.spLeft + glyph.spRight ;
134
144
str++;
135
145
}
136
146
}
@@ -165,15 +175,17 @@ const char* r_font_c::StringCursorInternal(f_fontHeight_s* fh, const char* str,
165
175
if (escLen) {
166
176
str+= escLen;
167
177
} else if (*str == ' \t ' ) {
168
- int spWidth = fh->glyphs [' ' ].width + fh->glyphs [' ' ].spLeft + fh->glyphs [' ' ].spRight ;
178
+ auto & glyph = fh->Glyph (' ' );
179
+ int spWidth = glyph.width + glyph.spLeft + glyph.spRight ;
169
180
x+= spWidth << 1 ;
170
181
if (curX <= x) {
171
182
break ;
172
183
}
173
184
x+= spWidth << 1 ;
174
185
str++;
175
186
} else {
176
- x+= fh->glyphs [*str].width + fh->glyphs [*str].spLeft + fh->glyphs [*str].spRight ;
187
+ auto & glyph = fh->Glyph (*str);
188
+ x+= glyph.width + glyph.spLeft + glyph.spRight ;
177
189
if (curX <= x) {
178
190
break ;
179
191
}
@@ -274,28 +286,29 @@ void r_font_c::DrawTextLine(scp_t pos, int align, int height, col4_t col, const
274
286
275
287
// Handle tabs
276
288
if (*str == ' \t ' ) {
277
- int spWidth = fh->glyphs [' ' ].width + fh->glyphs [' ' ].spLeft + fh->glyphs [' ' ].spRight ;
289
+ auto & glyph = fh->Glyph (' ' );
290
+ int spWidth = glyph.width + glyph.spLeft + glyph.spRight ;
278
291
x+= (spWidth << 2 ) * scale;
279
292
str++;
280
293
continue ;
281
294
}
282
295
283
296
// Draw glyph
284
- f_glyph_s* glyph = fh->glyphs + *( str++);
285
- x+= glyph-> spLeft * scale;
286
- if (glyph-> width ) {
287
- double w = glyph-> width * scale;
297
+ auto & glyph = fh->Glyph (* str++);
298
+ x+= glyph. spLeft * scale;
299
+ if (glyph. width ) {
300
+ double w = glyph. width * scale;
288
301
if (x + w >= 0 && x < renderer->VirtualScreenWidth ()) {
289
302
renderer->curLayer ->Quad (
290
- glyph-> tcLeft , glyph-> tcTop , x, y,
291
- glyph-> tcRight , glyph-> tcTop , x + w, y,
292
- glyph-> tcRight , glyph-> tcBottom , x + w, y + height,
293
- glyph-> tcLeft , glyph-> tcBottom , x, y + height
303
+ glyph. tcLeft , glyph. tcTop , x, y,
304
+ glyph. tcRight , glyph. tcTop , x + w, y,
305
+ glyph. tcRight , glyph. tcBottom , x + w, y + height,
306
+ glyph. tcLeft , glyph. tcBottom , x, y + height
294
307
);
295
308
}
296
309
x+= w;
297
310
}
298
- x+= glyph-> spRight * scale;
311
+ x+= glyph. spRight * scale;
299
312
}
300
313
}
301
314
0 commit comments