/U', $html, -1, PREG_SPLIT_DELIM_CAPTURE); foreach ($a as $i => $e) { if ($i % 2 == 0) { //Text if ($this->HREF) $this->PutLink($this->HREF, $e); elseif ($this->ALIGN == 'center') $this->Cell(0, 5, $e, 0, 1, 'C'); else $this->Write(5, $e); } else { //Tag if ($e[0] == '/') $this->CloseTag(strtoupper(substr($e, 1))); else { //Extract properties $a2 = explode(' ', $e); $tag = strtoupper(array_shift($a2)); $prop = array(); foreach ($a2 as $v) { if (preg_match('/([^=]*)=["\']?([^"\']*)/', $v, $a3)) $prop[strtoupper($a3[1])] = $a3[2]; } $this->OpenTag($tag, $prop); } } } } function OpenTag($tag, $prop) { //Opening tag if ($tag == 'B' || $tag == 'I' || $tag == 'U') $this->SetStyle($tag, true); if ($tag == 'A') $this->HREF = $prop['HREF']; if ($tag == 'BR') $this->Ln(5); if ($tag == 'P') $this->ALIGN = $prop['ALIGN']; if ($tag == 'HR') { if (!empty($prop['WIDTH'])) $Width = $prop['WIDTH']; else $Width = $this->w - $this->lMargin - $this->rMargin; $this->Ln(2); $x = $this->GetX(); $y = $this->GetY(); $this->SetLineWidth(0.4); $this->Line($x, $y, $x + $Width, $y); $this->SetLineWidth(0.2); $this->Ln(2); } } function CloseTag($tag) { //Closing tag if ($tag == 'B' || $tag == 'I' || $tag == 'U') $this->SetStyle($tag, false); if ($tag == 'A') $this->HREF = ''; if ($tag == 'P') $this->ALIGN = ''; } function SetStyle($tag, $enable) { //Modify style and select corresponding font $this->$tag += ($enable ? 1 : -1); $style = ''; foreach (array('B', 'I', 'U') as $s) if ($this->$s > 0) $style .= $s; $this->SetFont('', $style); } function PutLink($URL, $txt) { //Put a hyperlink $this->SetTextColor(0, 0, 255); $this->SetStyle('U', true); $this->Write(5, $txt, $URL); $this->SetStyle('U', false); $this->SetTextColor(0); } function BreakCell($w, $h, $txt, $border = 0, $align = 'L', $fill = false) { // Output text with automatic or explicit line breaks if (!isset($this->CurrentFont)) $this->Error('No font has been set'); $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 && $s[$nb - 1] == "\n") $nb--; //*** Since we only create one Cell, there is no need to remove bottom border //*** code removed $b = 0; if ($border) $b = $border; $sep = -1; $i = 0; $j = 0; $l = 0; $ns = 0; $nl = 1; // *** stop as one cell is set // *** prevents last line if there allready is a cell $stop = false; while ($i < $nb && $stop === false) { // 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); // *** cell is set, so we stop // *** rest of code removed $stop = true; break; } // *** do not auto-break after space // *** code removed $l += $cw[$c]; if ($l > $wmax) { // *** sep always is -1 if there is no "\n" // *** if/else removed // Automatic line break if ($sep == -1) { if ($i == $j) $i++; if ($this->ws > 0) { $this->ws = 0; $this->_out('0 Tw'); } //*** changed lenght $i-$j in $i-$j-3 to make space for 3 dots //*** added 3 dots $this->Cell($w, $h, substr($s, $j, $i - $j - 3) . '.', $b, 2, $align, $fill); //dol '.' // *** cell is set, so we stop // *** rest of code removed $stop = true; break; // *** cell is set, so we stop } } else $i++; } // Last chunk // *** only if no cell is set if ($stop === false) { if ($this->ws > 0) { $this->ws = 0; $this->_out('0 Tw'); } //*** bottom border allready set //*** code removed $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); } $this->x = $this->lMargin; } function RotatedText($x, $y, $txt, $angle) { //Text rotated around its origin $this->Rotate($angle, $x, $y); $this->Text($x, $y, $txt); $this->Rotate(0); } function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle = 0) { $font_angle += 90 + $txt_angle; $txt_angle *= M_PI / 180; $font_angle *= M_PI / 180; $txt_dx = cos($txt_angle); $txt_dy = sin($txt_angle); $font_dx = cos($font_angle); $font_dy = sin($font_angle); $s = sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', $txt_dx, $txt_dy, $font_dx, $font_dy, $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); if ($this->ColorFlag) $s = 'q ' . $this->TextColor . ' ' . $s . ' Q'; $this->_out($s); } function TextWithDirection($x, $y, $txt, $direction = 'R') { if ($direction == 'R') $s = sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', 1, 0, 0, 1, $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); elseif ($direction == 'L') $s = sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', -1, 0, 0, -1, $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); elseif ($direction == 'U') $s = sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', 0, 1, -1, 0, $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); elseif ($direction == 'D') $s = sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET', 0, -1, 1, 0, $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); else $s = sprintf('BT %.2F %.2F Td (%s) Tj ET', $x * $this->k, ($this->h - $y) * $this->k, $this->_escape($txt)); if ($this->ColorFlag) $s = 'q ' . $this->TextColor . ' ' . $s . ' Q'; $this->_out($s); } function imageCenterCell($file, $x, $y, $w, $h) { if (!file_exists($file)) { $this->Error('File does not exist: ' . $file); } else { list($width, $height) = getimagesize($file); $ratio = $width / $height; $zoneRatio = $w / $h; // Same Ratio, put the image in the cell if ($ratio == $zoneRatio) { $this->Image($file, $x, $y, $w, $h); } // Image is vertical and cell is horizontal if ($ratio < $zoneRatio) { $neww = $h * $ratio; $newx = $x + (($w - $neww) / 2); $this->Image($file, $newx, $y, $neww); } // Image is horizontal and cell is vertical if ($ratio > $zoneRatio) { $newh = $w / $ratio; $newy = $y + (($h - $newh) / 2); $this->Image($file, $x, $newy, $w); } } } function MultiCell($w, $h, $txt, $border = 0, $align = 'J', $fill = false, $maxline = 0) { // Output text with automatic or explicit line breaks, at most $maxline lines if (!isset($this->CurrentFont)) $this->Error('No font has been set'); $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", '', (string)$txt); $nb = strlen($s); if ($nb > 0 && $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); $i++; $sep = -1; $j = $i; $l = 0; $ns = 0; $nl++; if ($border && $nl == 2) $b = $b2; if ($maxline && $nl > $maxline) return substr($s, $i); 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); } 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); $i = $sep + 1; } $sep = -1; $j = $i; $l = 0; $ns = 0; $nl++; if ($border && $nl == 2) $b = $b2; if ($maxline && $nl > $maxline) { if ($this->ws > 0) { $this->ws = 0; $this->_out('0 Tw'); } return substr($s, $i); } } else $i++; } // Last chunk if ($this->ws > 0) { $this->ws = 0; $this->_out('0 Tw'); } if ($border && is_int(strpos($border, 'B'))) $b .= 'B'; $this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill); $this->x = $this->lMargin; return ''; } }