xref: /php-src/ext/gd/tests/bug43073.phpt (revision 0b8466f2)
1--TEST--
2Bug #43073 (TrueType bounding box is wrong for angle<>0)
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7    if(!function_exists('imagettftext')) die('skip imagettftext() not available');
8    if (!(imagetypes() & IMG_PNG)) {
9        die("skip No PNG support");
10    }
11?>
12--FILE--
13<?php
14$exp = [
15    [501,400, 611,400, 611,376, 501,376],
16    [492,361, 595,319, 586,296, 483,338],
17    [470,329, 549,251, 531,233, 453,312],
18    [439,307, 481,204, 458,195, 416,297],
19    [400,299, 400,189, 376,189, 376,299],
20    [361,307, 319,204, 296,213, 338,316],
21    [329,329, 251,250, 233,267, 311,346],
22    [307,360, 204,318, 195,341, 297,383],
23    [299,400, 189,400, 189,424, 299,424],
24    [307,438, 204,480, 213,503, 316,461],
25    [329,470, 250,548, 267,566, 346,488],
26    [360,492, 318,595, 341,604, 383,502],
27    [400,501, 400,611, 424,611, 424,501],
28    [438,492, 480,595, 503,586, 461,483],
29    [470,470, 548,549, 566,532, 488,453],
30    [492,439, 595,481, 604,458, 502,416]
31];
32$cwd = __DIR__;
33$font = "$cwd/Tuffy.ttf";
34$delta_t = 360.0 / 16; # Make 16 steps around
35$g = imagecreate(800, 800);
36$bgnd  = imagecolorallocate($g, 255, 255, 255);
37$black = imagecolorallocate($g, 0, 0, 0);
38$red = imagecolorallocate($g, 255, 0, 0);
39$x = 100;
40$y = 0;
41$cos_t = cos(deg2rad($delta_t));
42$sin_t = sin(deg2rad($delta_t));
43for ($angle = 0.0, $i = 0; $angle < 360.0; $angle += $delta_t, $i++) {
44  $bbox = imagettftext($g, 24, (int)$angle, (int)(400+$x), (int)(400+$y), $black, $font, 'ABCDEF');
45  imagepolygon($g, $bbox, $red);
46  printf("%2d: ", $i);
47  for ($j = 0; $j < 8; $j++) {
48    if ($bbox[$j] >= $exp[$i][$j] - 1 && $bbox[$j] <= $exp[$i][$j] + 1) {
49        echo '.';
50    } else {
51        echo "(expected $exp[$i][$j], got $bbox[$j])";
52    }
53  }
54  echo "\n";
55  $temp = $cos_t * $x + $sin_t * $y;
56  $y    = $cos_t * $y - $sin_t * $x;
57  $x    = $temp;
58}
59imagepng($g, "$cwd/bug43073.png");
60?>
61--CLEAN--
62<?php @unlink(__DIR__ . '/bug43073.png'); ?>
63--EXPECT--
64 0: ........
65 1: ........
66 2: ........
67 3: ........
68 4: ........
69 5: ........
70 6: ........
71 7: ........
72 8: ........
73 9: ........
7410: ........
7511: ........
7612: ........
7713: ........
7814: ........
7915: ........
80