From 0ffd63fed9dcfb60be7378b6f53f0f1d011fd26c Mon Sep 17 00:00:00 2001
From: 3gg <3gg@shellblade.net>
Date: Sat, 24 May 2025 17:01:01 -0700
Subject: Tweaks

---
 fontbaker/fontbaker.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

(limited to 'fontbaker')

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(
   printf("\n");
 }
 
+static char GetSymbol(unsigned char pixel) {
+  if (pixel >= 128) {
+    return '#';
+  } else if (pixel >= 32) {
+    return '*';
+  } else if (pixel > 0) {
+    return '.';
+  } else {
+    return ' ';
+  }
+}
+
 static void RenderText(const FontAtlas* atlas, const char* text) {
+  assert(atlas);
   assert(text);
 
-  const int glyph_width  = atlas->header.glyph_width;
-  const int glyph_height = atlas->header.glyph_height;
-  const int glyph_size   = glyph_width * glyph_height;
+  const int    glyph_width  = atlas->header.glyph_width;
+  const int    glyph_height = atlas->header.glyph_height;
+  const int    glyph_size   = glyph_width * glyph_height;
+  const size_t text_length  = strlen(text);
 
   for (int y = 0; y < glyph_height; ++y) {
     printf("%02d  ", y);
 
-    for (size_t i = 0; i < strlen(text); ++i) {
+    for (size_t i = 0; i < text_length; ++i) {
       const char c            = text[i];
       const int  glyph_offset = (c - FontGlyphStart) * glyph_size;
       const int  row_offset   = (y * glyph_width);
@@ -55,14 +69,7 @@ static void RenderText(const FontAtlas* atlas, const char* text) {
       const unsigned char* pixel = atlas->pixels + glyph_offset + row_offset;
 
       for (int x = 0; x < glyph_width; ++x, ++pixel) {
-        unsigned char p = ' ';
-        if (*pixel >= 128) {
-          p = '#';
-        } else if (*pixel >= 32) {
-          p = '*';
-        } else if (*pixel > 0) {
-          p = '.';
-        }
+        unsigned char p = GetSymbol(*pixel);
         printf("%c", p);
       }
     }
-- 
cgit v1.2.3