Beispiel #1
0
 /**
  * tag : TD
  * mode : OPEN
  *
  * @param  array $param
  * @return boolean
  */
 protected function _tag_open_TD($param, $other = 'td')
 {
     if ($this->_isForOneLine) {
         return false;
     }
     $this->_maxH = 0;
     $param['cellpadding'] = HTML2PDF::$_tables[$param['num']]['cellpadding'] . 'mm';
     $param['cellspacing'] = HTML2PDF::$_tables[$param['num']]['cellspacing'] . 'mm';
     // specific style for LI
     if ($other == 'li') {
         $specialLi = true;
     } else {
         $specialLi = false;
         if ($other == 'li_sub') {
             $param['style']['border'] = 'none';
             $param['style']['background-color'] = 'transparent';
             $param['style']['background-image'] = 'none';
             $param['style']['background-position'] = '';
             $param['style']['background-repeat'] = '';
             $other = 'li';
         }
     }
     // get the properties of the TD
     $x = HTML2PDF::$_tables[$param['num']]['td_curr'];
     $y = HTML2PDF::$_tables[$param['num']]['tr_curr'] - 1;
     $colspan = isset($param['colspan']) ? $param['colspan'] : 1;
     $rowspan = isset($param['rowspan']) ? $param['rowspan'] : 1;
     // flag for collapse table
     $collapse = false;
     // specific traitment for TD and TH
     if (in_array($other, array('td', 'th'))) {
         // id of the column
         $numCol = isset(HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr']) ? HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr'] : HTML2PDF::$_tables[$param['num']]['corr_x'];
         // we get the properties of the COL tag, if exist
         if (isset(HTML2PDF::$_tables[$param['num']]['cols'][$numCol])) {
             $colParam = HTML2PDF::$_tables[$param['num']]['cols'][$numCol];
             // for colspans => we get all the neede widths
             $colParam['style']['width'] = array();
             for ($k = 0; $k < $colspan; $k++) {
                 if (isset(HTML2PDF::$_tables[$param['num']]['cols'][$numCol + $k]['style']['width'])) {
                     $colParam['style']['width'][] = HTML2PDF::$_tables[$param['num']]['cols'][$numCol + $k]['style']['width'];
                 }
             }
             // calculate the total width of the column
             $total = '';
             $last = $this->parsingCss->getLastWidth();
             if (count($colParam['style']['width'])) {
                 $total = $colParam['style']['width'][0];
                 unset($colParam['style']['width'][0]);
                 foreach ($colParam['style']['width'] as $width) {
                     if (substr($total, -1) == '%' && substr($width, -1) == '%') {
                         $total = str_replace('%', '', $total) + str_replace('%', '', $width) . '%';
                     } else {
                         $total = $this->parsingCss->ConvertToMM($total, $last) + $this->parsingCss->ConvertToMM($width, $last) . 'mm';
                     }
                 }
             }
             // get the final width
             if ($total) {
                 $colParam['style']['width'] = $total;
             } else {
                 unset($colParam['style']['width']);
             }
             // merge the styles of the COL and the TD
             $param['style'] = array_merge($colParam['style'], $param['style']);
             // merge the class of the COL and the TD
             if (isset($colParam['class'])) {
                 $param['class'] = $colParam['class'] . (isset($param['class']) ? ' ' . $param['class'] : '');
             }
         }
         $collapse = isset($this->parsingCss->value['border']['collapse']) ? $this->parsingCss->value['border']['collapse'] : false;
     }
     $this->parsingCss->save();
     // legacy for TD and TH
     $legacy = null;
     if (in_array($other, array('td', 'th'))) {
         $legacy = array();
         $old = $this->parsingCss->getLastValue('background');
         if ($old && ($old['color'] || $old['image'])) {
             $legacy['background'] = $old;
         }
         if (HTML2PDF::$_tables[$param['num']]['border']) {
             $legacy['border'] = array();
             $legacy['border']['l'] = HTML2PDF::$_tables[$param['num']]['border'];
             $legacy['border']['t'] = HTML2PDF::$_tables[$param['num']]['border'];
             $legacy['border']['r'] = HTML2PDF::$_tables[$param['num']]['border'];
             $legacy['border']['b'] = HTML2PDF::$_tables[$param['num']]['border'];
         }
     }
     $return = $this->parsingCss->analyse($other, $param, $legacy);
     if ($specialLi) {
         $this->parsingCss->value['width'] -= $this->parsingCss->ConvertToMM($this->_listeGetWidth());
         $this->parsingCss->value['width'] -= $this->parsingCss->ConvertToMM($this->_listeGetPadding());
     }
     $this->parsingCss->setPosition();
     $this->parsingCss->fontSet();
     // if tale collapse => modify the borders
     if ($collapse) {
         if (!$this->_subPart) {
             if (HTML2PDF::$_tables[$param['num']]['tr_curr'] > 1 && !HTML2PDF::$_tables[$param['num']]['new_page'] || !$this->_isInThead && count(HTML2PDF::$_tables[$param['num']]['thead']['code'])) {
                 $this->parsingCss->value['border']['t'] = $this->parsingCss->readBorder('none');
             }
         }
         if (HTML2PDF::$_tables[$param['num']]['td_curr'] > 0) {
             if (!$return) {
                 $this->parsingCss->value['width'] += $this->parsingCss->value['border']['l']['width'];
             }
             $this->parsingCss->value['border']['l'] = $this->parsingCss->readBorder('none');
         }
     }
     // margins of the table
     $marge = array();
     $marge['t'] = $this->parsingCss->value['padding']['t'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['t']['width'];
     $marge['r'] = $this->parsingCss->value['padding']['r'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['r']['width'];
     $marge['b'] = $this->parsingCss->value['padding']['b'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['b']['width'];
     $marge['l'] = $this->parsingCss->value['padding']['l'] + 0.5 * HTML2PDF::$_tables[$param['num']]['cellspacing'] + $this->parsingCss->value['border']['l']['width'];
     // if we are in a sub HTML
     if ($this->_subPart) {
         // new position in the table
         HTML2PDF::$_tables[$param['num']]['td_curr']++;
         HTML2PDF::$_tables[$param['num']]['cases'][$y][$x] = array();
         HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'] = 0;
         HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'] = 0;
         HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['dw'] = 0;
         HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['colspan'] = $colspan;
         HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['rowspan'] = $rowspan;
         HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Xr'] = HTML2PDF::$_tables[$param['num']]['corr_x'];
         HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['Yr'] = HTML2PDF::$_tables[$param['num']]['corr_y'];
         // prepare the mapping for rowspan and colspan
         for ($j = 0; $j < $rowspan; $j++) {
             for ($i = 0; $i < $colspan; $i++) {
                 HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y'] + $j][HTML2PDF::$_tables[$param['num']]['corr_x'] + $i] = $i + $j > 0 ? '' : array($x, $y, $colspan, $rowspan);
             }
         }
         HTML2PDF::$_tables[$param['num']]['corr_x'] += $colspan;
         while (isset(HTML2PDF::$_tables[$param['num']]['corr'][HTML2PDF::$_tables[$param['num']]['corr_y']][HTML2PDF::$_tables[$param['num']]['corr_x']])) {
             HTML2PDF::$_tables[$param['num']]['corr_x']++;
         }
         // extract the content of the TD, and calculate his size
         $level = $this->parsingHtml->getLevel($this->_tempPos);
         $this->_createSubHTML($this->_subHtml);
         $this->_subHtml->parsingHtml->code = $level;
         $this->_subHtml->_makeHTMLcode();
         $this->_tempPos += count($level);
     } else {
         // new position in the table
         HTML2PDF::$_tables[$param['num']]['td_curr']++;
         HTML2PDF::$_tables[$param['num']]['td_x'] += HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['dw'];
         // borders and background of the TD
         $this->_drawRectangle(HTML2PDF::$_tables[$param['num']]['td_x'], HTML2PDF::$_tables[$param['num']]['td_y'], HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'], HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'], $this->parsingCss->value['border'], $this->parsingCss->value['padding'], HTML2PDF::$_tables[$param['num']]['cellspacing'] * 0.5, $this->parsingCss->value['background']);
         $this->parsingCss->value['width'] = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['w'] - $marge['l'] - $marge['r'];
         // marges = size of the TD
         $mL = HTML2PDF::$_tables[$param['num']]['td_x'] + $marge['l'];
         $mR = $this->pdf->getW() - $mL - $this->parsingCss->value['width'];
         $this->_saveMargin($mL, 0, $mR);
         // position of the content, from vertical-align
         $hCorr = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['h'];
         $hReel = HTML2PDF::$_tables[$param['num']]['cases'][$y][$x]['real_h'];
         switch ($this->parsingCss->value['vertical-align']) {
             case 'bottom':
                 $yCorr = $hCorr - $hReel;
                 break;
             case 'middle':
                 $yCorr = ($hCorr - $hReel) * 0.5;
                 break;
             case 'top':
             default:
                 $yCorr = 0;
                 break;
         }
         //  position of the content
         $x = HTML2PDF::$_tables[$param['num']]['td_x'] + $marge['l'];
         $y = HTML2PDF::$_tables[$param['num']]['td_y'] + $marge['t'] + $yCorr;
         $this->pdf->setXY($x, $y);
         $this->_setNewPositionForNewLine();
     }
     return true;
 }