|
PHP开发实例:创建PDF中文文档的程序代码(3) $this->AddCIDFont($family,'BI',$name.',BoldItalic',$cw,$CMap,$registry); } function GetStringWidth($s) { if($this->CurrentFont['type']=='Type0') return $this->GetMBStringWidth($s); else return parent::GetStringWidth($s); }
function GetMBStringWidth($s) { //Multi-byte version of GetStringWidth() $l=0; $cw=&$this->CurrentFont['cw']; $nb=strlen($s); $i=0; while($i<$nb) { $c=$s[$i]; if(ord($c)<128) { $l+=$cw[$c]; $i++; } else { $l+=1000; $i+=2; } } return $l*$this->FontSize/1000; } function MultiCell($w,$h,$txt,$border=0,$align='L',$fill=0) { if($this->CurrentFont['type']=='Type0') $this->MBMultiCell($w,$h,$txt,$border,$align,$fill); else parent::MultiCell($w,$h,$txt,$border,$align,$fill); } function MBMultiCell($w,$h,$txt,$border=0,$align='L',$fill=0) { //Multi-byte version of MultiCell() $cw=&$this->CurrentFont['cw']; if($w==0) $w=$this->w-$this->rMargin-$this->x; $wmax=($w-2*$this->cMargin)*1000/$this->FontSize; $s=str_replace("\r",'',$txt); $nb=strlen($s); if($nb>0 and $s[$nb-1]=="\n" $nb--; $b=0; if($border) { if($border==1) { $border='LTRB'; $b='LRT'; $b2='LR'; } else { $b2=''; if(is_int(strpos($border,'L'))) $b2.='L'; if(is_int(strpos($border,'R'))) $b2.='R'; $b=is_int(strpos($border,'T')) ? $b2.'T' : $b2; } } $sep=-1; $i=0; $j=0; $l=0; $ns=0; $nl=1; while($i<$nb) { //Get next character $c=$s[$i]; //Check if ASCII or MB $ascii=(ord($c)<128); if($c=="\n" { //EXPlicit line break if($this->ws>0) { $this->ws=0; $this->_out('0 Tw'); } $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); $i++; $sep=-1; $j=$i; $l=0;
|