📄 fpdf.php
字号:
$l=strlen($s);
for($i=0;$i<$l;$i++) $w+=$cw[$s{$i}];
return $w*$this->FontSize/1000;
}
function SetLineWidth($width)
{
//Set line width
$this->LineWidth=$width;
if($this->page>0) $this->_out(sprintf('%.2f w',$width*$this->k));
}
function Line($x1,$y1,$x2,$y2)
{
//Draw a line
$this->_out(sprintf('%.2f %.2f m %.2f %.2f l S',$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k));
}
function Rect($x,$y,$w,$h,$style='')
{
//Draw a rectangle
if($style=='F') $op='f';
elseif($style=='FD' or $style=='DF') $op='B';
else $op='S';
$this->_out(sprintf('%.2f %.2f %.2f %.2f re %s',$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
}
function AddFont($family,$style='',$file='')
{
//Add a TrueType or Type1 font
$family=strtolower($family);
if($family=='arial') $family='helvetica';
$style=strtoupper($style);
if($style=='IB') $style='BI';
if(isset($this->fonts[$family.$style])) $this->Error('Font already added: '.$family.' '.$style);
if($file=='') $file=str_replace(' ','',$family).strtolower($style).'.php';
if(defined('FPDF_FONTPATH')) $file=FPDF_FONTPATH.$file;
include($file);
if(!isset($name)) $this->Error('Could not include font definition file');
$i=count($this->fonts)+1;
$this->fonts[$family.$style]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'enc'=>$enc,'file'=>$file);
if($diff)
{
//Search existing encodings
$d=0;
$nb=count($this->diffs);
for($i=1;$i<=$nb;$i++)
if($this->diffs[$i]==$diff)
{
$d=$i;
break;
}
if($d==0)
{
$d=$nb+1;
$this->diffs[$d]=$diff;
}
$this->fonts[$family.$style]['diff']=$d;
}
if($file)
{
if($type=='TrueType') $this->FontFiles[$file]=array('length1'=>$originalsize);
else $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
}
}
function SetFont($family,$style='',$size=0)
{
//Select a font; size given in points
global $fpdf_charwidths;
$family=strtolower($family);
if($family=='') $family=$this->FontFamily;
//EDITEI - now understands: monospace,serif,sans [serif]
if($family=='monospace') $family='courier';
if($family=='serif') $family='times';
if($family=='sans') $family='arial';
if($family=='arial') $family='helvetica';
elseif($family=='symbol' or $family=='zapfdingbats') $style='';
$style=strtoupper($style);
if(is_int(strpos($style,'U')))
{
$this->underline=true;
$style=str_replace('U','',$style);
}
else $this->underline=false;
if ($style=='IB') $style='BI';
if ($size==0) $size=$this->FontSizePt;
//Test if font is already selected
if($this->FontFamily==$family and $this->FontStyle==$style and $this->FontSizePt==$size) return;
//Test if used for the first time
$fontkey=$family.$style;
if(!isset($this->fonts[$fontkey]))
{
//Check if one of the standard fonts
if(isset($this->CoreFonts[$fontkey]))
{
if(!isset($fpdf_charwidths[$fontkey]))
{
//Load metric file
$file=$family;
if($family=='times' or $family=='helvetica') $file.=strtolower($style);
$file.='.php';
if(defined('FPDF_FONTPATH')) $file=FPDF_FONTPATH.$file;
include($file);
if(!isset($fpdf_charwidths[$fontkey])) $this->Error('Could not include font metric file');
}
$i=count($this->fonts)+1;
$this->fonts[$fontkey]=array('i'=>$i,'type'=>'core','name'=>$this->CoreFonts[$fontkey],'up'=>-100,'ut'=>50,'cw'=>$fpdf_charwidths[$fontkey]);
}
else $this->Error('Undefined font: '.$family.' '.$style);
}
//Select it
$this->FontFamily=$family;
$this->FontStyle=$style;
$this->FontSizePt=$size;
$this->FontSize=$size/$this->k;
$this->CurrentFont=&$this->fonts[$fontkey];
if($this->page>0)
$this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
}
function SetFontSize($size)
{
//Set font size in points
if($this->FontSizePt==$size) return;
$this->FontSizePt=$size;
$this->FontSize=$size/$this->k;
if($this->page>0)
$this->_out(sprintf('BT /F%d %.2f Tf ET',$this->CurrentFont['i'],$this->FontSizePt));
}
function AddLink()
{
//Create a new internal link
$n=count($this->links)+1;
$this->links[$n]=array(0,0);
return $n;
}
function SetLink($link,$y=0,$page=-1)
{
//Set destination of internal link
if($y==-1) $y=$this->y;
if($page==-1) $page=$this->page;
$this->links[$link]=array($page,$y);
}
function Link($x,$y,$w,$h,$link)
{
//Put a link on the page
$this->PageLinks[$this->page][]=array($x*$this->k,$this->hPt-$y*$this->k,$w*$this->k,$h*$this->k,$link);
}
function Text($x,$y,$txt)
{
//Output a string
$s=sprintf('BT %.2f %.2f Td (%s) Tj ET',$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
if($this->underline and $txt!='') $s.=' '.$this->_dounderline($x,$y,$txt);
if($this->ColorFlag) $s='q '.$this->TextColor.' '.$s.' Q';
$this->_out($s);
}
function AcceptPageBreak()
{
//Accept automatic page break or not
return $this->AutoPageBreak;
}
function Cell($w,$h=0,$txt='',$border=0,$ln=0,$align='',$fill=0,$link='',$currentx=0) //EDITEI
{
//Output a cell
$k=$this->k;
if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $this->AcceptPageBreak())
{
//Automatic page break
$x=$this->x;//Current X position
$ws=$this->ws;//Word Spacing
if($ws>0)
{
$this->ws=0;
$this->_out('0 Tw');
}
$this->AddPage($this->CurOrientation);
$this->x=$x;
if($ws>0)
{
$this->ws=$ws;
$this->_out(sprintf('%.3f Tw',$ws*$k));
}
}
if($w==0) $w = $this->w-$this->rMargin-$this->x;
$s='';
if($fill==1 or $border==1)
{
if ($fill==1) $op=($border==1) ? 'B' : 'f';
else $op='S';
//$op='S';//DEBUG
$s=sprintf('%.2f %.2f %.2f %.2f re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
}
if(is_string($border))
{
$x=$this->x;
$y=$this->y;
if(is_int(strpos($border,'L')))
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
if(is_int(strpos($border,'T')))
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
if(is_int(strpos($border,'R')))
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
if(is_int(strpos($border,'B')))
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
}
if($txt!='')
{
if($align=='R') $dx=$w-$this->cMargin-$this->GetStringWidth($txt);
elseif($align=='C') $dx=($w-$this->GetStringWidth($txt))/2;
elseif($align=='L' or $align=='J') $dx=$this->cMargin;
else $dx = 0;
if($this->ColorFlag) $s.='q '.$this->TextColor.' ';
$txt2=str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$txt)));
//Check whether we are going to outline text or not
if($this->outline_on)
{
$s.=' '.sprintf('%.2f w',$this->LineWidth*$this->k).' ';
$s.=" $this->DrawColor ";
$s.=" 2 Tr ";
}
//Superscript and Subscript Y coordinate adjustment
$adjusty = 0;
if($this->SUB) $adjusty = 1;
if($this->SUP) $adjusty = -1;
//End of coordinate adjustment
$s.=sprintf('BT %.2f %.2f Td (%s) Tj ET',($this->x+$dx)*$k,($this->h-(($this->y+$adjusty)+.5*$h+.3*$this->FontSize))*$k,$txt2); //EDITEI
if($this->underline)
$s.=' '.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->FontSize+$adjusty,$txt2);
//Superscript and Subscript Y coordinate adjustment (now for striked-through texts)
$adjusty = 1.6;
if($this->SUB) $adjusty = 3.05;
if($this->SUP) $adjusty = 1.1;
//End of coordinate adjustment
if($this->strike) //EDITEI
$s.=' '.$this->_dounderline($this->x+$dx,$this->y+$adjusty,$txt);
if($this->ColorFlag) $s.=' Q';
if($link!='') $this->Link($this->x+$dx,$this->y+.5*$h-.5*$this->FontSize,$this->GetStringWidth($txt),$this->FontSize,$link);
}
if($s) $this->_out($s);
$this->lasth=$h;
if( strpos($txt,"\n") !== false) $ln=1; //EDITEI - cell now recognizes \n! << comes from <BR> tag
if($ln>0)
{
//Go to next line
$this->y += $h;
if($ln==1) //EDITEI
{
//Move to next line
if ($currentx != 0) $this->x=$currentx;
else $this->x=$this->lMargin;
}
}
else $this->x+=$w;
}
//EDITEI
function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0,$link='')
{
//Output text with automatic or explicit line breaks
$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};
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,$link);
$i++;
$sep=-1;
$j=$i;
$l=0;
$ns=0;
$nl++;
if($border and $nl==2) $b=$b2;
continue;
}
if($c==' ')
{
$sep=$i;
$ls=$l;
$ns++;
}
$l+=$cw[$c];
if($l>$wmax)
{
//Automatic line break
if($sep==-1)
{
if($i==$j) $i++;
if($this->ws>0)
{
$this->ws=0;
$this->_out('0 Tw');
}
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
}
else
{
if($align=='J')
{
$this->ws=($ns>1) ? ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0;
$this->_out(sprintf('%.3f Tw',$this->ws*$this->k));
}
$this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill,$link);
$i=$sep+1;
}
$sep=-1;
$j=$i;
$l=0;
$ns=0;
$nl++;
if($border and $nl==2) $b=$b2;
}
else $i++;
}
//Last chunk
if($this->ws>0)
{
$this->ws=0;
$this->_out('0 Tw');
}
if($border and is_int(strpos($border,'B'))) $b.='B';
$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill,$link);
$this->x=$this->lMargin;
}
function Write($h,$txt,$currentx=0,$link='') //EDITEI
{
//Output text in flowing mode
$cw=&$this->CurrentFont['cw'];
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
$s=str_replace("\r",'',$txt);
$nb=strlen($s);
$sep=-1;
$i=0;
$j=0;
$l=0;
$nl=1;
while($i<$nb)
{
//Get next character
$c=$s{$i};
if($c=="\n")
{
//Explicit line break
$this->Cell($w,$h,substr($s,$j,$i-$j),0,2,'',0,$link);
$i++;
$sep=-1;
$j=$i;
$l=0;
if($nl==1)
{
if ($currentx != 0) $this->x=$currentx;//EDITEI
else $this->x=$this->lMargin;
$w=$this->w-$this->rMargin-$this->x;
$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
}
$nl++;
continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -