From: Takeshi Abe Date: Mon, 27 Jul 2009 15:06:28 +0000 (+0000) Subject: MFH: fixed #48732 (TTF Bounding box wrong for letters below baseline) and #48801... X-Git-Tag: php-5.3.1RC1~249 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=366c261cce7ac0107ec24fa933d61e2369281947;p=php MFH: fixed #48732 (TTF Bounding box wrong for letters below baseline) and #48801 (Problem with imagettfbbox) --- diff --git a/ext/gd/libgd/gdft.c b/ext/gd/libgd/gdft.c index 73cbb8dce0..ffac3ebf6b 100644 --- a/ext/gd/libgd/gdft.c +++ b/ext/gd/libgd/gdft.c @@ -785,6 +785,7 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsi 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 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsi } #endif + i = 0; while (*next) { ch = *next; @@ -934,6 +936,7 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsi } /* 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 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsi 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 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsi 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 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsi 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); diff --git a/ext/gd/tests/bug48555.phpt b/ext/gd/tests/bug48555.phpt index 24b142a279..c259501e3a 100644 --- a/ext/gd/tests/bug48555.phpt +++ b/ext/gd/tests/bug48555.phpt @@ -15,5 +15,5 @@ $box = ImageFTBBox(13, 0, $font, "Text with\nline-break\none more"); 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 diff --git a/ext/gd/tests/bug48732.phpt b/ext/gd/tests/bug48732.phpt new file mode 100644 index 0000000000..d4c90113a1 --- /dev/null +++ b/ext/gd/tests/bug48732.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #48732 (TTF Bounding box wrong for letters below baseline) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Left Bottom: (0, 47) \ No newline at end of file diff --git a/ext/gd/tests/bug48801.phpt b/ext/gd/tests/bug48801.phpt new file mode 100644 index 0000000000..a6a9874ab8 --- /dev/null +++ b/ext/gd/tests/bug48801.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #48801 (Problem with imagettfbbox) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +(-1, 15) +(155, 15) +(155, -48) +(-1, -48)