JpGraph 中缺少字符
我有一个在 Windows 上运行并使用 cp1252
(又名 Win-1252
)的网站,因此它可以显示西班牙语字符。该应用程序使用 JpGraph 2.3 生成一些绘图。这些图使用 Tahoma Open Type 字体系列来显示文本标签。字符串以 ANSI(即 cp1252)提供,字体文件支持 cp1252(实际上,*.ttf 文件是从系统的字体文件夹复制的)。
它在从 PHP/5.2.6 到 PHP/5.3.0 的多个设置中都运行良好。当我在 PHP/5.3.1 下运行应用程序时,问题就开始了:所有非 ASCII 都被代表丢失或未知字符的空心矩形替换。
JpGraph 的文档对于它如何期望国际字符不是很精确。显然,文本由 imagettftext() 函数内部处理,该函数需要 UTF-8。但是,将所有内容编码为 UTF-8 会破坏所有系统中的应用程序。在 ANSI 以前工作正常的地方,我得到了错误的字符(Ê 而不是 Ú)。在我丢失字符的地方,现在出现 PHP 错误:
警告:imagettftext():any2eucjp(): 有事发生
您是否知道 GD2 从 PHP/5.3.0 到 5.3.1 中发生的哪些变化可能会影响非 ASCII 字符的渲染?我该如何向 JpGraph 提供 Win-1252 字符集中的字符串?
更新
最终,该问题与 JpGraph 无关。我可以通过简单调用 imagettftext() 来重现该问题:
<?php
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
//$text = 'áéíóú ÁÉÍÓÚ'; # ANSI
$text = utf8_encode('áéíóú ÁÉÍÓÚ'); # UTF8
$font = '/path/to/tahomabd.ttf';
imagettftext($im, 15, 0, 10, 25, $black, $font, $text);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
在 PHP/5.3.0 中,ANSI 和 UTF-8 都会呈现正确的文本。在 PHP/5.3.1 中,ANSI 呈现错误的字符,UTF-8 会触发 any2eucjp():发生了一些事情
内部错误。我敢说我遇到了一个错误......
I have a web site that runs on Windows and uses cp1252
(aka Win-1252
) so it can display Spanish characters. The app generates some plots with JpGraph 2.3. These plots use the Tahoma Open Type font family to display text labels. Strings are provided in ANSI (i.e., cp1252) and font files support cp1252 (actually, the *.ttf files were copied from the system's font folder).
It's been working fine in several setups from PHP/5.2.6 to PHP/5.3.0. Problems started when I ran the app under PHP/5.3.1: all non-ASCII are replaced by the hollow rectangle that represents missing or unknown chars.
JpGraph's documentation is not very precise about how it expects international chars. Apparently, text is handled internally by the imagettftext() function, which expects UTF-8. However, encoding everything as UTF-8 breaks the app in all the systems. Where ANSI used to work fine, I get wrong characters (Ê instead of Ú). Where I got missing chars, now I get a PHP error:
Warning: imagettftext(): any2eucjp():
something happen
Do you have any clue about what changed in GD2 from PHP/5.3.0 to 5.3.1 that could be affecting the rendering on non-ASCII chars? How am I expected to feed JpGraph with strings in the Win-1252 charset?
Update
Definitively, the issue is not related to JpGraph. I can reproduce the issue with a simple call to imagettftext():
<?php
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
//$text = 'áéíóú ÁÉÍÓÚ'; # ANSI
$text = utf8_encode('áéíóú ÁÉÍÓÚ'); # UTF8
$font = '/path/to/tahomabd.ttf';
imagettftext($im, 15, 0, 10, 25, $black, $font, $text);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
In PHP/5.3.0, both ANSI and UTF-8 render the right text. In PHP/5.3.1, ANSI renders wrong characters and UTF-8 triggers the any2eucjp(): something happen
internal error. I'd dare say I've hit a bug...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的发现摘要:
A summary of my findings: