diff options
| author | 3gg <3gg@shellblade.net> | 2025-05-24 17:01:01 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-05-24 17:01:01 -0700 |
| commit | 0ffd63fed9dcfb60be7378b6f53f0f1d011fd26c (patch) | |
| tree | 4a3b0f541b91349955b5b58f24b47c8b38f287f0 /fontbaker | |
| parent | 68a3532728b55b73d8bcadb8ccfc1d9396346cd2 (diff) | |
Tweaks
Diffstat (limited to 'fontbaker')
| -rw-r--r-- | fontbaker/fontbaker.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/fontbaker/fontbaker.c b/fontbaker/fontbaker.c index a11aa88..25d629d 100644 --- a/fontbaker/fontbaker.c +++ b/fontbaker/fontbaker.c | |||
| @@ -37,17 +37,31 @@ static void RenderGlyph( | |||
| 37 | printf("\n"); | 37 | printf("\n"); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | static char GetSymbol(unsigned char pixel) { | ||
| 41 | if (pixel >= 128) { | ||
| 42 | return '#'; | ||
| 43 | } else if (pixel >= 32) { | ||
| 44 | return '*'; | ||
| 45 | } else if (pixel > 0) { | ||
| 46 | return '.'; | ||
| 47 | } else { | ||
| 48 | return ' '; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 40 | static void RenderText(const FontAtlas* atlas, const char* text) { | 52 | static void RenderText(const FontAtlas* atlas, const char* text) { |
| 53 | assert(atlas); | ||
| 41 | assert(text); | 54 | assert(text); |
| 42 | 55 | ||
| 43 | const int glyph_width = atlas->header.glyph_width; | 56 | const int glyph_width = atlas->header.glyph_width; |
| 44 | const int glyph_height = atlas->header.glyph_height; | 57 | const int glyph_height = atlas->header.glyph_height; |
| 45 | const int glyph_size = glyph_width * glyph_height; | 58 | const int glyph_size = glyph_width * glyph_height; |
| 59 | const size_t text_length = strlen(text); | ||
| 46 | 60 | ||
| 47 | for (int y = 0; y < glyph_height; ++y) { | 61 | for (int y = 0; y < glyph_height; ++y) { |
| 48 | printf("%02d ", y); | 62 | printf("%02d ", y); |
| 49 | 63 | ||
| 50 | for (size_t i = 0; i < strlen(text); ++i) { | 64 | for (size_t i = 0; i < text_length; ++i) { |
| 51 | const char c = text[i]; | 65 | const char c = text[i]; |
| 52 | const int glyph_offset = (c - FontGlyphStart) * glyph_size; | 66 | const int glyph_offset = (c - FontGlyphStart) * glyph_size; |
| 53 | const int row_offset = (y * glyph_width); | 67 | const int row_offset = (y * glyph_width); |
| @@ -55,14 +69,7 @@ static void RenderText(const FontAtlas* atlas, const char* text) { | |||
| 55 | const unsigned char* pixel = atlas->pixels + glyph_offset + row_offset; | 69 | const unsigned char* pixel = atlas->pixels + glyph_offset + row_offset; |
| 56 | 70 | ||
| 57 | for (int x = 0; x < glyph_width; ++x, ++pixel) { | 71 | for (int x = 0; x < glyph_width; ++x, ++pixel) { |
| 58 | unsigned char p = ' '; | 72 | unsigned char p = GetSymbol(*pixel); |
| 59 | if (*pixel >= 128) { | ||
| 60 | p = '#'; | ||
| 61 | } else if (*pixel >= 32) { | ||
| 62 | p = '*'; | ||
| 63 | } else if (*pixel > 0) { | ||
| 64 | p = '.'; | ||
| 65 | } | ||
| 66 | printf("%c", p); | 73 | printf("%c", p); |
| 67 | } | 74 | } |
| 68 | } | 75 | } |
