diff tools/libgutil.c @ 1957:ef08af6887b7

Revamp the bitmap font system to use single SDL_Surface for the font graphics instead of N surfaces for each separate glyph.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 30 Jun 2018 05:24:12 +0300
parents 59e9ad13b50e
children 6d12670e0248
line wrap: on
line diff
--- a/tools/libgutil.c	Sat Jun 30 05:22:15 2018 +0300
+++ b/tools/libgutil.c	Sat Jun 30 05:24:12 2018 +0300
@@ -117,12 +117,15 @@
 void dmDrawBMTextConstQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt)
 {
     const char *ptr = fmt;
-    DMUnscaledBlitFunc blit = NULL;
+    DMUnscaledBlitFunc blit = dmGetUnscaledBlitFunc(font->glyphs->format, screen->format, mode);
+    Uint8 *orig = font->glyphs->pixels;
+    SDL_Surface surf;
+
+    memcpy(&surf, font->glyphs, sizeof(SDL_Surface));
 
     while (*ptr)
     {
         int ch = toupper(*ptr++);
-        SDL_Surface *glyph;
 
         if (ch == '_')
         {
@@ -130,16 +133,20 @@
             continue;
         }
 
-        if (ch >= 0 && ch < font->nglyphs && (glyph = font->glyphs[ch]) != NULL)
+        if (ch < font->maxglyph && ch != ' ')
         {
-            if (blit == NULL)
-                blit = dmGetUnscaledBlitFunc(glyph->format, screen->format, mode);
+            DMBitmapGlyph *glyph = &font->glyphMap[ch];
 
-            blit(glyph, xc, yc, screen);
-            xc += font->width;
+            if (glyph->index >= 0)
+            {
+                surf.pixels = orig + glyph->index * font->gsize;
+                surf.w = glyph->width;
+                surf.h = glyph->height;
+
+                blit(&surf, xc, yc, screen);
+            }
         }
-        else
-            xc += font->width;
+        xc += font->width;
     }
 }