libgd/src/fontsizetest.c

85 lines
2.0 KiB
C
Raw Permalink Normal View History

2006-04-05 08:44:56 -07:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2006-04-05 08:44:17 -07:00
#include "gd.h"
2006-04-05 08:46:42 -07:00
void
dosizes (gdImagePtr im, int color, char *fontfile,
2013-04-03 05:23:11 -07:00
int x, int y, const char *string)
2006-04-05 08:44:17 -07:00
{
2013-04-03 05:23:11 -07:00
int brect[8];
double curang = 0.0;
char *cp;
int cursize;
char buf[60];
2006-04-05 08:44:17 -07:00
2013-04-03 05:23:11 -07:00
for (cursize = 1; cursize <= 20; cursize++) {
sprintf (buf, "%d: %s", cursize, string);
2006-04-05 08:44:17 -07:00
2013-04-03 05:23:11 -07:00
/* The case of newlines is taken care of in the gdImageStringTTF call */
cp =
gdImageStringFT (im, brect, color, fontfile, cursize, curang, x, y,
buf);
if (cp)
fprintf(stderr, "%s\n", cp);
2013-04-03 05:23:11 -07:00
y += cursize + 4;
2006-04-05 08:44:17 -07:00
2013-04-03 05:23:11 -07:00
/* render the same fontsize with antialiasing turned off */
cp =
gdImageStringFT (im, brect, 0 - color, fontfile, cursize, curang, x,
y, buf);
if (cp)
fprintf(stderr, "%s\n", cp);
2013-04-03 05:23:11 -07:00
y += cursize + 4;
}
2006-04-05 08:44:17 -07:00
}
2006-04-05 08:46:42 -07:00
void
dotest (char *font, int w, int h, char *string, const char *filename)
2006-04-05 08:44:17 -07:00
{
2013-04-03 05:23:11 -07:00
gdImagePtr im;
FILE *out;
int bg;
int fc;
2006-04-05 08:44:17 -07:00
2013-04-03 05:23:11 -07:00
im = gdImageCreate (w, h);
bg = gdImageColorAllocate (im, 0, 0, 0);
2006-04-05 08:44:17 -07:00
2013-04-03 05:23:11 -07:00
gdImageFilledRectangle (im, 1, 1, w - 1, h - 1, bg);
2006-04-05 08:44:17 -07:00
2013-04-03 05:23:11 -07:00
fc = gdImageColorAllocate (im, 255, 192, 192);
2006-04-05 08:44:17 -07:00
2013-04-03 05:23:11 -07:00
out = fopen (filename, "wb");
2006-04-05 08:46:42 -07:00
2013-04-03 05:23:11 -07:00
dosizes (im, fc, font, 20, 20, string);
2006-04-05 08:44:17 -07:00
#if defined(HAVE_LIBPNG)
2013-04-03 05:23:11 -07:00
gdImagePng (im, out);
2006-04-05 08:44:17 -07:00
#elif defined(HAVE_LIBJPEG)
2013-04-03 05:23:11 -07:00
gdImageJpeg (im, out, -1);
2006-04-05 08:44:17 -07:00
#endif
2013-04-03 05:23:11 -07:00
fclose (out);
2006-04-05 08:44:17 -07:00
}
2006-04-05 08:46:42 -07:00
int
main(void)
2006-04-05 08:44:17 -07:00
{
#if defined(HAVE_LIBPNG)
2013-04-03 05:23:11 -07:00
dotest ("times", 400, 600, ".....Hello, there!", "fontsizetest1.png");
dotest ("cour", 400, 600, ".....Hello, there!", "fontsizetest2.png");
dotest ("arial", 400, 600, ".....Hello, there!", "fontsizetest3.png");
dotest ("luximr", 400, 600, ".....Hello, there!", "fontsizetest4.png");
2006-04-05 08:44:17 -07:00
#elif defined(HAVE_LIBJPEG)
2013-04-03 05:23:11 -07:00
dotest ("times", 400, 600, ".....Hello, there!", "fontsizetest1.jpeg");
dotest ("cour", 400, 600, ".....Hello, there!", "fontsizetest2.jpeg");
dotest ("arial", 400, 600, ".....Hello, there!", "fontsizetest3.jpeg");
dotest ("luximr", 400, 600, ".....Hello, there!", "fontsizetest4.jpeg");
2006-04-05 08:44:17 -07:00
#else
fprintf(stderr, "no PNG or JPEG support\n");
2006-04-05 08:44:17 -07:00
#endif
2013-04-03 05:23:11 -07:00
return 0;
2006-04-05 08:44:17 -07:00
}