Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* #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!


git-svn-id: https://svn.php.net/repository/pear/packages/Image_Canvas/trunk@292673 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 21397c5a73d3b62cec2fcc98541e154ceffef981 1 parent 4f2f7a7
@neufeind neufeind authored
Showing with 17 additions and 8 deletions.
  1. +17 −8 Image/Canvas/GD.php
View
25 Image/Canvas/GD.php
@@ -82,6 +82,14 @@ class Image_Canvas_GD extends Image_Canvas_WithMap
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 @@ function Image_Canvas_GD($param)
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 @@ function textWidth($text)
$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 @@ function textHeight($text, $force = false)
$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 @@ function _getAbsolutePosition($x, $y, $text, $align)
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 @@ function _getAbsolutePosition($x, $y, $text, $align)
}
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 @@ function addText($params)
$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'],
Please sign in to comment.
Something went wrong with that request. Please try again.