diff options
author | horchi <vdr@jwendel.de> | 2017-03-05 16:47:41 +0100 |
---|---|---|
committer | horchi <vdr@jwendel.de> | 2017-03-05 16:47:41 +0100 |
commit | 22ffee20bbacbc3378e4ba0df5b7f0c3daaeffc0 (patch) | |
tree | de46c945c62d43d1febb027b5bfa075e58c5b69a /imlibrenderer/imlib.cc | |
download | vdr-plugin-graphtftng-22ffee20bbacbc3378e4ba0df5b7f0c3daaeffc0.tar.gz vdr-plugin-graphtftng-22ffee20bbacbc3378e4ba0df5b7f0c3daaeffc0.tar.bz2 |
Diffstat (limited to 'imlibrenderer/imlib.cc')
-rw-r--r-- | imlibrenderer/imlib.cc | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/imlibrenderer/imlib.cc b/imlibrenderer/imlib.cc new file mode 100644 index 0000000..15148a4 --- /dev/null +++ b/imlibrenderer/imlib.cc @@ -0,0 +1,81 @@ +// +// Test +// + +#include <stdlib.h> +#include <stdio.h> + +#include <Imlib2.h> + +int text(int x, int y, const char* text, const char* fontName, int size); +Imlib_Image theImage; + +//----------------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------------- + +int main(int argc, char** argv) +{ + if (argc != 4) + { + printf("Usage: imlib <text> <font-with-path> <fontsize>\n"); + return -1; + } + + theImage = imlib_create_image(600, 100); + imlib_context_set_image(theImage); + + text(10, 10, argv[1], argv[2], atoi(argv[3])); + + text(10, 50, "Test1 \n Test2", argv[2], atoi(argv[3])); + + imlib_image_set_format("png"); + imlib_save_image("test.png"); + + imlib_free_image(); + + return 0; +} + +//----------------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------------- + +int text(int x, int y, const char* text, const char* fontName, int size) +{ + char* font; + Imlib_Font theFont; + int height, width; + + if (!text || !fontName || !size) + return -1; + + asprintf(&font, "%s/%d", fontName, size); + + if (!(theFont = imlib_load_font(font))) + { + printf("Loading font '%s' failed\n", font); + free(font); + + return -1; + } + + imlib_context_set_font(theFont); + imlib_context_set_image(theImage); + imlib_context_set_color(150, 150, 150, 255); + + imlib_get_text_size(text, &width, &height); + + printf("width (%d); height (%d)\n", width, height); + printf("Ascent=%d/%d Descent=%d/%d\n", imlib_get_font_ascent(), + imlib_get_maximum_font_ascent(), imlib_get_font_descent(), + imlib_get_maximum_font_descent()); + + imlib_text_draw(x, y, text); + + imlib_free_font(); + free(font); + + return 0; +} + |