[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>
Thu, 6 Oct 2011 22:05:21 +0000 (00:05 +0200)
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: I6c1548e0f8762d6c2befdd47dbfb7810b01c9508
Fixes: #21054
Releases: 4.6, 4.5, 4.4
Reviewed-on: http://review.typo3.org/3281
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
t3lib/class.t3lib_stdgraphic.php

index 990cfde..37a8dc0 100644 (file)
@@ -864,8 +864,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)) {
@@ -2920,4 +2933,4 @@ if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLA
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_stdgraphic.php']);
 }
 
-?>
\ No newline at end of file
+?>