php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23527 PostScript Type 1 font do not render properly
Submitted: 2003-05-07 08:52 UTC Modified: 2003-05-14 21:27 UTC
Votes:2
Avg. Score:3.5 ± 1.5
Reproduced:0 of 0 (0.0%)
From: nid at home dot se Assigned: iliaa (profile)
Status: Closed Package: GD related
PHP Version: 4.3.1 OS: Linux Slackware 8
Private report: No CVE-ID: None
 [2003-05-07 08:52 UTC] nid at home dot se
When installing PHP 4.3.x GD/t1lib stops behave properly. When showing a PS1-type font in an image, some characters get the wrong size.

When downgrading to PHP 4.2.3 the problem went away.

Using the bundled version of GD did not make any difference. Tried with bundled (4.3.x) and GD 2.0.8 (both with 4.3.x and 4.2.x).

The steps I went through are:
1. loading the font with imagepsloadfont('AkzGBS20.pfb');
2. Encoding the font with imagepsencodefont('8859.enc'); (even tried without this)
3. Executed this command: imagepstext($img,$text,$font_1,$size,$fg_color,$bg_color,$x,$y,$space,$tight,$angle,$antialias);
4. Imagepng()

variables:
$size = 12, $space = 0, $angle = 0, $antialias = 16

The code was run with the same source on 4.2.3, 4.3.0 and 4.3.1, and the problem started occuring on 4.3.0.

The font did have access to .afm-file, but it did not make any difference.

The font-file can be located at: http://www.delta-projects.com/AkzGBS20.pfb

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-07 09:10 UTC] nid at home dot se
Adding some more information along with a code-snippet

t1lib version: 1.3.1
Apache version: 1.3.27

The font can be fetched from the location in the main-comment.

When running the code, notice that G and Q does render differently from the rest of the characters.

----------[Code starts]-------------

$font_1 = imagepsloadfont('./AkzGBS20.pfb');

define('ANTIALIAS_MEDIUM',16);

$text = 'abcdefghijklmnopqrstuvxyz';

$x = 15;
$size = 12;
$y = 0;
$space = 0;
$tight = 0;
$angle = 0;
$antialias = ANTIALIAS_MEDIUM;

$text = strtoupper($text.'');

list($lx,$ly,$rx,$ry) = imagepsbbox($text,$font_1,$size,$space,$tight,$angle);
$w = $rx + 30;
$h = 18;
$y = 12;

$img = imagecreate($w,$h);
$fg_color = imagecolorallocate($img,133,118,98);
$bg_color = imagecolorallocate($img,255,255,255);

imagefill($img,2,2,$bg_color);
imagepstext($img,$text,$font_1,$size,$fg_color,$bg_color,$x,$y,$space,$tight,$angle,$antialias);
imagepng('test.png');
imagedestroy($img);
echo '<img src=test.png><br>';

--------------[Code ends]------------
 [2003-05-08 02:10 UTC] nid at home dot se
Also, I should say, PHP 4.2.3 had to be patched with this patch in order to install correctly:
http://www.boutell.com/gd/php-4.2.3-gd-2.0.8.patch

I have looked in this patch, and it does not seem to include any fixes about my problem.
 [2003-05-08 20:22 UTC] iliaa@php.net
Here is an image that was produced with your sample script using latest stable PHP & bundled GD (with your font).
As far as I can tell the text is perfect.
http://bb.prohost.org/test2.png
 [2003-05-09 01:38 UTC] nid at home dot se
Try generating an image with font size 12, and you might get the same results as me. The font renders well in some sizes (i've been testing 11 and 13 and higher).
 [2003-05-09 08:10 UTC] nid at home dot se
I found a solution for this problem, when tampering with ext/gd/gd.c

I don't have the original line numbers available, because of some tampering. But it is not hard to find it.

In the php-function imagepstext, there is a codesnippet that looks like this:

--------[code starts]-----

for (i = 1; i < str_len; i++) {
                amount_kern = (int) T1_GetKerning(*f_ind, str[i-1], str[i]);
                amount_kern += str[i-1] == ' ' ? space : 0;
                add_width = (int) (amount_kern+width)/extend;

                char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, size, transform);
                str_path = T1_ConcatOutlines(str_path, char_path);

                char_path = T1_GetCharOutline(*f_ind, str[i], size, transform);
                str_path = T1_ConcatOutlines(str_path, char_path);
        }
        str_img = T1_AAFillOutline(str_path, 0);

-----[code ends]-------

if you instead make this like it WAS in <=php4.2, it should look like this:

----[code starts]----
if (width) // this is the change
{
for (i = 1; i < str_len; i++) {
                amount_kern = (int) T1_GetKerning(*f_ind, str[i-1], str[i]);
                amount_kern += str[i-1] == ' ' ? space : 0;
                add_width = (int) (amount_kern+width)/extend;

                char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, size, transform);
                str_path = T1_ConcatOutlines(str_path, char_path);

                char_path = T1_GetCharOutline(*f_ind, str[i], size, transform);
                str_path = T1_ConcatOutlines(str_path, char_path);
        }
        str_img = T1_AAFillOutline(str_path, 0);

}
else // change continues here
{
      str_img = T1_AASetString(*f_ind, str,  str_len, space, T1_KERNING, size, transform);
}

----[code ends]----

Then the problem went away (until you set the space-property to a non-zero value). So, evidentually, there is some kind of bug, or PHP handles spaced texts differently than t1lib does as standard.

For further releases, can you _please_ put the "if (width)"-statement as it was before?
 [2003-05-09 08:14 UTC] nid at home dot se
The syntax seems to be uncorrect about the "space"-variable. This might be called "width".
 [2003-05-14 21:27 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 04 11:01:28 2024 UTC