bug43073.phpt 2.0 KB

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