tabe                                     Mon, 27 Jul 2009 15:06:28 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=286416

Log:
MFH: 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/branches/PHP_5_3/ext/gd/libgd/gdft.c
    U   php/php-src/branches/PHP_5_3/ext/gd/tests/bug48555.phpt
    A   php/php-src/branches/PHP_5_3/ext/gd/tests/bug48732.phpt
    A   php/php-src/branches/PHP_5_3/ext/gd/tests/bug48801.phpt

Modified: php/php-src/branches/PHP_5_3/ext/gd/libgd/gdft.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/gd/libgd/gdft.c    2009-07-27 15:02:15 UTC 
(rev 286415)
+++ php/php-src/branches/PHP_5_3/ext/gd/libgd/gdft.c    2009-07-27 15:06:28 UTC 
(rev 286416)
@@ -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/branches/PHP_5_3/ext/gd/tests/bug48555.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/gd/tests/bug48555.phpt     2009-07-27 
15:02:15 UTC (rev 286415)
+++ php/php-src/branches/PHP_5_3/ext/gd/tests/bug48555.phpt     2009-07-27 
15:06:28 UTC (rev 286416)
@@ -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/branches/PHP_5_3/ext/gd/tests/bug48732.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/gd/tests/bug48732.phpt                     
        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/gd/tests/bug48732.phpt     2009-07-27 
15:06:28 UTC (rev 286416)
@@ -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/branches/PHP_5_3/ext/gd/tests/bug48801.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/gd/tests/bug48801.phpt                     
        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/gd/tests/bug48801.phpt     2009-07-27 
15:06:28 UTC (rev 286416)
@@ -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)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to