1 
2 #include "gd.h"
3 #include <string.h>
4 
5 #define PI 3.141592
6 #define DEG2RAD(x) ((x)*PI/180.)
7 
8 #define MAX(x,y) ((x) > (y) ? (x) : (y))
9 #define MIN(x,y) ((x) < (y) ? (x) : (y))
10 
11 #define MAX4(x,y,z,w) \
12 	((MAX((x),(y))) > (MAX((z),(w))) ? (MAX((x),(y))) : (MAX((z),(w))))
13 #define MIN4(x,y,z,w) \
14 	((MIN((x),(y))) < (MIN((z),(w))) ? (MIN((x),(y))) : (MIN((z),(w))))
15 
16 #define MAXX(x) MAX4(x[0],x[2],x[4],x[6])
17 #define MINX(x) MIN4(x[0],x[2],x[4],x[6])
18 #define MAXY(x) MAX4(x[1],x[3],x[5],x[7])
19 #define MINY(x) MIN4(x[1],x[3],x[5],x[7])
20 
21 int
main(int argc,char * argv[])22 main (int argc, char *argv[])
23 {
24 #ifndef HAVE_LIBFREETYPE
25   fprintf (stderr, "gd was not compiled with HAVE_LIBFREETYPE defined.\n");
26   fprintf (stderr, "Install the FreeType library, including the\n");
27   fprintf (stderr, "header files. Then edit the gd Makefile, type\n");
28   fprintf (stderr, "make clean, and type make again.\n");
29   return 1;
30 #else
31   gdImagePtr im;
32   int black;
33   int white;
34   int brect[8];
35   int x, y;
36   char *err;
37   FILE *out;
38 #ifdef JISX0208
39   char *s = "Hello. ����ɂ��� Qyjpqg,";	/* String to draw. */
40 #else
41   char *s = "Hello. Qyjpqg,";	/* String to draw. */
42 #endif
43 
44   double sz = 40.;
45 
46 #if 0
47   double angle = 0.;
48 #else
49   double angle = DEG2RAD (-90);
50 #endif
51 
52 #ifdef JISX0208
53   char *f = "/usr/openwin/lib/locale/ja/X11/fonts/TT/HG-MinchoL.ttf";	/* UNICODE */
54   /* char *f = "/usr/local/lib/fonts/truetype/DynaFont/dfpop1.ttf"; *//* SJIS */
55 #else
56   char *f = "times";		/* TrueType font */
57 #endif
58 
59   /* obtain brect so that we can size the image */
60   err = gdImageStringFT ((gdImagePtr) NULL, &brect[0], 0, f, sz, angle, 0, 0, s);
61   if (err)
62     {
63       fprintf (stderr, "%s", err);
64       return 1;
65     }
66 
67   /* create an image just big enough for the string */
68   x = MAXX (brect) - MINX (brect) + 6;
69   y = MAXY (brect) - MINY (brect) + 6;
70 #if 0
71   im = gdImageCreate (500, 500);
72 #else
73   /* gd 2.0: true color images can use freetype too */
74   im = gdImageCreateTrueColor (x, y);
75 #endif
76 
77   /* Background color. gd 2.0: fill the image with it; truecolor
78      images have a black background otherwise. */
79   white = gdImageColorResolve (im, 255, 255, 255);
80   gdImageFilledRectangle (im, 0, 0, x, y, white);
81   black = gdImageColorResolve (im, 0, 0, 0);
82 
83   /* render the string, offset origin to center string */
84   x = 0 - MINX (brect) + 3;
85   y = 0 - MINY (brect) + 3;
86 
87   err = gdImageStringFT (im, NULL, black, f, sz, angle, x, y, s);
88   if (err)
89     {
90       fprintf (stderr, "%s", err);
91       return 1;
92     }
93   /* TBB: Write img to test/fttest.png */
94   out = fopen ("test/fttest.png", "wb");
95   if (!out)
96     {
97       fprintf (stderr, "Can't create test/fttest.png\n");
98       exit (1);
99     }
100   gdImagePng (im, out);
101   fclose (out);
102   fprintf (stderr, "Test image written to test/fttest.png\n");
103   /* Destroy it */
104   gdImageDestroy (im);
105 
106   return 0;
107 #endif /* HAVE_FREETYPE */
108 }
109