Browse Source

Add test_hello_world_text_rendering

rexim 3 years ago
parent
commit
4d0b185f2c
4 changed files with 108 additions and 7 deletions
  1. 90 7
      olive.c
  2. 18 0
      test.c
  3. BIN
      test/test_hello_world_text_rendering_expected.png
  4. BIN
      wasm/3d.wasm

+ 90 - 7
olive.c

@@ -22,10 +22,11 @@ typedef struct {
     const char *glyphs;
     const char *glyphs;
 } Olivec_Font;
 } Olivec_Font;
 
 
-#define DEFAULT_FONT_HEIGHT 5
-#define DEFAULT_FONT_WIDTH 5
+#define DEFAULT_FONT_HEIGHT 6
+#define DEFAULT_FONT_WIDTH 6
 static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] = {
 static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] = {
     ['a'] = {
     ['a'] = {
+        {0, 0, 0, 0, 0},
         {0, 1, 1, 0, 0},
         {0, 1, 1, 0, 0},
         {0, 0, 0, 1, 0},
         {0, 0, 0, 1, 0},
         {0, 1, 1, 1, 0},
         {0, 1, 1, 1, 0},
@@ -37,9 +38,11 @@ static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] =
         {1, 1, 1, 0, 0},
         {1, 1, 1, 0, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
+        {1, 0, 0, 1, 0},
         {1, 1, 1, 0, 0},
         {1, 1, 1, 0, 0},
     },
     },
     ['c'] = {
     ['c'] = {
+        {0, 0, 0, 0, 0},
         {0, 1, 1, 0, 0},
         {0, 1, 1, 0, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 0, 0},
         {1, 0, 0, 0, 0},
@@ -47,13 +50,15 @@ static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] =
         {0, 1, 1, 0, 0},
         {0, 1, 1, 0, 0},
     },
     },
     ['d'] = {
     ['d'] = {
-        {0, 0, 0, 1, 0},
         {0, 0, 0, 1, 0},
         {0, 0, 0, 1, 0},
         {0, 1, 1, 1, 0},
         {0, 1, 1, 1, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
+        {1, 0, 0, 1, 0},
+        {1, 0, 0, 1, 0},
         {0, 1, 1, 1, 0},
         {0, 1, 1, 1, 0},
     },
     },
     ['e'] = {
     ['e'] = {
+        {0, 0, 0, 0, 0},
         {0, 1, 1, 0, 0},
         {0, 1, 1, 0, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
         {1, 1, 1, 1, 0},
         {1, 1, 1, 1, 0},
@@ -66,21 +71,99 @@ static char default_font_glyphs[128][DEFAULT_FONT_HEIGHT][DEFAULT_FONT_WIDTH] =
         {1, 1, 1, 1, 0},
         {1, 1, 1, 1, 0},
         {0, 1, 0, 0, 0},
         {0, 1, 0, 0, 0},
         {0, 1, 0, 0, 0},
         {0, 1, 0, 0, 0},
+        {0, 1, 0, 0, 0},
     },
     },
-    ['p'] = {
+    ['g'] = {},
+    ['h'] = {
+        {1, 0, 0, 0, 0},
         {1, 1, 1, 0, 0},
         {1, 1, 1, 0, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
-        {1, 1, 1, 0, 0},
-        {1, 0, 0, 0, 0},
-        {1, 0, 0, 0, 0},
+        {1, 0, 0, 1, 0},
+        {1, 0, 0, 1, 0},
+        {1, 0, 0, 1, 0},
     },
     },
+    ['i'] = {},
+    ['j'] = {},
+    ['k'] = {},
+    ['l'] = {
+        {0, 1, 1, 0, 0},
+        {0, 0, 1, 0, 0},
+        {0, 0, 1, 0, 0},
+        {0, 0, 1, 0, 0},
+        {0, 0, 1, 0, 0},
+        {0, 1, 1, 1, 0},
+    },
+    ['m'] = {},
+    ['n'] = {},
     ['o'] = {
     ['o'] = {
+        {0, 0, 0, 0, 0},
         {0, 1, 1, 0, 0},
         {0, 1, 1, 0, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
         {1, 0, 0, 1, 0},
         {0, 1, 1, 0, 0},
         {0, 1, 1, 0, 0},
     },
     },
+    ['p'] = {
+        {1, 1, 1, 0, 0},
+        {1, 0, 0, 1, 0},
+        {1, 0, 0, 1, 0},
+        {1, 1, 1, 0, 0},
+        {1, 0, 0, 0, 0},
+        {1, 0, 0, 0, 0},
+    },
+    ['q'] = {},
+    ['r'] = {
+        {0, 0, 0, 0, 0},
+        {1, 0, 1, 1, 0},
+        {1, 1, 0, 0, 1},
+        {1, 0, 0, 0, 0},
+        {1, 0, 0, 0, 0},
+        {1, 0, 0, 0, 0},
+    },
+    ['s'] = {},
+    ['t'] = {},
+    ['u'] = {},
+    ['v'] = {},
+    ['w'] = {
+        {0, 0, 0, 0, 0},
+        {1, 0, 0, 0, 1},
+        {1, 0, 1, 0, 1},
+        {1, 0, 1, 0, 1},
+        {1, 0, 1, 0, 1},
+        {0, 1, 1, 1, 1},
+    },
+    ['x'] = {},
+    ['y'] = {},
+    ['z'] = {},
+
+    ['A'] = {},
+    ['B'] = {},
+    ['C'] = {},
+    ['D'] = {},
+    ['E'] = {},
+    ['F'] = {},
+    ['G'] = {},
+    ['H'] = {},
+    ['I'] = {},
+    ['J'] = {},
+    ['K'] = {},
+    ['L'] = {},
+    ['M'] = {},
+    ['N'] = {},
+    ['O'] = {},
+    ['P'] = {},
+    ['Q'] = {},
+    ['R'] = {},
+    ['S'] = {},
+    ['T'] = {},
+    ['U'] = {},
+    ['V'] = {},
+    ['W'] = {},
+    ['X'] = {},
+    ['Y'] = {},
+    ['Z'] = {},
+
+    [','] = {}
 };
 };
 
 
 static Olivec_Font default_font = {
 static Olivec_Font default_font = {

+ 18 - 0
test.c

@@ -316,6 +316,23 @@ Olivec_Canvas test_lines_example(void)
     return oc;
     return oc;
 }
 }
 
 
+Olivec_Canvas canvas_alloc(size_t width, size_t height)
+{
+    uint32_t *pixels = context_alloc(sizeof(uint32_t)*width*height);
+    return olivec_canvas(pixels, width, height, width);
+}
+
+Olivec_Canvas test_hello_world_text_rendering(void)
+{
+    size_t size = 5;
+    const char *text = "hello, world";
+    size_t text_len = strlen(text);
+    Olivec_Canvas oc = canvas_alloc(400, 150);
+    olivec_fill(oc, BACKGROUND_COLOR);
+    olivec_text(oc, text, oc.width/2 - DEFAULT_FONT_WIDTH*size*text_len/2, oc.height/2 - DEFAULT_FONT_HEIGHT*size/2, default_font, size, FOREGROUND_COLOR);
+    return oc;
+}
+
 Test_Case test_cases[] = {
 Test_Case test_cases[] = {
     DEFINE_TEST_CASE(test_fill_rect),
     DEFINE_TEST_CASE(test_fill_rect),
     DEFINE_TEST_CASE(test_fill_circle),
     DEFINE_TEST_CASE(test_fill_circle),
@@ -325,6 +342,7 @@ Test_Case test_cases[] = {
     DEFINE_TEST_CASE(test_checker_example),
     DEFINE_TEST_CASE(test_checker_example),
     DEFINE_TEST_CASE(test_circle_example),
     DEFINE_TEST_CASE(test_circle_example),
     DEFINE_TEST_CASE(test_lines_example),
     DEFINE_TEST_CASE(test_lines_example),
+    DEFINE_TEST_CASE(test_hello_world_text_rendering),
 };
 };
 #define TEST_CASES_COUNT (sizeof(test_cases)/sizeof(test_cases[0]))
 #define TEST_CASES_COUNT (sizeof(test_cases)/sizeof(test_cases[0]))
 
 

BIN
test/test_hello_world_text_rendering_expected.png


BIN
wasm/3d.wasm