svn: /php/php-src/trunk/ext/gd/ libgd/gdft.c tests/bug43073.phpt tests/bug48555.phpt tests/bug48732.phpt tests/bug48801.phpt
| From: | Takeshi Abe | Date: | Mon, 27 Jul 2009 15:02:15 +0000 |
| Subject: | svn: /php/php-src/trunk/ext/gd/ libgd/gdft.c tests/bug43073.phpt tests/bug48555.phpt tests/bug48732.phpt tests/bug48801.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-59855@lists.php.net to get a copy of this message | ||
tabe Mon, 27 Jul 2009 15:02:15 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=286415
Log:
fixed #48732 (TTF Bounding box wrong for letters below baseline) and #48801 (Problem with
imagettfbbox)
Bugs: http://bugs.php.net/48732 (Assigned) TTF Bounding box
wrong for letters below baseline
http://bugs.php.net/48801 (Open) Problem with
imagettfbbox
Changed paths:
U php/php-src/trunk/ext/gd/libgd/gdft.c
U php/php-src/trunk/ext/gd/tests/bug43073.phpt
U php/php-src/trunk/ext/gd/tests/bug48555.phpt
A php/php-src/trunk/ext/gd/tests/bug48732.phpt
A php/php-src/trunk/ext/gd/tests/bug48801.phpt
Modified: php/php-src/trunk/ext/gd/libgd/gdft.c
===================================================================
--- php/php-src/trunk/ext/gd/libgd/gdft.c 2009-07-27 14:52:48 UTC (rev 286414)
+++ php/php-src/trunk/ext/gd/libgd/gdft.c 2009-07-27 15:02:15 UTC (rev 286415)
@@ -785,6 +785,7 @@
int len, i = 0, ch;
int x1 = 0, y1 = 0;
int xb = x, yb = y;
+ int yd = 0;
font_t *font;
fontkey_t fontkey;
char *next;
@@ -919,6 +920,7 @@
}
#endif
+ i = 0;
while (*next) {
ch = *next;
@@ -934,6 +936,7 @@
}
/* newlines */
if (ch == '\n') {
+ if (!*(++next)) break;
/* 2.0.13: reset penf.x. Christopher J. Grayce */
penf.x = 0;
penf.y -= (long)(face->size->metrics.height * linespace);
@@ -942,9 +945,9 @@
y1 = (int)(- penf.y * cos_a + 32) / 64;
xb = x + x1;
yb = y + y1;
+ yd = 0;
pen.x = pen.y = 0;
previous = 0; /* clear kerning flag */
- next++;
continue;
}
@@ -1058,11 +1061,17 @@
glyph_bbox.xMax += slot->metrics.horiAdvance;
}
if (!i) { /* if first character, init BB corner values */
+ yd = slot->metrics.height - slot->metrics.horiBearingY;
bbox.xMin = glyph_bbox.xMin;
bbox.yMin = glyph_bbox.yMin;
bbox.xMax = glyph_bbox.xMax;
bbox.yMax = glyph_bbox.yMax;
} else {
+ FT_Pos desc;
+
+ if ( (desc = (slot->metrics.height - slot->metrics.horiBearingY)) > yd) {
+ yd = desc;
+ }
if (bbox.xMin > glyph_bbox.xMin) {
bbox.xMin = glyph_bbox.xMin;
}
@@ -1119,15 +1128,18 @@
normbox.xMax = bbox.xMax - bbox.xMin;
normbox.yMax = bbox.yMax - bbox.yMin;
+ brect[0] = brect[2] = brect[4] = brect[6] = (int) (yd * sin_a);
+ brect[1] = brect[3] = brect[5] = brect[7] = (int)(- yd * cos_a);
+
/* rotate bounding rectangle */
- brect[0] = (int) (normbox.xMin * cos_a - normbox.yMin * sin_a);
- brect[1] = (int) (normbox.xMin * sin_a + normbox.yMin * cos_a);
- brect[2] = (int) (normbox.xMax * cos_a - normbox.yMin * sin_a);
- brect[3] = (int) (normbox.xMax * sin_a + normbox.yMin * cos_a);
- brect[4] = (int) (normbox.xMax * cos_a - normbox.yMax * sin_a);
- brect[5] = (int) (normbox.xMax * sin_a + normbox.yMax * cos_a);
- brect[6] = (int) (normbox.xMin * cos_a - normbox.yMax * sin_a);
- brect[7] = (int) (normbox.xMin * sin_a + normbox.yMax * cos_a);
+ brect[0] += (int) (normbox.xMin * cos_a - normbox.yMin * sin_a);
+ brect[1] += (int) (normbox.xMin * sin_a + normbox.yMin * cos_a);
+ brect[2] += (int) (normbox.xMax * cos_a - normbox.yMin * sin_a);
+ brect[3] += (int) (normbox.xMax * sin_a + normbox.yMin * cos_a);
+ brect[4] += (int) (normbox.xMax * cos_a - normbox.yMax * sin_a);
+ brect[5] += (int) (normbox.xMax * sin_a + normbox.yMax * cos_a);
+ brect[6] += (int) (normbox.xMin * cos_a - normbox.yMax * sin_a);
+ brect[7] += (int) (normbox.xMin * sin_a + normbox.yMax * cos_a);
/* scale, round and offset brect */
brect[0] = xb + gdroundupdown(brect[0], d2 > 0);
Modified: php/php-src/trunk/ext/gd/tests/bug43073.phpt
===================================================================
--- php/php-src/trunk/ext/gd/tests/bug43073.phpt 2009-07-27 14:52:48 UTC (rev 286414)
+++ php/php-src/trunk/ext/gd/tests/bug43073.phpt 2009-07-27 15:02:15 UTC (rev 286415)
@@ -8,7 +8,7 @@
--FILE--
<?php
$cwd = dirname(__FILE__);
-$font = "$cwd/test8859.ttf";
+$font = "$cwd/Tuffy.ttf";
$delta_t = 360.0 / 16; # Make 16 steps around
$g = imagecreate(800, 800);
$bgnd = imagecolorallocate($g, 255, 255, 255);
@@ -25,21 +25,22 @@
$y = $cos_t * $y - $sin_t * $x;
$x = $temp;
}
+imagepng($g, "$cwd/bug43073.png");
?>
--EXPECTF--
-(500, 400), (579, 400), (579, 370), (500, 370)
-(492, 361), (575, 327), (564, 301), (480, 335)
-(470, 329), (540, 260), (521, 242), (451, 312)
-(438, 307), (478, 210), (461, 204), (420, 301)
-(400, 300), (400, 193), (383, 193), (383, 300)
-(361, 307), (319, 207), (297, 216), (338, 317)
-(329, 329), (254, 254), (233, 275), (307, 351)
-(307, 361), (215, 323), (203, 354), (294, 392)
-(300, 400), (203, 400), (203, 431), (300, 431)
-(307, 438), (219, 474), (229, 501), (318, 465)
-(329, 470), (263, 535), (281, 553), (347, 489)
-(361, 492), (326, 575), (343, 582), (378, 499)
-(400, 500), (400, 584), (416, 584), (416, 500)
-(438, 492), (468, 567), (490, 559), (460, 483)
-(470, 470), (523, 525), (545, 505), (491, 449)
-(492, 438), (560, 467), (572, 436), (504, 408)
+(500, 402), (610, 402), (610, 376), (500, 376)
+(492, 363), (591, 322), (580, 295), (480, 336)
+(470, 331), (548, 254), (527, 233), (449, 310)
+(439, 309), (483, 202), (461, 193), (416, 299)
+(401, 300), (401, 183), (381, 183), (381, 300)
+(362, 307), (316, 195), (291, 205), (337, 318)
+(330, 329), (246, 244), (224, 265), (308, 350)
+(308, 360), (202, 316), (190, 344), (296, 388)
+(300, 399), (186, 399), (186, 425), (300, 425)
+(306, 437), (195, 483), (206, 510), (318, 464)
+(328, 469), (240, 557), (260, 578), (349, 491)
+(359, 491), (312, 607), (334, 616), (382, 501)
+(398, 500), (398, 618), (418, 618), (418, 500)
+(436, 493), (483, 607), (507, 597), (461, 482)
+(468, 471), (555, 558), (577, 538), (490, 450)
+(490, 440), (600, 485), (611, 457), (502, 412)
Modified: php/php-src/trunk/ext/gd/tests/bug48555.phpt
===================================================================
--- php/php-src/trunk/ext/gd/tests/bug48555.phpt 2009-07-27 14:52:48 UTC (rev 286414)
+++ php/php-src/trunk/ext/gd/tests/bug48555.phpt 2009-07-27 15:02:15 UTC (rev 286415)
@@ -15,5 +15,5 @@
echo 'Top with line-break: ' . $box[7] . "\n";
?>
--EXPECTF--
-Top without line-break: -15
-Top with line-break: -15
+Top without line-break: -14
+Top with line-break: -14
Added: php/php-src/trunk/ext/gd/tests/bug48732.phpt
===================================================================
--- php/php-src/trunk/ext/gd/tests/bug48732.phpt (rev 0)
+++ php/php-src/trunk/ext/gd/tests/bug48732.phpt 2009-07-27 15:02:15 UTC (rev 286415)
@@ -0,0 +1,20 @@
+--TEST--
+Bug #48732 (TTF Bounding box wrong for letters below baseline)
+--SKIPIF--
+<?php
+ if(!extension_loaded('gd')){ die('skip gd extension not available'); }
+ if(!function_exists('imagefttext')) die('skip imagefttext() not available');
+?>
+--FILE--
+<?php
+$cwd = dirname(__FILE__);
+$font = "$cwd/Tuffy.ttf";
+$g = imagecreate(100, 50);
+$bgnd = imagecolorallocate($g, 255, 255, 255);
+$black = imagecolorallocate($g, 0, 0, 0);
+$bbox = imagettftext($g, 12, 0, 0, 20, $black, $font, "ABCEDFGHIJKLMN\nopqrstu\n");
+imagepng($g, "$cwd/bug48732.png");
+echo 'Left Bottom: (' . $bbox[0] . ', ' . $bbox[1] . ')';
+?>
+--EXPECTF--
+Left Bottom: (0, 47)
\ No newline at end of file
Added: php/php-src/trunk/ext/gd/tests/bug48801.phpt
===================================================================
--- php/php-src/trunk/ext/gd/tests/bug48801.phpt (rev 0)
+++ php/php-src/trunk/ext/gd/tests/bug48801.phpt 2009-07-27 15:02:15 UTC (rev 286415)
@@ -0,0 +1,22 @@
+--TEST--
+Bug #48801 (Problem with imagettfbbox)
+--SKIPIF--
+<?php
+ if(!extension_loaded('gd')){ die('skip gd extension not available'); }
+ if(!function_exists('imageftbbox')) die('skip imageftbbox() not available');
+?>
+--FILE--
+<?php
+$cwd = dirname(__FILE__);
+$font = "$cwd/Tuffy.ttf";
+$bbox = imageftbbox(50, 0, $font, "image");
+echo '(' . $bbox[0] . ', ' . $bbox[1] . ")\n";
+echo '(' . $bbox[2] . ', ' . $bbox[3] . ")\n";
+echo '(' . $bbox[4] . ', ' . $bbox[5] . ")\n";
+echo '(' . $bbox[6] . ', ' . $bbox[7] . ")\n";
+?>
+--EXPECTF--
+(-1, 15)
+(155, 15)
+(155, -48)
+(-1, -48)