[BUGFIX] Random miscalculations in ImageTTFBBox
authorAlbrecht Koehnlein <typo3@bestof1983.de>
Wed, 13 Jul 2011 09:47:21 +0000 (11:47 +0200)
committerJigal van Hemert <jigal@xs4all.nl>
Fri, 16 Dec 2011 20:38:00 +0000 (21:38 +0100)
ImageTTFBBox() randomly returns incorrect negative values. Repeat the operation
a number of time if this happens to try to find the correct values.

Change-Id: Ic7367345c786148674fe83331b9fff368546038c
Fixes: #21054
Releases: 4.6, 4.5, 4.4
Reviewed-on: http://review.typo3.org/7119
Reviewed-by: Simon Schaufelberger
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
t3lib/class.t3lib_stdgraphic.php

index 6a71aa2..ff3ed7d 100644 (file)
@@ -946,8 +946,21 @@ class t3lib_stdGraphic {
                        $fontFile = t3lib_stdGraphic::prependAbsolutePath($strCfg['fontFile']);
                        if (is_readable($fontFile)) {
 
-                                       // Calculate Bounding Box for part:
-                               $calc = ImageTTFBBox(t3lib_div::freetypeDpiComp($sF * $strCfg['fontSize']), $angle, $fontFile, $strCfg['str']);
+                               /**
+                                * Calculate Bounding Box for part.
+                                * Due to a PHP bug, we must retry if $calc[2] is negative.
+                                * @see https://bugs.php.net/bug.php?id=51315
+                                * @see https://bugs.php.net/bug.php?id=22513
+                                */
+                               $try = 0;
+                               do {
+                                       $calc = ImageTTFBBox(
+                                               t3lib_div::freetypeDpiComp($sF * $strCfg['fontSize']),
+                                               $angle,
+                                               $fontFile,
+                                               $strCfg['str']
+                                       );
+                               } while ($calc[2] < 0 && $try++ < 10);
 
                                        // Calculate offsets:
                                if (!count($offsetInfo)) {