1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-25 17:43:44 +02:00

tools/libtxt/: make_font takes ownership of the image

This way, we don't need to track/free the image separately.
This commit is contained in:
Werner Almesberger 2012-06-30 11:43:13 -03:00
parent 67a3ecc798
commit 3ef4fb3ca2
2 changed files with 7 additions and 6 deletions

View File

@ -40,7 +40,7 @@ struct image {
}; };
struct font { struct font {
const struct image *img; struct image *img;
struct sym sym[CHARS]; struct sym sym[CHARS];
}; };
@ -143,7 +143,7 @@ struct image *load_image(const char *name, const char **error)
if (err) { if (err) {
if (error) if (error)
*error = err; *error = err;
free(img); free_image(img);
return NULL; return NULL;
} }
return img; return img;
@ -216,7 +216,7 @@ static const char *analyze_font(struct font *font)
} }
struct font *make_font(const struct image *img, const char **error) struct font *make_font(struct image *img, const char **error)
{ {
struct font *font; struct font *font;
const char *err; const char *err;
@ -229,7 +229,7 @@ struct font *make_font(const struct image *img, const char **error)
if (err) { if (err) {
if (error) if (error)
*error = err; *error = err;
free(font); free_font(font);
return NULL; return NULL;
} }
return font; return font;
@ -238,6 +238,7 @@ struct font *make_font(const struct image *img, const char **error)
void free_font(struct font *font) void free_font(struct font *font)
{ {
free_image(font->img);
free(font); free(font);
} }
@ -300,7 +301,7 @@ int char_height(const struct font *font, char c)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct font *font; struct font *font;
const struct image *img; struct image *img;
const char *error; const char *error;
uint8_t canvas[W*H/8] = { 0 }; uint8_t canvas[W*H/8] = { 0 };
char *s; char *s;

View File

@ -53,7 +53,7 @@ struct edit {
struct image *load_image(const char *name, const char **error); struct image *load_image(const char *name, const char **error);
void free_image(struct image *img); void free_image(struct image *img);
struct font *make_font(const struct image *img, const char **error); struct font *make_font(struct image *img, const char **error);
void free_font(struct font *font); void free_font(struct font *font);
int draw_char(void *canvas, int width, int height, int draw_char(void *canvas, int width, int height,