1.修改Nblines方法,该方法是用来计算内容在宽度固定的条件,需要几行来显示该数据才不至于撑破单元格。并且我们在使用中文换行时,出现的现象是一致的,就是每个中文内容字段在一个cell中显示2行就不再显示。仔细查看代码:
发现31行存在问题,由于这里的cw就是我们在chinese.php中定义的$GB_widths数组。而$GB_widths中并没有对中文的判断,因此每次遇到中文时,都没有进行累加操作。因此需改变为如下的代码:
if(!$cw[$c]) $l+=500; else $l+$cw[$c];
500 可能不够, 可以再适当的放大一些
也就是说,我们把一个中文字看作一个占据一个空间的字母/数字代替,也就解决了中文不能换行的问题
3.如果要生成pdf文档颜色交替显示,需要修改Rows方法,添加一个参数fill,并修改其中的
$this-> Rect($x,$y,$w,$h);为 if($fill) $this->sect($x,$y,$w,$h,"FD"); else $this-> Rect($x,$y,$w,$h);
1
function NbLines($w
,
$txt)
2 {
3 //Computes the number of lines a MultiCell of width w will take
4 $cw = &$this->CurrentFont [ 'cw' ] ;
5 if($w == 0 )
6 $w = $this->w-$this->rMargin-$this->x ;
7 $wmax = ($w- 2 *$this->cMargin)* 1000 /$this->FontSize ;
8 $s = str_replace( " /r " , '' , $txt) ;
9 $nb = strlen($s) ;
10 if($nb> 0 and $s [ $nb-1 ] == " /n " )
11 $nb-- ;
12 $sep = - 1 ;
13 $i = 0 ;
14 $j = 0 ;
15 $l = 0 ;
16 $nl = 1 ;
17 while($i<$nb)
18 {
19 $c = $s [ $i ] ;
20 if($c == " /n " )
21 {
22 $i++ ;
23 $sep = - 1 ;
24 $j = $i ;
25 $l = 0 ;
26 $nl++ ;
27 continue ;
28 }
29 if($c == ' ')
30 $sep = $i ;
31 $l+ = $cw [ $c ] ;
32 if($l>$wmax)
33 {
34 if($sep == - 1 )
35 {
36 if($i == $j)
37 $i++ ;
38 }
39 else
40 $i = $sep+ 1 ;
41 $sep = - 1 ;
42 $j = $i ;
43 $l = 0 ;
44 $nl++ ;
45 }
46 else
47 $i++ ;
48 }
49 return $nl ;
50 }
2 {
3 //Computes the number of lines a MultiCell of width w will take
4 $cw = &$this->CurrentFont [ 'cw' ] ;
5 if($w == 0 )
6 $w = $this->w-$this->rMargin-$this->x ;
7 $wmax = ($w- 2 *$this->cMargin)* 1000 /$this->FontSize ;
8 $s = str_replace( " /r " , '' , $txt) ;
9 $nb = strlen($s) ;
10 if($nb> 0 and $s [ $nb-1 ] == " /n " )
11 $nb-- ;
12 $sep = - 1 ;
13 $i = 0 ;
14 $j = 0 ;
15 $l = 0 ;
16 $nl = 1 ;
17 while($i<$nb)
18 {
19 $c = $s [ $i ] ;
20 if($c == " /n " )
21 {
22 $i++ ;
23 $sep = - 1 ;
24 $j = $i ;
25 $l = 0 ;
26 $nl++ ;
27 continue ;
28 }
29 if($c == ' ')
30 $sep = $i ;
31 $l+ = $cw [ $c ] ;
32 if($l>$wmax)
33 {
34 if($sep == - 1 )
35 {
36 if($i == $j)
37 $i++ ;
38 }
39 else
40 $i = $sep+ 1 ;
41 $sep = - 1 ;
42 $j = $i ;
43 $l = 0 ;
44 $nl++ ;
45 }
46 else
47 $i++ ;
48 }
49 return $nl ;
50 }
发现31行存在问题,由于这里的cw就是我们在chinese.php中定义的$GB_widths数组。而$GB_widths中并没有对中文的判断,因此每次遇到中文时,都没有进行累加操作。因此需改变为如下的代码:
if(!$cw[$c]) $l+=500; else $l+$cw[$c];
500 可能不够, 可以再适当的放大一些
也就是说,我们把一个中文字看作一个占据一个空间的字母/数字代替,也就解决了中文不能换行的问题
3.如果要生成pdf文档颜色交替显示,需要修改Rows方法,添加一个参数fill,并修改其中的
$this-> Rect($x,$y,$w,$h);为 if($fill) $this->sect($x,$y,$w,$h,"FD"); else $this-> Rect($x,$y,$w,$h);