*** empty log message ***
[m17n/m17n-test.git] / pangotest.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <unistd.h>
6 #include <string.h>
7 #include <pango/pango.h>
8 #include <pango/pangocairo.h>
9
10 int
11 main (int argc, char **argv)
12 {
13   FILE *fp;
14   struct stat statbuf;
15   char *buf;
16   size_t nbytes;
17   PangoFontMap *fontmap;
18   PangoContext *context;
19   PangoLayout *layout;
20   int width, height;
21   int count = 1;
22
23   if (argc < 2)
24     {
25       fprintf (stderr, "Usage: viewfile FILENAME [COUNT]\n");
26       exit (1);
27     }
28   if (argc > 2)
29     count = atoi (argv[2]);
30
31   if (stat (argv[1], &statbuf) != 0
32       || ! (fp = fopen (argv[1], "r")))
33     {
34       fprintf (stderr, "Can't open \"%s\"\n", argv[1]);
35       exit (1);
36     }
37   buf = alloca (statbuf.st_size + 1);
38   fread (buf, 1, statbuf.st_size, fp);
39   fclose (fp);
40   buf[statbuf.st_size] = '\0';
41
42   fontmap = pango_cairo_font_map_get_default ();
43   context = pango_cairo_font_map_create_context ((PangoCairoFontMap *) fontmap);
44   layout = pango_layout_new (context);
45   while (count-- > 0)
46     {
47       int w, h;
48
49       pango_layout_set_text (layout, buf, statbuf.st_size);
50       pango_layout_get_pixel_size (layout, &width, &height);
51       pango_layout_set_text (layout, "abc", 3);
52       pango_layout_get_pixel_size (layout, &w, &h);
53     }
54   printf ("%dx%d\n", width, height);
55   exit (0);
56 }