summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Peter Nilsson <peppe@pappkartong.se>2011-02-05 12:19:34 +0100
committerJan-Peter Nilsson <peppe@pappkartong.se>2011-02-05 12:19:34 +0100
commit6bffa6de8ede9b8976623055504a50f4e70b9c60 (patch)
treefd64983d627efc93db50b2ea7dcb601eed0e2d2f
first
-rw-r--r--Makefile2
-rw-r--r--test.c125
2 files changed, 127 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4eed0da
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+test: test.c
+ gcc -Wall -std=c99 -o test test.c -lgd
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..2bac120
--- /dev/null
+++ b/test.c
@@ -0,0 +1,125 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <assert.h>
+#include <gd.h>
+
+
+typedef struct
+{
+ float left;
+ float top;
+ float right;
+ float bottom;
+ float width;
+ float height;
+ float kerning;
+ float ascent;
+} FNTINFO;
+FNTINFO fntinfo[256];
+
+typedef struct
+{
+ float x;
+ float y;
+} point_t;
+
+typedef struct
+{
+ float u1;
+ point_t top_left;
+ point_t top_right;
+ point_t bottom_left;
+ point_t bottom_right;
+ float width;
+ float height;
+ float u2;
+ float kerning;
+ float ascent;
+
+} chrPos_t;
+
+int main()
+{
+ FILE* fp;
+
+ //fp = fopen("daedric_font.fnt", "rb");
+ fp = fopen("Magic_Cards_Regular.fnt", "rb");
+ float fontSize;
+ int one;
+ fread(&fontSize, sizeof(fontSize), 1, fp);
+ printf("fontSize: %f\n", fontSize);
+ fread(&one, sizeof(int), 1, fp);
+ assert(one == 1);
+ fread(&one, sizeof(int), 1, fp);
+ assert(one == 1);
+
+ char name[284];
+ fread(name, 1, sizeof(name), fp);
+ printf("Name: %s\n", name);
+
+ //Next data starts at 296
+ chrPos_t data[256];
+ fread(data, sizeof(chrPos_t), 256, fp);
+ fclose(fp);
+
+
+ //Read the bitmap
+ char filename[1024];
+ snprintf(filename, 1024, "%s.tex", name);
+ printf("%s\n", filename);
+ fp = fopen(filename, "rb");
+ assert(fp);
+ uint32_t width, height;
+ char texarray[1024][1024][4];
+ fread(&width, sizeof(uint32_t), 1, fp);
+ fread(&height, sizeof(uint32_t), 1, fp);
+ printf("width: %d\n", width);
+ printf("height: %d\n", height);
+
+ for (int y=0; y<width; ++y)
+ {
+ for (int x=0; x<height; ++x)
+ {
+ for (int comp=0; comp<4; ++comp)
+ {
+ fread(&texarray[x][y][comp], 1, 1, fp);
+ }
+ }
+ }
+ fclose(fp);
+
+
+ int col[128];
+ gdImagePtr im, im2;
+ im = gdImageCreate(width, height);
+ im2 = gdImageCreate(width*2, height*2);
+ gdImageColorAllocate(im, 0, 0, 0);
+ col[0] = gdImageColorAllocate(im, 0xFF, 0xFF, 0xFF);
+ col[1] = gdImageColorAllocate(im, 0xFF, 0x00, 0x00);
+
+ //Make a red square beind the char
+ int c = 'D';
+ gdImageFilledRectangle(im, data[c].top_left.x*width, data[c].top_left.y*height, data[c].bottom_right.x*width, data[c].bottom_right.y*height, col[1]);
+
+ for (int y=0; y<width; ++y)
+ {
+ for (int x=0; x<height; ++x)
+ {
+ if((texarray[x][y][0] || texarray[x][y][1] || texarray[x][y][2]) && texarray[x][y][3])
+ {
+ gdImageSetPixel(im, x, y, col[0]);
+ }
+ }
+ }
+
+ gdImageCopyResized(im2, im, 0, 0, 0, 0, (width*2), (height*2), width, height);
+
+ fp = fopen("test.png", "wb");
+ gdImagePng(im2, fp);
+ fclose(fp);
+
+ gdImageDestroy(im2);
+ gdImageDestroy(im);
+
+ return 0;
+}