From ead4200b8b309f71f1b61f527df208c55bbd26cf Mon Sep 17 00:00:00 2001 From: Benni Mack <benni@typo3.org> Date: Sat, 25 Mar 2017 22:27:04 +0100 Subject: [PATCH] [TASK] Deprecate GeneralUtility::freetypeDpiComp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- .../Classes/Imaging/GraphicalFunctions.php | 18 +++++++++-- .../core/Classes/Utility/GeneralUtility.php | 2 ++ ...on-80449-GeneralUtilityfreetypeDpiComp.rst | 32 +++++++++++++++++++ .../Controller/Action/Tool/TestSetup.php | 2 +- 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-80449-GeneralUtilityfreetypeDpiComp.rst diff --git a/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php b/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php index f7d43a72ab08..e8dc51e67496 100644 --- a/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php +++ b/typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php @@ -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; + } } diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 97bf2c847b70..cf3ac5a9725c 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -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 index 000000000000..1e0749eed06d --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-80449-GeneralUtilityfreetypeDpiComp.rst @@ -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 diff --git a/typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php b/typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php index 792c8401a7a2..1582db4e24b1 100644 --- a/typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php +++ b/typo3/sysext/install/Classes/Controller/Action/Tool/TestSetup.php @@ -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, -- GitLab