linux
137 days ago
fpdf 中文包MultiCell的一个bug
中文包地址 http://fpdf.org/phorum/read.php?f=1&i=5142&t=5142
运行下面测试例(gbk 编码), php 陷入死循环
<?php
require('chinese.php');
$pdf=new PDF_Chinese();
$pdf->AddBig5Font();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Big5','',20);
$test='气01234567890ab';
$pdf->MultiCell(50,9,$test);
$pdf->Output();
?>
该bug在chinese/chinese-unicode都存在, 开发者oliver联系不上, 这是补丁:
--- chinese.php 2004-03-03 23:14:20.000000000 +0800
+++ chinese2.php 2010-03-08 14:24:12.000000000 +0800
@@ -187,11 +187,11 @@ function MBMultiCell($w,$h,$txt,$border=
}
$l+=$ascii ? $cw[$c] : 1000;
if($l>$wmax)
{
//Automatic line break
- if($sep==-1 or $i==$j)
+ if($sep==-1 or $i==$j or $sep==$j)
{
if($i==$j)
$i+=$ascii ? 1 : 2;
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
}
@@ -265,11 +265,11 @@ function MBWrite($h,$txt,$link)
$sep=$i;
$l+=$ascii ? $cw[$c] : 1000;
if($l>$wmax)
{
//Automatic line break
- if($sep==-1 or $i==$j)
+ if($sep==-1 or $i==$j or $sep==$j)
{
if($this->x>$this->lMargin)
{
//Move to next line
$this->x=$this->lMargin;
Commenting is closed for this article.