📄 tcpdf.php
字号:
if($this->page>0) { $this->_out($this->FillColor); } if ($storeprev) { // store color as previous value $this->prevFillColor = array($r, $g, $b); } } /** * Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page. * @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255 * @param int $g Green component (between 0 and 255) * @param int $b Blue component (between 0 and 255) * @param boolean $storeprev if true stores the RGB array on $prevTextColor variable. * @since 1.3 * @see SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell() */ public function SetTextColor($r, $g=-1, $b=-1, $storeprev=false) { //Set color for text if(($r==0 and $g==0 and $b==0) or $g==-1) { $this->TextColor=sprintf('%.3f g',$r/255); } else { $this->TextColor=sprintf('%.3f %.3f %.3f rg',$r/255,$g/255,$b/255); } $this->ColorFlag=($this->FillColor!=$this->TextColor); if ($storeprev) { // store color as previous value $this->prevTextColor = array($r, $g, $b); } } /** * Returns the length of a string in user unit. A font must be selected.<br> * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02] * @param string $s The string whose length is to be computed * @return int * @since 1.2 */ public function GetStringWidth($s) { //Get width of a string in the current font $s = (string)$s; $cw = &$this->CurrentFont['cw']; $w = 0; if($this->isunicode) { $unicode = $this->UTF8StringToArray($s); foreach($unicode as $char) { if (isset($cw[$char])) { $w+=$cw[$char]; } elseif(isset($cw[ord($char)])) { $w+=$cw[ord($char)]; } elseif(isset($cw[chr($char)])) { $w+=$cw[chr($char)]; } elseif(isset($this->CurrentFont['desc']['MissingWidth'])) { $w += $this->CurrentFont['desc']['MissingWidth']; // set default size } else { $w += 500; } } } else { $l = strlen($s); for($i=0; $i < $l; $i++) { if (isset($cw[$s{$i}])) { $w += $cw[$s{$i}]; } else if (isset($cw[ord($s{$i})])) { $w += $cw[ord($s{$i})]; } } } return ($w * $this->FontSize / 1000); } /** * Returns the numbero of characters in a string. * @param string $s The input string. * @return int number of characters * @since 2.0.0001 (2008-01-07) */ public function GetNumChars($s) { if($this->isunicode) { return count($this->UTF8StringToArray($s)); } return strlen($s); } /** * Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility. The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by K_PATH_FONTS if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated. * Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]. * <b>Example</b>:<br /> * <pre> * $pdf->AddFont('Comic','I'); * // is equivalent to: * $pdf->AddFont('Comic','I','comici.php'); * </pre> * @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font. * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul> * @param string $file The font definition file. By default, the name is built from the family and style, in lower case with no space. * @since 1.5 * @see SetFont() */ public function AddFont($family, $style='', $file='') { if(empty($family)) { return; } //Add a TrueType or Type1 font $family = strtolower($family); if((!$this->isunicode) AND ($family == 'arial')) { $family = 'helvetica'; } $style=strtoupper($style); $style=str_replace('U','',$style); if($style == 'IB') { $style = 'BI'; } $fontkey = $family.$style; // check if the font has been already added if(isset($this->fonts[$fontkey])) { return; } if($file=='') { $file = str_replace(' ', '', $family).strtolower($style).'.php'; } if(!file_exists($this->_getfontpath().$file)) { // try to load the basic file without styles $file = str_replace(' ', '', $family).'.php'; } include($this->_getfontpath().$file); if(!isset($name) AND !isset($fpdf_charwidths)) { $this->Error('Could not include font definition file'); } $i = count($this->fonts)+1; if($this->isunicode) { $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg); $fpdf_charwidths[$fontkey] = $cw; } else { $this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]); } if(isset($diff) AND (!empty($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[$fontkey]['diff']=$d; } if(!empty($file)) { if((strcasecmp($type,"TrueType") == 0) OR (strcasecmp($type,"TrueTypeUnicode") == 0)) { $this->FontFiles[$file]=array('length1'=>$originalsize); } else { $this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2); } } } /** * Sets the font used to print character strings. It is mandatory to call this method at least once before printing text or the resulting document would not be valid. * The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe). * The method can be called before the first page is created and the font is retained from page to page. If you just wish to change the current font size, it is simpler to call SetFontSize(). * Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the K_PATH_FONTS constant</li></ul><br /> * Example for the last case (note the trailing slash):<br /> * <pre> * define('K_PATH_FONTS','/home/www/font/'); * require('tcpdf.php'); * * //Times regular 12 * $pdf->SetFont('Times'); * //Arial bold 14 * $pdf->SetFont('Arial','B',14); * //Removes bold * $pdf->SetFont(''); * //Times bold, italic and underlined 14 * $pdf->SetFont('Times','BIU'); * </pre><br /> * If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated. * @param string $family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case, the current family is retained. * @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li></ul>or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats * @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12 * @since 1.0 * @see AddFont(), SetFontSize(), Cell(), MultiCell(), Write() */ public function SetFont($family, $style='', $size=0) { // save previous values $this->prevFontFamily = $this->FontFamily; $this->prevFontStyle = $this->FontStyle; //Select a font; size given in points global $fpdf_charwidths; $family=strtolower($family); if($family=='') { $family=$this->FontFamily; } if((!$this->isunicode) AND ($family == 'arial')) { $family = 'helvetica'; } elseif(($family=="symbol") OR ($family=="zapfdingbats")) { $style=''; } $style=strtoupper($style); if(strpos($style,'U')!==false) { $this->underline=true; $style=str_replace('U','',$style); } else { $this->underline=false; } if($style=='IB') { $style='BI'; } if($size==0) { $size=$this->FontSizePt; } // try to add font (if not already added) if($this->isunicode) { $this->AddFont($family, $style); } //Test if font is already selected if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size)) { return; } $fontkey = $family.$style; //if(!isset($this->fonts[$fontkey]) AND isset($this->fonts[$family])) { // $style=''; //} //Test if used for the first time 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!='symbol') AND ($family!='zapfdingbats')) { $file .= strtolower($style); } if(!file_exists($this->_getfontpath().$file.'.php')) { // try to load the basic file without styles $file = $family; $fontkey = $family; } include($this->_getfontpath().$file.'.php'); if (($this->isunicode AND !isset($ctg)) OR ((!$this->isunicode) AND (!isset($fpdf_charwidths[$fontkey]))) ) { $this->Error("Could not include font metric file [".$fontkey."]: ".$this->_getfontpath().$file.".php"); } } $i = count($this->fonts) + 1; if($this->isunicode) { $this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg); $fpdf_charwidths[$fontkey] = $cw; } else { $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)); } } /** * Defines the size of the current font. * @param float $size The size (in points) * @since 1.0 * @see SetFont() */ public 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)); } } /** * Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br /> * The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink(). * @since 1.5 * @see Cell(), Write(), Image(), Link(), SetLink() */ public function AddLink() { //Create a new internal link $n=count($this->links)+1; $this->links[$n]=array(0,0); return $n; } /** * Defines the page and position a link points to * @param int $link The link identifier returned by AddLink() * @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page) * @param int $page Number of target page; -1 indicates the current page. This is the default value * @since 1.5 * @see AddLink() */ public 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); } /** * Puts a link on a rectangular area of the page. Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image. * @param float $x Abscissa of the upper-left corner of the rectangle (or upper-right for RTL languages) * @param float $y Ordinate of the upper-left corner of the rectangle (or upper-right for RTL languages) * @param float $w Width of the rectangle * @param float $h Height of the rectangle * @param mixed $link URL or identifier returned by AddLink() * @since 1.5 * @see AddLink(), Cell(), Write(), Image() */ public function Link($x, $y, $w, $h, $link) { $this->PageLinks[$this->page][] = array($x * $this->k, $this->hPt - $y * $this->k, $w * $this->k, $h*$this->k, $link); } /** * Prints a character string. The origin is on the left of the first charcter, on the baseline. This method allows to place a string precisely on the page, but it is usually easier to use Cell(), MultiCell() or Write() which are the standard methods to print text. * @param float $x Abscissa of the origin * @param float $y Ordinate of the origin * @param string $txt String to print * @since 1.0 * @see SetFont(), SetTextColor(), Cell(), MultiCell(), Write() */ public function Text($x, $y, $txt) { //Output a string if($this->rtl) { $xr = $this->w - $x - $this->GetStringWidth($txt); } else { $xr = $x; } $s = sprintf('BT %.2f %.2f Td (%s) Tj ET', $xr * $this->k, ($this->h-$y) * $this->k, $this->_escapetext($txt)); if($this->underline AND ($txt!='')) { $s .= ' '.$this->_dounderline($xr, $y, $txt); } if($this->ColorFlag) { $s='q '.$this->TextColor.' '.$s.' Q'; } $this->_out($s); } /** * Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br /> * This method is called automatically and should not be called directly by the application.<br /> * <b>Example:</b><br /> * The method is overriden in an inherited class in order to obtain a 3 column layout:<br /> * <pre> * class PDF extends TCPDF { * var $col=0; * * public function SetCol($col) { * //Move position to a column * $this->col=$col; * $x=10+$col*65; * $this->SetLeftMargin($x); * $this->SetX($x); * } * * public function AcceptPageBreak() { * if($this->col<2) { * //Go to next column * $this->SetCol($this->col+1); * $this->SetY(10); * return false; * } * else { * //Go back to first column and issue page break * $this->SetCol(0); * return true; * } * } * } * * $pdf=new PDF(); * $pdf->Open(); * $pdf->AddPage(); * $pdf->SetFont('Arial','',12); * for($i=1;$i<=300;$i++) { * $pdf->Cell(0,5,"Line $i",0,1); * } * $pdf->Output(); * </pre> * @return boolean * @since 1.4 * @see SetAutoPageBreak() */ public function AcceptPageBreak() { //Accept automatic page break or not return $this->AutoPageBreak; } /** * Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br /> * If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting. * @param float $w Cell width. If 0, the cell extends up to the right margin. * @param float $h Cell height. Default value: 0. * @param string $txt String to print. Default value: empty string. * @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -