changeset 73:295d08376744

Add function for saving a bitmap font.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 14:18:35 +0300
parents be6160981428
children 23ac82365a65
files dmtext_bm.c
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dmtext_bm.c	Mon Oct 01 14:17:47 2012 +0300
+++ b/dmtext_bm.c	Mon Oct 01 14:18:35 2012 +0300
@@ -5,6 +5,7 @@
  * (C) Copyright 2012 Tecnic Software productions (TNSP)
  */
 #include "dmtext.h"
+#include "dmresw.h"
 
 
 void dmDrawBMTextConst(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt)
@@ -161,3 +162,25 @@
     *pfont = font;
     return DMERR_OK;
 }
+
+int dmSaveBitmapFont(DMResource *res, DMBitmapFont *font)
+{
+    int i;
+
+    dmf_write_str(res, (Uint8 *) "DMFONT", 6);
+    dmf_write_le16(res, 0x0100);
+    dmf_write_le32(res, font->width);
+    dmf_write_le32(res, font->height);
+    dmf_write_le32(res, font->nglyphs);
+
+    for (i = 0; i < font->nglyphs; i++)
+    {
+        SDL_Surface *glyph = font->glyphs[i];
+        dmf_write_le32(res, glyph->w);
+        dmf_write_le32(res, glyph->h);
+        dmf_write_le32(res, glyph->pitch);
+        dmf_write_str(res, glyph->pixels, glyph->h * glyph->pitch);
+    }
+        
+    return DMERR_OK;
+}