Debian Codegraph @

tests/gdimagestringft/gdimagestringft_bbox.c

raw
1 #include "gd.h"
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <math.h>
5 #include "gdtest.h"
6
7 #define PI 3.141592
8 #define DELTA (PI/8)
9
10 static int EXPECT[16][8] = {
11 {500, 400, 628, 400, 628, 376, 500, 376},
12 {492, 362, 611, 312, 601, 290, 483, 339},
13 {470, 330, 561, 239, 544, 221, 453, 312},
14 {437, 308, 486, 189, 464, 180, 414, 299},
15 {400, 301, 400, 173, 376, 173, 376, 301},
16 {363, 309, 313, 190, 291, 200, 340, 318},
17 {332, 331, 241, 240, 223, 257, 314, 348},
18 {311, 363, 192, 314, 183, 336, 302, 386},
19 {304, 399, 176, 399, 176, 423, 304, 423},
20 {312, 435, 193, 485, 203, 507, 321, 458},
21 {333, 465, 242, 556, 259, 574, 350, 483},
22 {364, 486, 315, 605, 337, 614, 387, 495},
23 {399, 492, 399, 620, 423, 620, 423, 492},
24 {434, 484, 484, 603, 506, 593, 457, 475},
25 {463, 464, 554, 555, 572, 538, 481, 447},
26 {483, 434, 602, 483, 611, 461, 492, 411},
27 };
28
29 int main()
30 {
31 char *path;
32 gdImagePtr im;
33 int black;
34 double cos_t, sin_t;
35 int x, y, temp;
36 int i, j;
37 int brect[8];
38 int error = 0;
39 FILE *fp;
40
41 /* disable subpixel hinting */
42 putenv("FREETYPE_PROPERTIES=truetype:interpreter-version=35");
43
44 path = gdTestFilePath("freetype/DejaVuSans.ttf");
45 im = gdImageCreate(800, 800);
46 gdImageColorAllocate(im, 0xFF, 0xFF, 0xFF); /* allocate white for background color */
47 black = gdImageColorAllocate(im, 0, 0, 0);
48 cos_t = cos(DELTA);
49 sin_t = sin(DELTA);
50 x = 100;
51 y = 0;
52 for (i = 0; i < 16; i++) {
53 if (gdImageStringFT(im, brect, black, path, 24, DELTA*i, 400+x, 400+y, "ABCDEF")) {
54 error = 1;
55 goto done;
56 }
57 for (j = 0; j < 8; j++) {
58 if (brect[j] < EXPECT[i][j] - 1 || brect[j] > EXPECT[i][j] + 1) {
59 gdTestErrorMsg("(%d, %d) (%d, %d) (%d, %d) (%d, %d) expected, but (%d, %d) (%d, %d) (%d, %d) (%d, %d)\n",
60 EXPECT[i][0], EXPECT[i][1], EXPECT[i][2], EXPECT[i][3],
61 EXPECT[i][4], EXPECT[i][5], EXPECT[i][6], EXPECT[i][7],
62 brect[0], brect[1], brect[2], brect[3],
63 brect[4], brect[5], brect[6], brect[7]);
64 error = 1;
65 goto done;
66 }
67 }
68 gdImagePolygon(im, (gdPointPtr)brect, 4, black);
69 gdImageFilledEllipse(im, brect[0], brect[1], 8, 8, black);
70 temp = (int)(cos_t * x + sin_t * y);
71 y = (int)(cos_t * y - sin_t * x);
72 x = temp;
73 }
74 fp = gdTestTempFp();
75 gdImagePng(im, fp);
76 fclose(fp);
77 done:
78 gdImageDestroy(im);
79 gdFontCacheShutdown();
80 free(path);
81 return error;
82 }