svn: /pear/packages/Image_Canvas/trunk/Image/Canvas/ GD.php

From: Date: Sat, 26 Dec 2009 20:11:28 +0000
Subject: svn: /pear/packages/Image_Canvas/trunk/Image/Canvas/ GD.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-58381@lists.php.net to get a copy of this message
neufeind Sat, 26 Dec 2009 20:11:28 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=292673 Log: * #16947: Font-size in GD (with GD2) incorrect ** first step: make GD-module work with GD2 as documented in the API/phpdoc ** note: BC-break for people expecting values to be passed unaltered to GD2-TTF-functions - but fixes a bug! Bug: http://pear.php.net/bugs/16947 (unknown) Changed paths: U pear/packages/Image_Canvas/trunk/Image/Canvas/GD.php Modified: pear/packages/Image_Canvas/trunk/Image/Canvas/GD.php =================================================================== --- pear/packages/Image_Canvas/trunk/Image/Canvas/GD.php 2009-12-26 19:33:25 UTC (rev 292672) +++ pear/packages/Image_Canvas/trunk/Image/Canvas/GD.php 2009-12-26 20:11:28 UTC (rev 292673) @@ -82,6 +82,14 @@ var $_gd2 = true; /** + * Do we need a factor to convert size in pixels to points? + * GD2 uses "pt" for font-sizes + * @var float + * @access private + */ + var $_pxToPtFactor = 1; + + /** * Antialiasing? * * Possible values 'off', 'driver' and 'native' @@ -151,6 +159,7 @@ parent::Image_Canvas_WithMap($param); $this->_gd2 = ($this->_version() == 2); + $this->_pxToPtFactor = ($this->_gd2 ? (72/96) : 1); $this->_font = array('font' => 1, 'color' => 'black'); if ((isset($param['gd'])) && (is_resource($param['gd']))) { @@ -1291,7 +1300,7 @@ $lines = explode("\n", $text); foreach ($lines as $line) { $bounds = ImageTTFBBox( - $this->_font['size'], + $this->_font['size']*$this->_pxToPtFactor, $angle, $this->_font['file'], $text @@ -1355,7 +1364,7 @@ $lines = explode("\n", $text); foreach ($lines as $line) { $bounds = ImageTTFBBox( - $this->_font['size'], + $this->_font['size']*$this->_pxToPtFactor, $angle, $this->_font['file'], $line @@ -1420,17 +1429,17 @@ if (($this->_font['angle'] >= 90) && ($this->_font['angle'] < 270)) { $dx += $w0; } - } else { + } else { // get the maximum size of normal text above base line - sampled by 'Al' - $size1 = imagettfbbox($this->_font['size'], 0, $this->_font['file'], 'Al'); + $size1 = imagettfbbox($this->_font['size']*$this->_pxToPtFactor, 0, $this->_font['file'], 'Al'); $height1 = abs($size1[7] - $size1[1]); // get the maximum size of all text above base and below line - sampled by 'AlgjpqyQ' - $size2 = imagettfbbox($this->_font['size'], 0, $this->_font['file'], 'AlgjpqyQ'); + $size2 = imagettfbbox($this->_font['size']*$this->_pxToPtFactor, 0, $this->_font['file'], 'AlgjpqyQ'); $height2 = abs($size2[7] - $size2[1]); // get the size of the text, simulating height above baseline beinh max, by sampling using 'Al' - $size = imagettfbbox($this->_font['size'], 0, $this->_font['file'], 'Al' . $text); + $size = imagettfbbox($this->_font['size']*$this->_pxToPtFactor, 0, $this->_font['file'], 'Al' . $text); $height = abs($size[7] - $size[1]); // if all text is above baseline, i.e. height of text compares to max height above (within 10%) @@ -1461,7 +1470,7 @@ } if ($factor != 0) { - $size = imagettfbbox($this->_font['size'], 0, $this->_font['file'], $text); + $size = imagettfbbox($this->_font['size']*$this->_pxToPtFactor, 0, $this->_font['file'], $text); $w0 = abs($size[2] - $size[0]); $dx -= cos(deg2rad($this->_font['angle'])) * $w0 * $factor; $dy += sin(deg2rad($this->_font['angle'])) * $w0 * $factor; @@ -1533,7 +1542,7 @@ $result = $this->_getAbsolutePosition($x, $y, $line, $alignment); ImageTTFText( $this->_canvas, - $this->_font['size'], + $this->_font['size']*$this->_pxToPtFactor, $this->_font['angle'], $result['x'], $result['y'],

« previous php.pear.cvs (#58381) next »