[TASK] Deprecate GeneralUtility::freetypeDpiComp 60/52160/4
authorBenni Mack <benni@typo3.org>
Sat, 25 Mar 2017 21:27:04 +0000 (22:27 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 25 Mar 2017 22:14:02 +0000 (23:14 +0100)
The Freetype related method "GeneralUtility::freetypeDpiComp"
has been marked as deprecated and moved to GraphicalFunctions
where it belongs to.

Resolves: #80449
Releases: master
Change-Id: Iaa549051c38993a24415c2bfdb785715c1d6e74d
Reviewed-on: https://review.typo3.org/52160
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-80449-GeneralUtilityfreetypeDpiComp.rst [new file with mode: 0644]
typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php

index f7d43a7..e8dc51e 100644 (file)
@@ -996,7 +996,7 @@ class GraphicalFunctions
                  */
                 $try = 0;
                 do {
-                    $calc = imagettfbbox(GeneralUtility::freetypeDpiComp($sF * $strCfg['fontSize']), $angle, $fontFile, $strCfg['str']);
+                    $calc = imagettfbbox($this->compensateFontSizeiBasedOnFreetypeDpi($sF * $strCfg['fontSize']), $angle, $fontFile, $strCfg['str']);
                 } while ($calc[2] < 0 && $try++ < 10);
                 // Calculate offsets:
                 if (empty($offsetInfo)) {
@@ -1054,9 +1054,9 @@ class GraphicalFunctions
             $fontFile = GeneralUtility::getFileAbsFileName($strCfg['fontFile']);
             if (is_readable($fontFile)) {
                 // Render part:
-                imagettftext($im, GeneralUtility::freetypeDpiComp($sF * $strCfg['fontSize']), $angle, $x, $y, $colorIndex, $fontFile, $strCfg['str']);
+                imagettftext($im, $this->compensateFontSizeiBasedOnFreetypeDpi($sF * $strCfg['fontSize']), $angle, $x, $y, $colorIndex, $fontFile, $strCfg['str']);
                 // Calculate offset to apply:
-                $wordInf = imagettfbbox(GeneralUtility::freetypeDpiComp($sF * $strCfg['fontSize']), $angle, GeneralUtility::getFileAbsFileName($strCfg['fontFile']), $strCfg['str']);
+                $wordInf = imagettfbbox($this->compensateFontSizeiBasedOnFreetypeDpi($sF * $strCfg['fontSize']), $angle, GeneralUtility::getFileAbsFileName($strCfg['fontFile']), $strCfg['str']);
                 $x += $wordInf[2] - $wordInf[0] + (int)$splitRendering['compX'] + (int)$strCfg['xSpaceAfter'];
                 $y += $wordInf[5] - $wordInf[7] - (int)$splitRendering['compY'] - (int)$strCfg['ySpaceAfter'];
             } else {
@@ -3022,4 +3022,16 @@ class GraphicalFunctions
             imagegif($im, $filename);
         }
     }
+
+    /**
+     * Function to compensate for DPI resolution.
+     * FreeType 2 always has 96 dpi, so it is hard-coded at this place.
+     *
+     * @param float $fontSize font size for freetype function call
+     * @return float compensated font size based on 96 dpi
+     */
+    protected function compensateFontSizeiBasedOnFreetypeDpi($fontSize)
+    {
+        return $fontSize / 96.0 * 72;
+    }
 }
index 97bf2c8..cf3ac5a 100644 (file)
@@ -4242,9 +4242,11 @@ class GeneralUtility
      * @param float $fontSize font size for freetype function call
      *
      * @return float compensated font size based on 96 dpi
+     * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, the functionality is now moved to GraphicalFunctions->compensateFontSizeiBasedOnFreetypeDpi()
      */
     public static function freetypeDpiComp($fontSize)
     {
+        self::logDeprecatedFunction();
         // FreeType 2 always has 96 dpi.
         $dpi = 96.0;
         return $fontSize / $dpi * 72;
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-80449-GeneralUtilityfreetypeDpiComp.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-80449-GeneralUtilityfreetypeDpiComp.rst
new file mode 100644 (file)
index 0000000..1e0749e
--- /dev/null
@@ -0,0 +1,32 @@
+.. include:: ../../Includes.txt
+
+=====================================================
+Deprecation: #80449 - GeneralUtility::freetypeDpiComp
+=====================================================
+
+See :issue:`80449`
+
+Description
+===========
+
+The method ``GeneralUtility::freetypeDpiComp`` has been marked as deprecated.
+
+
+Impact
+======
+
+Calling this method will trigger a deprecation log entry.
+
+
+Affected Installations
+======================
+
+Any installation using custom GraphicalFunctions where GDlib/Freetype does custom calculations.
+
+
+Migration
+=========
+
+No substitution available.
+
+.. index:: PHP-API
\ No newline at end of file
index 792c840..1582db4 100644 (file)
@@ -187,7 +187,7 @@ class TestSetup extends Action\AbstractAction
         $textColor = imagecolorallocate($image, 233, 14, 91);
         @imagettftext(
             $image,
-            GeneralUtility::freetypeDpiComp(20),
+            20 / 96.0 * 72, // As in  compensateFontSizeiBasedOnFreetypeDpi
             0,
             10,
             20,