summaryrefslogtreecommitdiff
path: root/font/font.h
diff options
context:
space:
mode:
Diffstat (limited to 'font/font.h')
-rw-r--r--font/font.h8
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
6static const unsigned char FontGlyphStart = 32; // Space. 6static const unsigned char FontGlyphStart = 32; // Space.
7static const unsigned char FontGlyphEnd = 127; // One past tilde. 7static const unsigned char FontGlyphEnd = 127; // One past tilde.
8static const int FontAtlasNumGlyphs = FontGlyphEnd - FontGlyphStart; 8static const unsigned int FontAtlasNumGlyphs = FontGlyphEnd - FontGlyphStart;
9 9
10/// Font atlas header. 10/// Font atlas header.
11typedef struct FontHeader { 11typedef struct FontHeader {
@@ -32,8 +32,10 @@ FontAtlas* LoadFontAtlas(const char* path);
32static inline const unsigned char* FontGetGlyph( 32static 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);