fpdf.php
来自「php绿色服务器,让大家试用greenamp」· PHP 代码 · 共 2,044 行 · 第 1/5 页
PHP
2,044 行
if (($r == 0 && $g == 0 && $b == 0) || $g == -1) { $this->FillColor = sprintf('%.3f g', $r / 255); } else { $this->FillColor = sprintf('%.3f %.3f %.3f rg', $r / 255, $g / 255, $b / 255); } // end if... else... $this->ColorFlag = ($this->FillColor != $this->TextColor); // If a page is defined, applies this property if ($this->page > 0) { $this->_out($this->FillColor); } } // end of the "SetDrawColor()" method /** * Sets color for text * * @param integer The red level (0 to 255) * @param integer The green level (0 to 255) * @param integer The blue level (0 to 255) * * @access public */ function SetTextColor($r, $g = -1, $b =-1) { if (($r == 0 && $g == 0 && $b == 0) || $g == -1) { $this->TextColor = sprintf('%.3f g', $r / 255); } else { $this->TextColor = sprintf('%.3f %.3f %.3f rg', $r / 255, $g / 255, $b / 255); } // end if... else... $this->ColorFlag = ($this->FillColor != $this->TextColor); } // end of the "SetTextColor()" method /** * Sets the line width * * @param double The line width * * @access public */ function SetLineWidth($width) { $this->LineWidth = $width; // If a page is defined, applies this property if ($this->page > 0) { $this->_out(sprintf('%.2f w', $width * $this->k)); } } // end of the "SetLineWidth()" method /** * Draws a line * * @param double The horizontal position of the starting point * @param double The vertical position of the starting point * @param double The horizontal position of the ending point * @param double The vertical position of the ending point * * @access public */ function Line($x1, $y1, $x2, $y2) { $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)); } // end of the "Line()" method /** * Draws a rectangle * * @param double The horizontal position of the top left corner * @param double The vertical position of the top left corner * @param double The horizontal position of the bottom right corner * @param double The vertical position of the bottom right corner * @param string The rectangle style * * @access public */ function Rect($x, $y, $w, $h, $style = '') { if ($style == 'F') { $op = 'f'; } else if ($style == 'FD' || $style=='DF') { $op = 'B'; } else { $op = 'S'; } // end if... else if... else $this->_out(sprintf('%.2f %.2f %.2f %.2f re %s', $x * $this->k, ($this->h - $y) * $this->k, $w * $this->k, -$h * $this->k, $op)); } // end of the "Rect()" method /** * Adds a TrueType or Type1 font * * @param string The font name * @param string The font style (B, I, BI) * @param string The font file definition * * @access public */ function AddFont($family, $style = '', $file = '') { $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 (isset($GLOBALS['FPDF_font_path'])) { $file = $GLOBALS['FPDF_font_path'] . $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); // Searches existing encodings if ($diff) { $d = 0; $nb = count($this->diffs); for ($i = 1; $i <= $nb; $i++) { if ($this->diffs[$i] == $diff) { $d = $i; break; } // end if } // end for if ($d == 0) { $d = $nb + 1; $this->diffs[$d] = $diff; } // end if $this->fonts[$family . $style]['diff'] = $d; } // end if if ($file) { if ($type == 'TrueType') { $this->FontFiles[$file] = array('length1' => $originalsize); } else { $this->FontFiles[$file] = array('length1' => $size1, 'length2' => $size2); } } // end if } // end of the "AddFont()" method /** * Sets font size * * @param double The font size (in points) * * @access public */ function SetFontSize($size) { 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)); } } // end of the "SetFontSize()" method /** * Creates a new internal link * * @return integer The link id * * @access public */ function AddLink() { $n = count($this->links) + 1; $this->links[$n] = array(0, 0); return $n; } // end of the "AddLink()" method /** * Sets destination of internal link * * @param integer The link id * @param double The y position on the page * @param integer The page number * * @access public */ function SetLink($link, $y = 0, $page = -1) { if ($y == -1) { $y = $this->y; } if ($page == -1) { $page = $this->page; } $this->links[$link] = array($page, $y); } // end of the "SetLink()" method /** * Put a link inside a rectangular area of the page * * @param double The top left x position * @param double The top left y position * @param double The rectangle width * @param double The rectangle height * @param mixed The link id or an url * * @access 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); } // end of the "Link()" method /** * Outputs a string * * @param double The x position * @param double The y position * @param string The string * * @access public */ function Text($x, $y, $txt) { $txt = str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt))); $s = sprintf('BT %.2f %.2f Td (%s) Tj ET', $x * $this->k, ($this->h - $y) * $this->k, $txt); if ($this->underline && $txt != '') { $s .= ' ' . $this->_dounderline($x, $y, $txt); } if ($this->ColorFlag) { $s = 'q ' . $this->TextColor . ' ' . $s . ' Q'; } $this->_out($s); } // end of the "Text()" method /** * Gets whether automatic page break is on or not * * @return boolean Whether automatic page break is on or not * * @access public */ function AcceptPageBreak() { return $this->AutoPageBreak; } // end of the "AcceptPageBreak()" method /** * Output a cell * * @param double The cell width * @param double The cell height * @param string The text to output * @param mixed Wether to add borders or not (see the manual) * @param integer Where to put the cursor once the output is done * @param string Align mode * @param integer Whether to fill the cell with a color or not * @param mixed The link id or an url * * @access public */ function Cell($w, $h = 0, $txt = '', $border = 0, $ln = 0, $align = '', $fill = 0, $link = '') { $k = $this->k; if ($this->y + $h > $this->PageBreakTrigger && !$this->InFooter && $this->AcceptPageBreak()) { $x = $this->x; $ws = $this->ws; 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)); } } // end if if ($w == 0) { $w = $this->w - $this->rMargin - $this->x; } $s = ''; if ($fill == 1 || $border == 1) { if ($fill == 1) { $op = ($border == 1) ? 'B' : 'f'; } else { $op = 'S'; } $s = sprintf('%.2f %.2f %.2f %.2f re %s ', $this->x * $k, ($this->h - $this->y) * $k, $w * $k, -$h * $k, $op); } // end if if (is_string($border)) { $x = $this->x; $y = $this->y; if (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 (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 (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 (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); } } // end if if ($txt != '') { if ($align == 'R') { $dx = $w - $this->cMargin - $this->GetStringWidth($txt); } else if ($align == 'C') { $dx = ($w - $this->GetStringWidth($txt)) / 2; } else { $dx = $this->cMargin; } $txt = str_replace(')', '\\)', str_replace('(', '\\(', str_replace('\\', '\\\\', $txt))); if ($this->ColorFlag) { $s .= 'q ' . $this->TextColor . ' '; } $s .= sprintf('BT %.2f %.2f Td (%s) Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + .5 * $h + .3 * $this->FontSize)) * $k, $txt); if ($this->underline) { $s .= ' ' . $this->_dounderline($this->x+$dx, $this->y + .5 * $h + .3 * $this->FontSize, $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); } } // end if if ($s) { $this->_out($s); } $this->lasth = $h; if ($ln > 0) { // Go to next line $this->y += $h; if ($ln == 1) { $this->x = $this->lMargin; } } else { $this->x += $w; } } // end of the "Cell()" method /** * Output text with automatic or explicit line breaks * * @param double The cell width * @param double The cell height * @param string The text to output * @param mixed Wether to add borders or not (see the manual) * @param string Align mode * @param integer Whether to fill the cell with a color or not * * @access public */ function MultiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = 0) { // loic1: PHP3 compatibility // $cw = &$this->CurrentFont['cw']; if ($w == 0) { $w = $this->w - $this->lMargin - $this->x; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?