changeset 70:a791146e3094

Make BM text work, a bit at least.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 13:42:47 +0300
parents 7b97df6f8a97
children b908fda1036e
files dmtext_bm.c
diffstat 1 files changed, 36 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/dmtext_bm.c	Mon Oct 01 13:42:20 2012 +0300
+++ b/dmtext_bm.c	Mon Oct 01 13:42:47 2012 +0300
@@ -11,13 +11,33 @@
 {
     const char *ptr = fmt;
     DMScaledBlitFunc blit = dmGetScaledBlitFunc(font->glyphs[0]->format, screen->format, mode);
+
     while (*ptr)
     {
-        char ch = *ptr++;
+        SDL_Surface *glyph;
+        int pos;
+        int ch = *ptr++;
 
-        if (isprint(ch) && ch != ' ' && ch != '\t')
+        if (ch == 'ยง')
         {
-            SDL_Surface *glyph = font->glyphs[(unsigned char) ch];
+            xc += 15;
+            continue;
+        }
+        else
+        if (ch >= 'A' && ch <= 'Z')
+            pos = ch - 'A' + 256 + 1;
+        else
+        if (ch >= 'a' && ch <= 'z')
+            pos = ch - 'a' + 1;
+        else
+        if (ch >= '0' && ch <= '9')
+            pos = ch - '0' + 48;
+        else
+            pos = ch;
+        
+        if (pos >= 0 && pos < font->nglyphs)
+        {
+            glyph = font->glyphs[pos];
             blit(glyph, xc, yc, glyph->w, glyph->h, screen);
             xc += glyph->w;
         }
@@ -104,6 +124,11 @@
 
     font->width = width;
     font->height = height;
+
+    fprintf(stderr, "%d x %d split as %d x %d blocks => %d x %d = %d glyphs\n",
+        image->w, image->h,
+        width, height,
+        xglyphs, yglyphs, xglyphs * yglyphs);
     
     glyph = 0;
     for (yc = 0; yc < yglyphs; yc++)
@@ -121,6 +146,14 @@
             dmFreeBitmapFont(font);
             return DMERR_MALLOC;
         }
+
+        SDL_Rect r;
+        r.x = xc * width;
+        r.y = yc * height;
+        r.w = width;
+        r.h = height;
+        
+        SDL_BlitSurface(image, &r, bmp, NULL);
         
         font->glyphs[glyph++] = bmp;
     }