/
aeon.c
82 lines (66 loc) · 1.74 KB
/
aeon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <assert.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include "aeon.h"
#define return_if(error) ({ \
typeof(error) _error = error; \
\
if(error) { \
return error; \
} \
})
void bitblit(
void *target,
unsigned target_width,
const void *source,
unsigned source_width,
unsigned source_height,
unsigned x,
unsigned y
) {
unsigned i;
target = (char *)(target) + (target_width * y) + x;
for(i = 0; i < source_height; ++i) {
memcpy(target, source, source_width);
target = (char *)(target) + target_width;
source = (const char *)(source) + source_width;
}
}
void aeon_bitmap_alloc(aeon_op *op, unsigned glyph_count) {
assert(NULL && "Not implemented.");
}
int aeon_render(
aeon_op *op,
aeon_glyph_info *glyph_info,
unsigned charcode
) {
FT_Error ft_error;
FT_Face ft_face = op->ft_face;
FT_Bitmap *ft_bitmap;
void *op_bitmap = op->bitmap;
unsigned op_bitmap_width = op->bitmap_width;
unsigned op_bitmap_height = op->bitmap_height;
unsigned max_glyph_width = op->max_glyph_width;
unsigned max_glyph_height = op->max_glyph_height;
unsigned *pen_x = &op->pen_x;
unsigned *pen_y = &op->pen_y;
ft_error = FT_Load_Char(ft_face, charcode, FT_LOAD_RENDER);
return_if(ft_error);
ft_bitmap = &ft_face->glyph->bitmap;
bitblit(
op_bitmap,
op_bitmap_width,
ft_bitmap->buffer,
ft_bitmap->width,
ft_bitmap->rows,
*pen_x,
*pen_y
);
*pen_x += op->max_glyph_width;
if(*pen_x + max_glyph_width > op_bitmap_width) {
*pen_y += max_glyph_height;
*pen_x = 0;
}
assert(*pen_y + max_glyph_height <= op->bitmap_height);
return 0;
}