Skip to content

Commit 9a73e1c

Browse files
author
Takeshi Abe
committed
Bug #49600 (imageTTFText text shifted right)
- fix difference of horizontal position between imagettftext() and imagettfbbox()
1 parent 00c5ca7 commit 9a73e1c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

ext/gd/libgd/gdft.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsi
11011101

11021102
/* now, draw to our target surface */
11031103
bm = (FT_BitmapGlyph) image;
1104-
gdft_draw_bitmap(tc_cache, im, fg, bm->bitmap, x + x1 + ((pen.x + 31) >> 6) + bm->left, y + y1 + ((pen.y + 31) >> 6) - bm->top);
1104+
gdft_draw_bitmap(tc_cache, im, fg, bm->bitmap, x + x1 + ((pen.x + 31) >> 6), y + y1 + ((pen.y + 31) >> 6) - bm->top);
11051105
}
11061106

11071107
/* record current glyph index for kerning */

ext/gd/tests/bug49600.phpt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
Bug #49600 (imageTTFText text shifted right)
3+
--SKIPIF--
4+
<?php
5+
if(!extension_loaded('gd')){ die('skip gd extension not available'); }
6+
if(!function_exists('imagettftext')) die('skip imagettftext() not available');
7+
if(!function_exists('imagettfbbox')) die('skip imagettfbbox() not available');
8+
?>
9+
--FILE--
10+
<?php
11+
$cwd = dirname(__FILE__);
12+
$font = "$cwd/Tuffy.ttf";
13+
$image = imagecreatetruecolor(50, 50);
14+
$color = imagecolorallocate($image, 255, 255, 255);
15+
foreach (array("E", "I", "P", "g", "i", "q") as $c)
16+
{
17+
$x = imagettftext($image, 32, 0, 0, 0, $color, $font, $c);
18+
$y = imagettfbbox(32, 0, "$cwd/Tuffy.ttf", $c);
19+
if ( abs($x[0] - $y[0]) > 1
20+
|| abs($x[2] - $y[2]) > 1
21+
|| abs($x[4] - $y[4]) > 1
22+
|| abs($x[6] - $y[6]) > 1 ) {
23+
echo "FAILED: \n";
24+
var_dump($x);
25+
var_dump($y);
26+
exit;
27+
}
28+
}
29+
echo 'OK';
30+
?>
31+
--EXPECTF--
32+
OK

0 commit comments

Comments
 (0)