diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-17 17:49:27 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-17 17:49:27 (EDT) |
commit | e0a9d32f969a384dcace05531a244aa84bb06595 (patch) | |
tree | 85074db40ed4d25888af9a2f8d93cd7d8a800cb8 | |
parent | ebcbcbbb38bb9e8caee0197575bbe97f28e40b1d (diff) |
font_find(): New function
-rw-r--r-- | src/font.c | 56 | ||||
-rw-r--r-- | src/font.h | 32 | ||||
-rw-r--r-- | src/local.mk | 1 | ||||
-rw-r--r-- | src/main.c | 9 |
4 files changed, 95 insertions, 3 deletions
diff --git a/src/font.c b/src/font.c new file mode 100644 index 0000000..f110a23 --- /dev/null +++ b/src/font.c @@ -0,0 +1,56 @@ +/* + * Font lookup and rendering functions + * + * Copyright (C) 2019 Patrick McDermott + * + * This file is part of fbcon2png. + * + * fbcon2png is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * fbcon2png is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with fbcon2png. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "font.h" + +#include <string.h> + +#include <png.h> + +#include <linux/font.h> + +struct font { + const struct font_desc desc; +}; + +static const struct font_desc *fonts[] = { + &font_mplus_1mn_medium_10x14, + &font_mplus_1mn_regular_12x17, + &font_mplus_1mn_regular_14x19, + &font_mplus_1mn_regular_16x22, +}; + +struct font * +font_find(const char *name) +{ + size_t i; + + if (!name) { + return (struct font *) fonts[0]; + } + + for (i = 0; i < *(&fonts + 1) - fonts; ++i) { + if (strcmp(fonts[i]->name, name) == 0) { + return (struct font *) fonts[i]; + } + } + return (struct font *) fonts[0]; +} diff --git a/src/font.h b/src/font.h new file mode 100644 index 0000000..cf9276a --- /dev/null +++ b/src/font.h @@ -0,0 +1,32 @@ +/* + * Font lookup and rendering functions + * + * Copyright (C) 2019 Patrick McDermott + * + * This file is part of fbcon2png. + * + * fbcon2png is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * fbcon2png is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with fbcon2png. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef FONT_H +#define FONT_H + +#include <png.h> + +#include <linux/font.h> + +struct font * +font_find(const char *name) __attribute__((pure)); + +#endif /* FONT_H */ diff --git a/src/local.mk b/src/local.mk index 397a9a2..43f5c4a 100644 --- a/src/local.mk +++ b/src/local.mk @@ -1,4 +1,5 @@ fbcon2png_SOURCES += \ + %reldir%/font.c \ %reldir%/image.c \ %reldir%/main.c \ %reldir%/text.c @@ -19,20 +19,23 @@ * along with fbcon2png. If not, see <http://www.gnu.org/licenses/>. */ -#include "text.h" +#include "font.h" #include "image.h" +#include "text.h" int main(int argc, char **argv) { + struct font *font; struct text *text; struct image *image; - if (argc != 2) { + if (argc != 3) { return 1; } - text = text_new(argv[1]); + font = font_find(argv[1]); + text = text_new(argv[2]); image = image_new("test.png"); image_render(image, text); text_destroy(&text); |