Mirai's Miscellaneous Misadventures
M19 / core / text.c
1
2
3
4#include <mimimi/engines.h>
5#include <mimimi/chapters.h>
6#include <mimimi/fonts.h>
7#include <mimimi/ground.h>
8#include <mimimi/assets.h>
9
10static void mimimi_stamp_image(struct mimimi_image *target, int x0, int y0, struct mimimi_image *source)
11{
12 for (int x1 = 0 ; x1 < source->width ; x1++)
13 for (int y1 = 0 ; y1 < source->height ; y1++)
14 {
15 int x = x0 + x1;
16 int y = y0 + y1;
17
18 if (x < 0) continue;
19 if (y < 0) continue;
20
21 if (x >= target->width) continue;
22 if (y >= target->height) continue;
23
24 unsigned char color = source->colors[x1 + y1 * source->width];
25 if (color == 0) continue;
26
27 target->colors[x + y * target->width] = color;
28 }
29}
30
31int mimimi_text(struct mimimi_image *image, struct mimimi_image *glyphs, int x, int y, char *text)
32{
33 while (*text != 0)
34 {
35 char ch = *text++;
36
37 if (ch == 0x20)
38 {
39 x += 4;
40 continue;
41 }
42
43 if (ch <= 0x20) continue;
44 if (ch >= 0x7F) continue;
45
46 struct mimimi_image *glyph = glyphs + (ch - 0x20);
47
48 mimimi_stamp_image(image, x - 1, y - glyph->height + 6, glyph);
49 x += glyph->width - 1;
50 }
51
52 return x;
53}