mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-01 07:24:58 +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:
parent
67a3ecc798
commit
3ef4fb3ca2
@ -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;
|
||||||
|
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user