src/font.c: finish implementations
parent
e549ce7332
commit
5c83c9e89e
27
src/font.c
27
src/font.c
|
@ -20,9 +20,9 @@ font_t font_create(char *name, char *filename) {
|
||||||
toml_table_t *table = toml_parse_file(fp);
|
toml_table_t *table = toml_parse_file(fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
#define TOML_GET_KEY((var, key, func)) toml_datum_t *(var) = func(table, key);\
|
#define TOML_GET_KEY((var, key, func)) toml_datum_t *(var) = func(table, (key));\
|
||||||
if (!var.ok) {\
|
if (!(var).ok) {\
|
||||||
error("key '" key "' missing from", filename); \
|
error("key '" (key) "' missing from", filename); \
|
||||||
}
|
}
|
||||||
|
|
||||||
TOML_GET_KEY(name, "name", toml_string_in)
|
TOML_GET_KEY(name, "name", toml_string_in)
|
||||||
|
@ -42,10 +42,17 @@ font_t font_create(char *name, char *filename) {
|
||||||
font.width = width;
|
font.width = width;
|
||||||
font.height = height;
|
font.height = height;
|
||||||
font.map_entries = map_create(mapping, *map);
|
font.map_entries = map_create(mapping, *map);
|
||||||
|
font.map = map;
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void font_destroy(font_t font) {
|
||||||
|
map_destroy(font.map);
|
||||||
|
free(font.name);
|
||||||
|
free(font.filename);
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int map_create(toml_table_t *table, map_t **map) {
|
unsigned int map_create(toml_table_t *table, map_t **map) {
|
||||||
map_t *node;
|
map_t *node;
|
||||||
map_t *next;
|
map_t *next;
|
||||||
|
@ -82,4 +89,18 @@ unsigned int map_create(toml_table_t *table, map_t **map) {
|
||||||
node->next = next;
|
node->next = next;
|
||||||
node = next;
|
node = next;
|
||||||
}
|
}
|
||||||
|
node->next = NULL;
|
||||||
|
|
||||||
|
*map = root;
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void map_destroy(map_t *map) {
|
||||||
|
map_t *node = map;
|
||||||
|
map_t *next;
|
||||||
|
|
||||||
|
while ((next = node->next) != NULL) {
|
||||||
|
free(node);
|
||||||
|
node = next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,3 +15,8 @@ typedef struct {
|
||||||
unsigned int map_entries;
|
unsigned int map_entries;
|
||||||
map_t *map;
|
map_t *map;
|
||||||
} font_t;
|
} font_t;
|
||||||
|
|
||||||
|
font_t font_create(char *name, char *filename);
|
||||||
|
void font_destroy(font_t font);
|
||||||
|
unsigned int map_create(toml_table_t *table, map_t **map);
|
||||||
|
void map_destroy(map_t *map);
|
||||||
|
|
Loading…
Reference in New Issue