1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-22 14:05:20 +02:00

tools/libtxt/: add font search path (untested)

This commit is contained in:
Werner Almesberger 2012-07-01 20:59:49 -03:00
parent 236ef1dad0
commit 685cd809db
2 changed files with 51 additions and 1 deletions

View File

@ -23,6 +23,54 @@
/* ----- Render a list of editing instructions ----------------------------- */
struct font_dir {
const char *name;
struct font_dir *next;
} *font_path = NULL, **last_font_dir = &font_path;
void add_font_dir(const char *name)
{
struct font_dir *dir;
dir = alloc_type(struct font_dir);
dir->name = strdup(name);
if (!dir->name)
abort();
dir->next = NULL;
*last_font_dir = dir;
last_font_dir = &dir->next;
}
static struct image *find_font_image(const char *name, const char **error)
{
struct image *img;
const char *err;
const struct font_dir *dir;
FILE *file;
char *path;
img = load_image(name, error);
if (img)
return img;
if (error)
err = *error;
for (dir = font_path; dir; dir = dir->next) {
asprintf(&path, "%s/%s.xbm", dir->name, name);
file = fopen(path, "r");
if (!file)
continue;
img = load_image_file(file, error);
fclose(file);
return img;
}
if (error)
*error = err;
return NULL;
}
static int do_edit(uint8_t *canvas, int width, int height,
const struct edit *e, const char **error)
{
@ -47,7 +95,7 @@ static int do_edit(uint8_t *canvas, int width, int height,
break;
case edit_font:
free_font(font);
img = load_image(e->u.s, error);
img = find_font_image(e->u.s, error);
if (!img)
return 0;
font = make_font(img, error);

View File

@ -72,6 +72,8 @@ struct edit *text2edit(const char *s);
char *edit2text(const struct edit *e);
void free_edit(struct edit *e);
void add_font_dir(const char *name);
void *apply_edits(int width, int height, const struct edit *e,
const char **error);