123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include "gd.h"
- #include <string.h>
- #define PI 3.141592
- #define DEG2RAD(x) ((x)*PI/180.)
- #define MAX(x,y) ((x) > (y) ? (x) : (y))
- #define MIN(x,y) ((x) < (y) ? (x) : (y))
- #define MAX4(x,y,z,w) \
- ((MAX((x),(y))) > (MAX((z),(w))) ? (MAX((x),(y))) : (MAX((z),(w))))
- #define MIN4(x,y,z,w) \
- ((MIN((x),(y))) < (MIN((z),(w))) ? (MIN((x),(y))) : (MIN((z),(w))))
- #define MAXX(x) MAX4(x[0],x[2],x[4],x[6])
- #define MINX(x) MIN4(x[0],x[2],x[4],x[6])
- #define MAXY(x) MAX4(x[1],x[3],x[5],x[7])
- #define MINY(x) MIN4(x[1],x[3],x[5],x[7])
- int
- main (int argc, char *argv[])
- {
- #ifndef HAVE_LIBFREETYPE
- fprintf (stderr, "gd was not compiled with HAVE_LIBFREETYPE defined.\n");
- fprintf (stderr, "Install the FreeType library, including the\n");
- fprintf (stderr, "header files. Then edit the gd Makefile, type\n");
- fprintf (stderr, "make clean, and type make again.\n");
- return 1;
- #else
- gdImagePtr im;
- int black;
- int white;
- int brect[8];
- int x, y;
- char *err;
- FILE *out;
- #ifdef JISX0208
- char *s = "Hello. ‚±‚ñ‚É‚¿‚Í Qyjpqg,";
- #else
- char *s = "Hello. Qyjpqg,";
- #endif
- double sz = 40.;
- #if 0
- double angle = 0.;
- #else
- double angle = DEG2RAD (-90);
- #endif
- #ifdef JISX0208
- char *f = "/usr/openwin/lib/locale/ja/X11/fonts/TT/HG-MinchoL.ttf";
-
- #else
- char *f = "times";
- #endif
-
- err = gdImageStringFT ((gdImagePtr) NULL, &brect[0], 0, f, sz, angle, 0, 0, s);
- if (err)
- {
- fprintf (stderr, "%s", err);
- return 1;
- }
-
- x = MAXX (brect) - MINX (brect) + 6;
- y = MAXY (brect) - MINY (brect) + 6;
- #if 0
- im = gdImageCreate (500, 500);
- #else
-
- im = gdImageCreateTrueColor (x, y);
- #endif
-
- white = gdImageColorResolve (im, 255, 255, 255);
- gdImageFilledRectangle (im, 0, 0, x, y, white);
- black = gdImageColorResolve (im, 0, 0, 0);
-
- x = 0 - MINX (brect) + 3;
- y = 0 - MINY (brect) + 3;
- err = gdImageStringFT (im, NULL, black, f, sz, angle, x, y, s);
- if (err)
- {
- fprintf (stderr, "%s", err);
- return 1;
- }
-
- out = fopen ("test/fttest.png", "wb");
- if (!out)
- {
- fprintf (stderr, "Can't create test/fttest.png\n");
- exit (1);
- }
- gdImagePng (im, out);
- fclose (out);
- fprintf (stderr, "Test image written to test/fttest.png\n");
-
- gdImageDestroy (im);
- return 0;
- #endif
- }
|