|
4 | 4 | #include "internal.h" |
5 | 5 | #include <c2d/font.h> |
6 | 6 |
|
| 7 | +fontGlyphPos_s g_systemFontASCIICache[128]; |
| 8 | + |
7 | 9 | C2D_Font C2D_FontLoad(const char* filename) |
8 | 10 | { |
9 | 11 | FILE* f = fopen(filename, "rb"); |
@@ -51,6 +53,11 @@ static C2D_Font C2Di_PostLoadFont(C2D_Font font) |
51 | 53 | tex->border = 0; |
52 | 54 | tex->lodParam = 0; |
53 | 55 | } |
| 56 | + |
| 57 | + for (i = 0; i < NUM_ASCII_CHARACTERS; i++) |
| 58 | + { |
| 59 | + fontCalcGlyphPos(&font->asciiCache[i], font->cfnt, fontGlyphIndexFromCodePoint(font->cfnt, i), 0, 1.0, 1.0); |
| 60 | + } |
54 | 61 | } |
55 | 62 | return font; |
56 | 63 | } |
@@ -243,6 +250,26 @@ void C2D_FontCalcGlyphPos(C2D_Font font, fontGlyphPos_s* out, int glyphIndex, u3 |
243 | 250 | fontCalcGlyphPos(out, font->cfnt, glyphIndex, flags, scaleX, scaleY); |
244 | 251 | } |
245 | 252 |
|
| 253 | +void C2D_FontCalcGlyphPosFromCodePoint(C2D_Font font, fontGlyphPos_s* out, u32 codepoint, u32 flags, float scaleX, float scaleY) |
| 254 | +{ |
| 255 | + // Building glyph positions is pretty expensive, but we could just store the results for plain ASCII. |
| 256 | + if (codepoint < NUM_ASCII_CHARACTERS && flags == 0 && scaleX == 1 && scaleY == 1) |
| 257 | + { |
| 258 | + if (font) |
| 259 | + { |
| 260 | + *out = font->asciiCache[codepoint]; |
| 261 | + } |
| 262 | + else |
| 263 | + { |
| 264 | + *out = g_systemFontASCIICache[codepoint]; |
| 265 | + } |
| 266 | + } |
| 267 | + else |
| 268 | + { |
| 269 | + C2D_FontCalcGlyphPos(font, out, C2D_FontGlyphIndexFromCodePoint(font, codepoint), 0, 1.0f, 1.0f); |
| 270 | + } |
| 271 | +} |
| 272 | + |
246 | 273 | FINF_s* C2D_FontGetInfo(C2D_Font font) |
247 | 274 | { |
248 | 275 | if (!font) |
|
0 commit comments