summaryrefslogtreecommitdiff
path: root/imlibrenderer/imlib.cc
blob: 15148a432e7642466ff863cb256e748956f3b30f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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;
}