diff options
Diffstat (limited to 'font')
| -rw-r--r-- | font/font.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/font/font.h b/font/font.h index 13ff1c3..9d37e64 100644 --- a/font/font.h +++ b/font/font.h | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | static const unsigned char FontGlyphStart = 32; // Space. | 6 | static const unsigned char FontGlyphStart = 32; // Space. |
| 7 | static const unsigned char FontGlyphEnd = 127; // One past tilde. | 7 | static const unsigned char FontGlyphEnd = 127; // One past tilde. |
| 8 | static const int FontAtlasNumGlyphs = FontGlyphEnd - FontGlyphStart; | 8 | static const unsigned int FontAtlasNumGlyphs = FontGlyphEnd - FontGlyphStart; |
| 9 | 9 | ||
| 10 | /// Font atlas header. | 10 | /// Font atlas header. |
| 11 | typedef struct FontHeader { | 11 | typedef struct FontHeader { |
| @@ -32,8 +32,10 @@ FontAtlas* LoadFontAtlas(const char* path); | |||
| 32 | static inline const unsigned char* FontGetGlyph( | 32 | static inline const unsigned char* FontGetGlyph( |
| 33 | const FontAtlas* atlas, unsigned char c) { | 33 | const FontAtlas* atlas, unsigned char c) { |
| 34 | assert(atlas); | 34 | assert(atlas); |
| 35 | const int index = c - FontGlyphStart; | 35 | unsigned index = c - FontGlyphStart; |
| 36 | assert(index >= 0); | 36 | if (index >= FontAtlasNumGlyphs) { |
| 37 | index = '?' - FontGlyphStart; | ||
| 38 | } | ||
| 37 | assert(index < FontAtlasNumGlyphs); | 39 | assert(index < FontAtlasNumGlyphs); |
| 38 | return atlas->pixels + | 40 | return atlas->pixels + |
| 39 | index * (atlas->header.glyph_width * atlas->header.glyph_height); | 41 | index * (atlas->header.glyph_width * atlas->header.glyph_height); |
