function cb_plain_list($matches)
 {
     list(, $type, $pattern) = $matches;
     $liarray = preg_split('/(\\n\\s?-\\s|\\[\\*\\])/', $pattern);
     $list = "\n";
     $i = 0;
     $pre = '  ';
     foreach ($liarray as $li) {
         $li = trim($li);
         if (empty($li)) {
             continue;
         }
         $i++;
         if (!empty($type)) {
             if ($type == 'i' || $type == 'I') {
                 $converter = new ConvertRoman($i);
                 $a = $converter->result();
                 if ($type == 'i') {
                     $a = strtolower($a);
                 }
                 $list .= $pre . "{$a}. {$li}\n";
             } elseif ($type == 'a' || $type == 'A') {
                 $converter = new ConvertRoman($i, TRUE);
                 $a = $converter->result();
                 if ($type == 'a') {
                     $a = strtolower($a);
                 }
                 $list .= $pre . "{$a}. {$li}\n";
             } else {
                 $list .= $pre . "{$i}. {$li}\n";
             }
         } else {
             $list .= $pre . "- {$li}\n";
         }
     }
     // A workaround for a bug in the parser
     $list = preg_replace('/ +?([a-zA-Z0-9\\-\\.]+?) \\n/is', '', $list);
     return $list;
 }
Пример #2
0
 /**
  * Process opening tags.
  * @param string $tag tag name (in uppercase)
  * @param string $attr tag attribute (in uppercase)
  * @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.
  * @access private
  */
 function openHTMLTagHandler($tag, $attr, $fill = 0)
 {
     //Opening tag
     switch ($tag) {
         case 'table':
             $this->Ln(0);
             // Linebreak to avoid wrong positioned first row
             if (isset($attr['border']) and $attr['border'] != '') {
                 $this->tableborder = $attr['border'];
             } else {
                 $this->tableborder = 0;
             }
             break;
         case 'tr':
             break;
         case 'td':
         case 'th':
             if (isset($attr['width']) && $attr['width'] != '' && is_numeric($attr['width'])) {
                 // Only numeric values, no values with percentages (%), % is not supported
                 $this->tdwidth = $attr['width'] / 4;
             } else {
                 $this->tdwidth = ($this->w - $this->lMargin - $this->rMargin) / $this->default_table_columns;
             }
             if (isset($attr['height']) and $attr['height'] != '') {
                 $this->tdheight = $attr['height'] / $this->k;
             } else {
                 $this->tdheight = $this->lasth;
             }
             if (isset($attr['align']) and $attr['align'] != '') {
                 switch ($attr['align']) {
                     case 'center':
                         $this->tdalign = "C";
                         break;
                     case 'right':
                         $this->tdalign = "R";
                         break;
                     default:
                     case 'left':
                         $this->tdalign = "L";
                         break;
                 }
             }
             if (isset($attr['bgcolor']) and $attr['bgcolor'] != '') {
                 $coul = $this->convertColorHexToDec($attr['bgcolor']);
                 $this->SetFillColor($coul['R'], $coul['G'], $coul['B']);
                 $this->tdbgcolor = true;
             }
             if ($tag == 'th') {
                 $this->setStyle('b', true);
             }
             $this->tdbegin = true;
             break;
         case 'hr':
             $this->Ln();
             if (isset($attr['width']) and $attr['width'] != '') {
                 $hrWidth = $attr['width'];
             } else {
                 $hrWidth = $this->w - $this->lMargin - $this->rMargin;
             }
             $x = $this->GetX();
             $y = $this->GetY();
             $this->SetLineWidth(0.2);
             $this->SetDrawColor(150, 150, 150);
             $this->Line($x, $y, $x + $hrWidth, $y);
             $this->SetDrawColor(0);
             $this->SetLineWidth(0.2);
             $this->Ln();
             break;
         case 'strong':
             $this->setStyle('b', true);
             break;
         case 'em':
             $this->setStyle('i', true);
             break;
         case 'b':
         case 'i':
         case 'u':
             $this->setStyle($tag, true);
             break;
         case 'a':
             $this->HREF = $attr['href'];
             break;
         case 'img':
             if (isset($attr['src'])) {
                 // replace relative path with real server path
                 $attr['src'] = str_replace(K_PATH_URL_CACHE, K_PATH_CACHE, $attr['src']);
                 if (!isset($attr['width'])) {
                     $attr['width'] = 0;
                 }
                 if (!isset($attr['height'])) {
                     $attr['height'] = 0;
                 }
                 $this->Image($attr['src'], $this->GetX(), $this->GetY(), $this->pixelsToMillimeters($attr['width']), $this->pixelsToMillimeters($attr['height']));
                 //$this->SetX($this->img_rb_x);
                 $this->SetY($this->img_rb_y);
             }
             break;
         case 'ul':
             $this->listordered = false;
             $this->listdepth++;
             $this->listcount[$this->listdepth] = 0;
             break;
         case 'ol':
             $this->listordered = empty($attr['type']) ? '1' : $attr['type'];
             // 1, a, A, i, I
             $this->listdepth++;
             $this->listcount[$this->listdepth] = 0;
             break;
         case 'li':
             $this->Ln();
             if ($this->listordered != false) {
                 $this->listcount[$this->listdepth]++;
                 if ($this->listordered == 'a' || $this->listordered == 'A') {
                     $converter = new ConvertRoman($this->listcount[$this->listdepth], true);
                     $a = $converter->result($this->listordered == 'a');
                 } elseif ($this->listordered == 'i' || $this->listordered == 'I') {
                     $converter = new ConvertRoman($this->listcount[$this->listdepth]);
                     $a = $converter->result($this->listordered == 'i');
                 } else {
                     $a = $this->listcount[$this->listdepth] . '.';
                 }
                 $this->lispacer = str_repeat('    ', $this->listdepth) . str_repeat(' ', 4 - strlen($a)) . $a . ' ';
                 // With correct alignment of the numbers ;)
             } else {
                 //unordered list simbol
                 $this->lispacer = str_repeat('    ', $this->listdepth) . '-  ';
             }
             $this->Write($this->lasth, $this->lispacer, '', $fill);
             break;
         case 'blockquote':
         case 'br':
             $this->Ln();
             if (strlen($this->lispacer) > 0) {
                 $this->x += $this->GetStringWidth($this->lispacer);
             }
             break;
         case 'p':
             $this->Ln();
             $this->Ln();
             break;
         case 'sup':
             $currentFontSize = $this->FontSize;
             $this->tempfontsize = $this->FontSizePt;
             $this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
             $this->SetXY($this->GetX(), $this->GetY() - ($currentFontSize - $this->FontSize) * K_SMALL_RATIO);
             break;
         case 'sub':
             $currentFontSize = $this->FontSize;
             $this->tempfontsize = $this->FontSizePt;
             $this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
             $this->SetXY($this->GetX(), $this->GetY() + ($currentFontSize - $this->FontSize) * K_SMALL_RATIO);
             break;
         case 'small':
             $currentFontSize = $this->FontSize;
             $this->tempfontsize = $this->FontSizePt;
             $this->SetFontSize($this->FontSizePt * K_SMALL_RATIO);
             $this->SetXY($this->GetX(), $this->GetY() + ($currentFontSize - $this->FontSize) / 3);
             break;
         case 'tt':
             $this->SetFont(strtolower($this->FontFamilyMono));
             $this->issetfont = true;
             break;
         case 'code':
             $this->SetTextColor(136, 0, 0);
             $this->issetcolor = true;
             $this->SetFont(strtolower($this->FontFamilyMono));
             $this->issetfont = true;
             break;
         case 'font':
             if (isset($attr['color']) and $attr['color'] != '') {
                 $coul = $this->convertColorHexToDec($attr['color']);
                 $this->SetTextColor($coul['R'], $coul['G'], $coul['B']);
                 $this->issetcolor = true;
             }
             if (isset($attr['face']) and in_array(strtolower($attr['face']), $this->fontlist)) {
                 $this->SetFont(strtolower($attr['face']));
                 $this->issetfont = true;
             }
             if (isset($attr['size'])) {
                 $headsize = intval($attr['size']);
             } else {
                 $headsize = 0;
             }
             $currentFontSize = $this->FontSize;
             $this->tempfontsize = $this->FontSizePt;
             $this->SetFontSize($this->FontSizePt + $headsize);
             $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
             break;
         case 'h1':
         case 'h2':
         case 'h3':
         case 'h4':
         case 'h5':
         case 'h6':
             $headsize = (4 - substr($tag, 1)) * 2;
             $currentFontSize = $this->FontSize;
             $this->tempfontsize = $this->FontSizePt;
             $this->SetFontSize($this->FontSizePt + $headsize);
             $this->setStyle('b', true);
             $this->lasth = $this->FontSize * K_CELL_HEIGHT_RATIO;
             break;
     }
 }