示例#1
0
文件: Css.php 项目: juchi/html2pdf
 /**
  * Set the New position for the current Tag
  *
  * @return void
  */
 public function setPosition()
 {
     // get the current position
     $currentX = $this->pdf->getX();
     $currentY = $this->pdf->getY();
     // save it
     $this->value['xc'] = $currentX;
     $this->value['yc'] = $currentY;
     if ($this->value['position'] == 'relative' || $this->value['position'] == 'absolute') {
         if ($this->value['right'] !== null) {
             $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width'];
             if ($this->value['margin']['r']) {
                 $x -= $this->value['margin']['r'];
             }
         } else {
             $x = $this->value['left'];
             if ($this->value['margin']['l']) {
                 $x += $this->value['margin']['l'];
             }
         }
         if ($this->value['bottom'] !== null) {
             $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height'];
             if ($this->value['margin']['b']) {
                 $y -= $this->value['margin']['b'];
             }
         } else {
             $y = $this->value['top'];
             if ($this->value['margin']['t']) {
                 $y += $this->value['margin']['t'];
             }
         }
         if ($this->value['position'] == 'relative') {
             $this->value['x'] = $currentX + $x;
             $this->value['y'] = $currentY + $y;
         } else {
             $this->value['x'] = $this->getLastAbsoluteX() + $x;
             $this->value['y'] = $this->getLastAbsoluteY() + $y;
         }
     } else {
         $this->value['x'] = $currentX;
         $this->value['y'] = $currentY;
         if ($this->value['margin']['l']) {
             $this->value['x'] += $this->value['margin']['l'];
         }
         if ($this->value['margin']['t']) {
             $this->value['y'] += $this->value['margin']['t'];
         }
     }
     // save the new position
     $this->pdf->setXY($this->value['x'], $this->value['y']);
 }
示例#2
0
 /**
  * tag : DRAW
  * mode : OPEN
  *
  * @param  array $param
  * @return boolean
  */
 protected function _tag_open_DRAW($param)
 {
     if ($this->_isForOneLine) {
         return false;
     }
     if ($this->_debugActif) {
         $this->_DEBUG_add('DRAW', true);
     }
     $this->parsingCss->save();
     $this->parsingCss->analyse('draw', $param);
     $this->parsingCss->fontSet();
     $alignObject = null;
     if ($this->parsingCss->value['margin-auto']) {
         $alignObject = 'center';
     }
     $overW = $this->parsingCss->value['width'];
     $overH = $this->parsingCss->value['height'];
     $this->parsingCss->value['old_maxX'] = $this->_maxX;
     $this->parsingCss->value['old_maxY'] = $this->_maxY;
     $this->parsingCss->value['old_maxH'] = $this->_maxH;
     $w = $this->parsingCss->value['width'];
     $h = $this->parsingCss->value['height'];
     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;
     }
     $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'];
     $marge['r'] = $this->parsingCss->value['border']['r']['width'];
     $marge['t'] = $this->parsingCss->value['border']['t']['width'];
     $marge['b'] = $this->parsingCss->value['border']['b']['width'];
     $this->parsingCss->value['width'] -= $marge['l'] + $marge['r'];
     $this->parsingCss->value['height'] -= $marge['t'] + $marge['b'];
     $overW -= $marge['l'] + $marge['r'];
     $overH -= $marge['t'] + $marge['b'];
     // clipping to draw only in the size opf the DRAW tag
     $this->pdf->clippingPathStart($this->parsingCss->value['x'] + $marge['l'], $this->parsingCss->value['y'] + $marge['t'], $this->parsingCss->value['width'], $this->parsingCss->value['height']);
     // left and right of the DRAW tag
     $mL = $this->parsingCss->value['x'] + $marge['l'];
     $mR = $this->pdf->getW() - $mL - $overW;
     // position of the DRAW tag
     $x = $this->parsingCss->value['x'] + $marge['l'];
     $y = $this->parsingCss->value['y'] + $marge['t'];
     // prepare the drawing area
     $this->_saveMargin($mL, 0, $mR);
     $this->pdf->setXY($x, $y);
     // we are in a draw tag
     $this->_isInDraw = array('x' => $x, 'y' => $y, 'w' => $overW, 'h' => $overH);
     // init the translate matrix : (0,0) => ($x, $y)
     $this->pdf->doTransform(array(1, 0, 0, 1, $x, $y));
     $this->pdf->SetAlpha(1.0);
     return true;
 }