JpGraph中缺少字符 [英] Missing chars in JpGraph

查看:139
本文介绍了JpGraph中缺少字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Windows上运行并使用cp1252(又名Win-1252)的网站,因此它可以显示西班牙语字符.该应用程序使用 JpGraph 2.3 生成一些绘图.这些图使用Tahoma Open Type字体系列显示文本标签.字符串在ANSI(即cp1252)中提供,字体文件支持cp1252(实际上,* .ttf文件是从系统的字体文件夹中复制的).

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).

在从PHP/5.2.6到PHP/5.3.0的几种设置中,它一直运行良好.当我在 PHP/5.3.1 下运行该应用程序时出现了问题:所有非ASCII字符都被表示缺失或未知字符的空心矩形替换.

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的文档对于它对国际字符的期望不是很精确.显然,文本是由imagettftext()函数在内部处理的,该函数需要使用UTF-8.但是,将所有内容编码为UTF-8会破坏所有系统中的应用程序.在ANSI正常工作的地方,我得到了错误的字符(Ê,而不是Ú).我缺少字符的地方,现在出现了PHP错误:

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:

警告:imagettftext():any2eucjp(): 发生了什么事

Warning: imagettftext(): any2eucjp(): something happen

您是否对GD2中从PHP/5.3.0到5.3.1的更改有任何影响,可能会影响非ASCII字符的呈现?我应该如何在Win-1252字符集中用字符串填充JpGraph?

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?

最终,该问题与JpGraph无关.我可以通过简单调用imagettftext()重现该问题:

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);

?>

在PHP/5.3.0中,ANSI和UTF-8都呈现正确的文本.在PHP/5.3.1中,ANSI呈现错误的字符,而UTF-8触发any2eucjp(): something happen内部错误.我敢说我碰到了一个错误...

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...

推荐答案

我的发现摘要:

  1. 这可能是PHP/5.3.1(或我的PHP/5.3.1二进制版本)中的错误; PHP/5.3.2不再丢失字符或引发警告.
  2. 一种解决方法是使用数字HTML实体对非ASCII字符进行编码.

这篇关于JpGraph中缺少字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆