~ubuntu-branches/ubuntu/maverick/ntop/maverick

« back to all changes in this revision

Viewing changes to gdchart0.94c/gd-1.8.3/gdtestttf.c

  • Committer: Bazaar Package Importer
  • Author(s): Dennis Schoen
  • Date: 2002-04-12 11:38:47 UTC
  • Revision ID: james.westby@ubuntu.com-20020412113847-4k4yydw0pzybc6g8
Tags: upstream-2.0.0
Import upstream version 2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "gd.h"
 
2
#include <string.h>
 
3
 
 
4
#define PI 3.141592
 
5
#define DEG2RAD(x) ((x)*PI/180.)
 
6
 
 
7
#define MAX(x,y) ((x) > (y) ? (x) : (y))
 
8
#define MIN(x,y) ((x) < (y) ? (x) : (y))
 
9
 
 
10
#define MAX4(x,y,z,w) \
 
11
        ((MAX((x),(y))) > (MAX((z),(w))) ? (MAX((x),(y))) : (MAX((z),(w))))
 
12
#define MIN4(x,y,z,w) \
 
13
        ((MIN((x),(y))) < (MIN((z),(w))) ? (MIN((x),(y))) : (MIN((z),(w))))
 
14
 
 
15
#define MAXX(x) MAX4(x[0],x[2],x[4],x[6])
 
16
#define MINX(x) MIN4(x[0],x[2],x[4],x[6])
 
17
#define MAXY(x) MAX4(x[1],x[3],x[5],x[7])
 
18
#define MINY(x) MIN4(x[1],x[3],x[5],x[7])
 
19
 
 
20
int main(int argc, char *argv[])
 
21
{
 
22
#ifndef HAVE_LIBTTF
 
23
        fprintf(stderr, "gd was not compiled with HAVE_LIBTTF defined.\n");
 
24
        fprintf(stderr, "Install the FreeType library, including the\n");
 
25
        fprintf(stderr, "header files. Then edit the gd Makefile, type\n");
 
26
        fprintf(stderr, "make clean, and type make again.\n");
 
27
        return 1;
 
28
#else
 
29
        gdImagePtr im;
 
30
        int black;
 
31
        int white;
 
32
        int brect[8];
 
33
        int x, y;
 
34
        char *err;
 
35
 
 
36
#ifdef JISX0208
 
37
        char *s = "Hello. ����ɂ��� Qyjpqg,"; /* String to draw. */
 
38
#else
 
39
        char *s = "Hello. Qyjpqg,"; /* String to draw. */
 
40
#endif
 
41
        double sz = 40.;
 
42
        double angle = DEG2RAD(-90);
 
43
#ifdef JISX0208
 
44
        char *f = "/usr/openwin/lib/locale/ja/X11/fonts/TT/HG-MinchoL.ttf"; /* UNICODE */
 
45
        /* char *f = "/usr/local/lib/fonts/truetype/DynaFont/dfpop1.ttf"; */ /* SJIS */
 
46
#else
 
47
        char *f = "/usr/local/lib/fonts/truetype/misc/times.ttf"; /* TrueType font */
 
48
#endif
 
49
        
 
50
        /* obtain brect so that we can size the image */
 
51
        err = gdImageStringTTF((gdImagePtr)NULL,&brect[0],0,f,sz,angle,0,0,s);
 
52
        if (err) {fprintf(stderr,err); return 1;}
 
53
 
 
54
        /* create an image just big enough for the string */
 
55
        x = MAXX(brect) - MINX(brect) + 6;
 
56
        y = MAXY(brect) - MINY(brect) + 6;
 
57
        im = gdImageCreate(x,y);
 
58
 
 
59
        /* Background color (first allocated) */
 
60
        white = gdImageColorResolve(im, 255, 255, 255);
 
61
        black = gdImageColorResolve(im, 0, 0, 0);
 
62
 
 
63
        /* render the string, offset origin to center string*/
 
64
        x = 0 - MINX(brect) + 3;
 
65
        y = 0 - MINY(brect) + 3;
 
66
        err = gdImageStringTTF(im,&brect[0],black,f,sz,angle,x,y,s);
 
67
        if (err) {fprintf(stderr,err); return 1;}
 
68
 
 
69
        /* Write img to stdout */
 
70
        gdImagePng(im, stdout);
 
71
 
 
72
        /* Destroy it */
 
73
        gdImageDestroy(im);
 
74
 
 
75
        return 0;
 
76
#endif /* HAVE_TTF */
 
77
}