22 if(code < 0x20)
return NULL;
23 for(i = 0; i < font->
count; i++) {
25 return font->
glyph[i];
40 unsigned char* buffer;
53 if((dq == 0 && line[i] ==
' ') || line[i] == 0) {
57 args[argc] = line + incr;
58 if(args[argc][0] ==
'"') args[argc]++;
59 if(args[argc][strlen(args[argc]) - 1] ==
'"') args[argc][strlen(args[argc]) - 1] = 0;
66 }
else if(line[i] ==
'"') {
70 if(store->line_index != -1 && store->line_index < font->
glyph[store->glyph_index]->
bbox.
height) {
72 unsigned char* linebuf = store->buffer + store->line_index * wid * 4;
73 for(i = 0; line[i] != 0; i++) {
76 if(
'0' <= line[i] && line[i] <=
'9') {
78 }
else if(
'a' <= line[i] && line[i] <=
'f') {
79 n = 10 + line[i] -
'a';
80 }
else if(
'A' <= line[i] && line[i] <=
'F') {
81 n = 10 + line[i] -
'A';
83 for(j = 0; j < (wid > 4 ? 4 : wid); j++) {
85 memset(linebuf + 16 * i + 4 * j, 255, 4);
92 }
else if(argc > 0 && strcmp(args[0],
"STARTCHAR") == 0) {
93 font->
glyph[store->glyph_index] = malloc(
sizeof(**font->
glyph));
94 memset(font->
glyph[store->glyph_index], 0,
sizeof(**font->
glyph));
95 }
else if(argc > 0 && strcmp(args[0],
"ENDCHAR") == 0) {
99 store->line_index = -1;
100 }
else if(argc > 0 && strcmp(args[0],
"BITMAP") == 0) {
101 store->line_index = 0;
102 }
else if(argc == 2) {
103 if(strcmp(args[0],
"COPYRIGHT") == 0) {
105 }
else if(strcmp(args[0],
"NOTICE") == 0) {
107 }
else if(strcmp(args[0],
"FOUNDRY") == 0) {
109 }
else if(strcmp(args[0],
"CHARS") == 0) {
112 font->
count = atoi(args[1]);
114 for(j = 0; j < font->
count; j++) font->
glyph[j] = NULL;
115 }
else if(strcmp(args[0],
"ENCODING") == 0) {
116 font->
glyph[store->glyph_index]->
code = atoi(args[1]);
118 }
else if(argc == 3) {
119 if(strcmp(args[0],
"DWIDTH") == 0) {
120 font->
glyph[store->glyph_index]->
dwidth[0] = atoi(args[1]);
121 font->
glyph[store->glyph_index]->
dwidth[1] = atoi(args[2]);
123 }
else if(argc == 5) {
124 if(strcmp(args[0],
"FONTBOUNDINGBOX") == 0) {
127 font->
bbox.
x = atoi(args[3]);
128 font->
bbox.
y = atoi(args[4]);
129 }
else if(strcmp(args[0],
"BBX") == 0) {
132 font->
glyph[store->glyph_index]->
bbox.
x = atoi(args[3]);
133 font->
glyph[store->glyph_index]->
bbox.
y = atoi(args[4]);
135 store->buffer = malloc(atoi(args[1]) * atoi(args[2]) * 4);
136 memset(store->buffer, 0, atoi(args[1]) * atoi(args[2]) * 4);
149 store.line_index = -1;
150 store.glyph_index = 0;
151 memset(font, 0,
sizeof(*font));
152 if(gf_stat(path, &s) != 0) {
156 gf_log_function(NULL,
"%s: %lu bytes", path, (
unsigned long)s.st_size);
157 buf = malloc(s.st_size + 1);
159 f = fopen(path,
"r");
160 fread(buf, s.st_size, 1, f);
164 if(buf[i] == 0 || buf[i] ==
'\n') {
166 char* line = buf + incr;
170 gf_font_parse_line(draw, path, &store, font, line);
gf_font_t * gf_font_create(gf_draw_t *draw, const char *path)
Load font.
gf_font_glyph_t * gf_font_get(gf_font_t *font, int code)
Get glyph.
#define gf_log_function(engine, fmt,...)
Output log with line number and function name.
#define GF_DECLARE_TYPE(n, b)
Macro to define engine type shorter.
Required headers before anything.
gf_texture_t * gf_texture_create(gf_draw_t *draw, int width, int height, unsigned char *data)
Create texture.
int dwidth[2]
Device width.
gf_font_bbox_t bbox
Bounding box.
gf_texture_t * texture
Texture.
gf_font_glyph_t ** glyph
Glyph data.
gf_font_bbox_t bbox
Bounding box.