~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to gd/gdtestft.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
Import upstream version 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
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 fg;
 
33
  int bg;
 
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 1
 
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 = "arial";            /* TrueType font */
 
57
#endif
 
58
 
 
59
  /* obtain brect so that we can size the image */
 
60
  err = gdImageStringFT ((gdImagePtr) NULL, brect, 0, f, sz, angle, 0, 0, s);
 
61
  if (err)
 
62
    {
 
63
      fprintf (stderr, 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 1
 
71
  im = gdImageCreate (x, y);
 
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
#if 0
 
80
  bg = gdImageColorResolve (im, 255, 255, 255);
 
81
  gdImageFilledRectangle (im, 0, 0, x, y, bg);
 
82
  fg = gdImageColorResolve (im, 0, 0, 0);
 
83
#else
 
84
  bg = gdImageColorResolve (im, 0, 0, 0);
 
85
  fg = gdImageColorResolve (im, 255, 255, 255);
 
86
#endif
 
87
 
 
88
  /* render the string, offset origin to center string */
 
89
  x = 0 - MINX (brect) + 3;
 
90
  y = 0 - MINY (brect) + 3;
 
91
 
 
92
  err = gdImageStringFT (im, NULL, fg, f, sz, angle, x, y, s);
 
93
  if (err)
 
94
    {
 
95
      fprintf (stderr, err);
 
96
      return 1;
 
97
    }
 
98
  /* TBB: Write img to test/fttest.png */
 
99
  out = fopen ("test/fttest.png", "wb");
 
100
  if (!out)
 
101
    {
 
102
      fprintf (stderr, "Can't create test/fttest.png\n");
 
103
      exit (1);
 
104
    }
 
105
  gdImagePng (im, out);
 
106
  fclose (out);
 
107
  fprintf (stderr, "Test image written to test/fttest.png\n");
 
108
  /* Destroy it */
 
109
  gdImageDestroy (im);
 
110
 
 
111
  return 0;
 
112
#endif /* HAVE_FREETYPE */
 
113
}