php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17955 GD and unicode maps/webdings
Submitted: 2002-06-24 16:03 UTC Modified: 2004-01-26 14:59 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: dk at webcluster dot at Assigned: moriyoshi (profile)
Status: Not a bug Package: GD related
PHP Version: 4CVS, 5CVS OS: RedHat 7.3
Private report: No CVE-ID: None
 [2002-06-24 16:03 UTC] dk at webcluster dot at
Hello,

I want to output the webdings.ttf font using freetype and gd.
Unfortunately I only get rectangular symbols back.

I discusse the issue inside the freetype mailing list and they told me that 
"FreeType2 selects a Unicode charmap as default charmap for a font if available. Webdings.ttf does not have a Unicode charmap."

They thought that it could be a bug in gd and supplied a patch for gdlib.

_-_-_quote_-_-_


----8<----
  for (n = 0; n < a->face->num_charmaps; n++)
    {
      charmap = a->face->charmaps[n];
      platform = charmap->platform_id;
      encoding = charmap->encoding_id;
      if ((platform == 3 && encoding == 1)	/* Windows Unicode */
	  || (platform == 3 && encoding == 0)	/* Windows Symbol */
	  || (platform == 2 && encoding == 1)	/* ISO Unicode */
	  || (platform == 0))
	{			/* Apple Unicode */
	  a->have_char_map_unicode = 1;
	  found = charmap;
----8<----

So it would work if GD would not forget to tell FreeType2 to use the
charmap it found... :

----8<----
--- gd-2.0.1/gdft.c.ori	Tue Apr  3 20:44:42 2001
+++ gd-2.0.1/gdft.c	Mon Jun 24 16:25:35 2002
@@ -445,6 +445,12 @@
       *error = "Unable to find a CharMap that I can handle";
       return NULL;
     }
+  err = FT_Set_Charmap (a->face, found);
+  if (err)
+    {
+      *error = "Could not set CharMap";
+      return NULL;
+    }
 
   return (void *) a;
 }
----8<----
_-_-_quote_-_-_


I applied it, but it still doesn't seem to work.
I'm sure that the right gd is linked (ldd).

I've seen examples with Zapf Dingbats and Webdings work with other languages, so I think it may be also a php issue.

Maybe you could point me on a solution.

Thanks in advance

Daniel Khan

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-24 18:54 UTC] sniper@php.net
Being the lazy asses we are, could you add some
short example script which shows what doesn't work?

--Jani

 [2002-06-24 21:25 UTC] dk at webcluster dot at
<?PHP
function hex2rgb($hex) {
    $c = array('R', 'G', 'B'); $i = 0;
    preg_replace('/([a-f0-9]{2})/ie', '$rgb[$c[$i++]] = hexdec("\1")',
$hex);
    return $rgb;
} 

$col = "FF0000";
$text = "Here comes the text!";
$rgb = hex2rgb($col);

$fontsize = 18;
$font="/some/dir/webdings.ttf";

$size=ImageTTFBBox($fontsize,0,$font,$text);

$width = abs($size[2]); 
$height = abs($size[5]);
Header ("Content-type: image/jpeg");


$im = ImageCreate ($width+11, $height+8);
$bg = ImageColorAllocate ($im, 255, 255, 255);
ImageColorTransparent($im, $bg);
$main = ImageColorAllocate ($im, $rgb["R"], $rgb["G"], $rgb["B"]);

$shadow = ImageColorAllocate ($im, 219, 219, 219);
ImageTTFText($im,$fontsize,0,1,21,$shadow,$font,$text);
ImageTTFText($im,$fontsize,0,0,20,$main,$font,$text);


ImageGif ($im);
ImageDestroy ($im);

?>
 [2002-06-25 05:44 UTC] dk at webcluster dot at
Additional info:

I talked again to the freetype guys.

They asked me to try to use "&#61473;" instead of the characters. This worked fine:

<quote>
If &#61473; works but UTF-8 not then GD was compiled with the option
JISX0208 which IMHO prevents decoding of UTF-8 encoded character codes.
Then try to find out why this option was set.
</quote>
 [2003-12-17 09:20 UTC] moriyoshi@php.net
I'll take a look into this.
Assign to myself.

 [2004-01-22 18:16 UTC] moriyoshi@php.net
Take a look at bug #26901. I summerized the 
"rectangular / square placeholders" issues that you may 
encounter when using non-ASCII characters with 
ImageTTFText() / ImageFTText().

 [2004-01-26 14:34 UTC] moriyoshi@php.net
This problem turned out not to be a PHP developer's 
issue.

Read the following post on the freetype list archive:

http://www.freetype.org/pipermail/freetype/2001-October/
004507.html

And then, try this one:

<?php
$str = "this is a test";
$str = iconv("UCS-2", "UTF-8", preg_replace("/(.)/", 
"\xf0\$1", $str));

$fsize = 32;
$ffile="./webdings.ttf";

$size = ImageTTFBBox($fsize, 0, $ffile, $str);

$txt_width = ($size[2] - $size[0]);
$txt_height = ($size[1] - $size[7]);

$im_width = $txt_width * 1.5; 
$im_height = $txt_height * 1.5;

$im = ImageCreateTrueColor($im_width, $im_height);
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);

$txt_x = ($im_width - $txt_width) / 2;
$txt_y = ($im_height - $txt_height) / 2 + $txt_height;

ImageFilledRectangle($im, 0, 0, $im_width, $im_height, 
$white);
ImageTTFText($im, $fsize, 0, $txt_x, $txt_y, $black, 
$ffile, $str);

ImagePng($im);
ImageDestroy($im);
?>

The output of the script can be seen in the following 
page:
http://www.voltex.jp/articles/imagettf_m10n.htm
 [2004-01-26 14:59 UTC] datenpunk@php.net
I can't add much more to this as my initial report was from 2002 but I'll get back to your tips as soon as I need symbol fonts again.

Thank's a lot moriyoshi for digging into this problem and for taking care of even old bug reports - _really_

cheers

Daniel Khan
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 22:01:29 2024 UTC