/** * tag : DIV * mode : OPEN * * @param array $param * @param string $other name of tag that used the div tag * @return boolean */ protected function _tag_open_DIV($param, $other = 'div') { if ($this->_isForOneLine) { return false; } if ($this->_debugActif) { $this->_DEBUG_add(strtoupper($other), true); } $this->parsingCss->save(); $this->parsingCss->analyse($other, $param); $this->parsingCss->fontSet(); // for fieldset and legend if (in_array($other, array('fieldset', 'legend'))) { if (isset($param['moveTop'])) { $this->parsingCss->value['margin']['t'] += $param['moveTop']; } if (isset($param['moveLeft'])) { $this->parsingCss->value['margin']['l'] += $param['moveLeft']; } if (isset($param['moveDown'])) { $this->parsingCss->value['margin']['b'] += $param['moveDown']; } } $alignObject = null; if ($this->parsingCss->value['margin-auto']) { $alignObject = 'center'; } $marge = array(); $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03; $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03; $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03; $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03; // extract the content of the div $level = $this->parsingHtml->getLevel($this->_parsePos); // create a sub Html2Pdf to get the dimensions of the content of the div $w = 0; $h = 0; if (count($level)) { $sub = null; $this->_createSubHTML($sub); $sub->parsingHtml->code = $level; $sub->_makeHTMLcode(); $w = $sub->_maxX; $h = $sub->_maxY; $this->_destroySubHTML($sub); } $wReel = $w; $hReel = $h; $w += $marge['l'] + $marge['r'] + 0.001; $h += $marge['t'] + $marge['b'] + 0.001; if ($this->parsingCss->value['overflow'] == 'hidden') { $overW = max($w, $this->parsingCss->value['width']); $overH = max($h, $this->parsingCss->value['height']); $overflow = true; $this->parsingCss->value['old_maxX'] = $this->_maxX; $this->parsingCss->value['old_maxY'] = $this->_maxY; $this->parsingCss->value['old_maxH'] = $this->_maxH; $this->parsingCss->value['old_overflow'] = $this->_isInOverflow; $this->_isInOverflow = true; } else { $overW = null; $overH = null; $overflow = false; $this->parsingCss->value['width'] = max($w, $this->parsingCss->value['width']); $this->parsingCss->value['height'] = max($h, $this->parsingCss->value['height']); } switch ($this->parsingCss->value['rotate']) { case 90: $tmp = $overH; $overH = $overW; $overW = $tmp; $tmp = $hReel; $hReel = $wReel; $wReel = $tmp; unset($tmp); $w = $this->parsingCss->value['height']; $h = $this->parsingCss->value['width']; $tX = -$h; $tY = 0; break; case 180: $w = $this->parsingCss->value['width']; $h = $this->parsingCss->value['height']; $tX = -$w; $tY = -$h; break; case 270: $tmp = $overH; $overH = $overW; $overW = $tmp; $tmp = $hReel; $hReel = $wReel; $wReel = $tmp; unset($tmp); $w = $this->parsingCss->value['height']; $h = $this->parsingCss->value['width']; $tX = 0; $tY = -$w; break; default: $w = $this->parsingCss->value['width']; $h = $this->parsingCss->value['height']; $tX = 0; $tY = 0; break; } if (!$this->parsingCss->value['position']) { if ($w < $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin() && $this->pdf->getX() + $w >= $this->pdf->getW() - $this->pdf->getrMargin()) { $this->_tag_open_BR(array()); } if ($h < $this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin() && $this->pdf->getY() + $h >= $this->pdf->getH() - $this->pdf->getbMargin() && !$this->_isInOverflow) { $this->_setNewPage(); } $old = $this->parsingCss->getOldValues(); $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); if ($parentWidth > $w) { if ($alignObject == 'center') { $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); } elseif ($alignObject == 'right') { $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); } } $this->parsingCss->setPosition(); } else { $old = $this->parsingCss->getOldValues(); $parentWidth = $old['width'] ? $old['width'] : $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin(); if ($parentWidth > $w) { if ($alignObject == 'center') { $this->pdf->setX($this->pdf->getX() + ($parentWidth - $w) * 0.5); } elseif ($alignObject == 'right') { $this->pdf->setX($this->pdf->getX() + $parentWidth - $w); } } $this->parsingCss->setPosition(); $this->_saveMax(); $this->_maxX = 0; $this->_maxY = 0; $this->_maxH = 0; $this->_maxE = 0; } if ($this->parsingCss->value['rotate']) { $this->pdf->startTransform(); $this->pdf->setRotation($this->parsingCss->value['rotate']); $this->pdf->setTranslate($tX, $tY); } $this->_drawRectangle($this->parsingCss->value['x'], $this->parsingCss->value['y'], $this->parsingCss->value['width'], $this->parsingCss->value['height'], $this->parsingCss->value['border'], $this->parsingCss->value['padding'], 0, $this->parsingCss->value['background']); $marge = array(); $marge['l'] = $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['padding']['l'] + 0.03; $marge['r'] = $this->parsingCss->value['border']['r']['width'] + $this->parsingCss->value['padding']['r'] + 0.03; $marge['t'] = $this->parsingCss->value['border']['t']['width'] + $this->parsingCss->value['padding']['t'] + 0.03; $marge['b'] = $this->parsingCss->value['border']['b']['width'] + $this->parsingCss->value['padding']['b'] + 0.03; $this->parsingCss->value['width'] -= $marge['l'] + $marge['r']; $this->parsingCss->value['height'] -= $marge['t'] + $marge['b']; $xCorr = 0; $yCorr = 0; if (!$this->_subPart && !$this->_isSubPart) { switch ($this->parsingCss->value['text-align']) { case 'right': $xCorr = $this->parsingCss->value['width'] - $wReel; break; case 'center': $xCorr = ($this->parsingCss->value['width'] - $wReel) * 0.5; break; } if ($xCorr > 0) { $xCorr = 0; } switch ($this->parsingCss->value['vertical-align']) { case 'bottom': $yCorr = $this->parsingCss->value['height'] - $hReel; break; case 'middle': $yCorr = ($this->parsingCss->value['height'] - $hReel) * 0.5; break; } } if ($overflow) { $overW -= $marge['l'] + $marge['r']; $overH -= $marge['t'] + $marge['b']; $this->pdf->clippingPathStart($this->parsingCss->value['x'] + $marge['l'], $this->parsingCss->value['y'] + $marge['t'], $this->parsingCss->value['width'], $this->parsingCss->value['height']); $this->parsingCss->value['x'] += $xCorr; // marges from the dimension of the content $mL = $this->parsingCss->value['x'] + $marge['l']; $mR = $this->pdf->getW() - $mL - $overW; } else { // marges from the dimension of the div $mL = $this->parsingCss->value['x'] + $marge['l']; $mR = $this->pdf->getW() - $mL - $this->parsingCss->value['width']; } $x = $this->parsingCss->value['x'] + $marge['l']; $y = $this->parsingCss->value['y'] + $marge['t'] + $yCorr; $this->_saveMargin($mL, 0, $mR); $this->pdf->setXY($x, $y); $this->_setNewPositionForNewLine(); return true; }