Пример #1
0
 /**
  * display a image
  *
  * @access protected
  * @param  string $src
  * @param  boolean $subLi if true=image of a list
  * @return boolean depending on "isForOneLine"
  */
 protected function _drawImage($src, $subLi = false)
 {
     // get the size of the image
     // WARNING : if URL, "allow_url_fopen" must turned to "on" in php.ini
     $infos = @getimagesize($src);
     // if the image does not exist, or can not be loaded
     if (count($infos) < 2) {
         // if the test is activ => exception
         if ($this->_testIsImage) {
             throw new HTML2PDF_exception(6, $src);
         }
         // else, display a gray rectangle
         $src = null;
         $infos = array(16, 16);
     }
     // convert the size of the image in the unit of the PDF
     $imageWidth = $infos[0] / $this->pdf->getK();
     $imageHeight = $infos[1] / $this->pdf->getK();
     // calculate the size from the css style
     if ($this->parsingCss->value['width'] && $this->parsingCss->value['height']) {
         $w = $this->parsingCss->value['width'];
         $h = $this->parsingCss->value['height'];
     } else {
         if ($this->parsingCss->value['width']) {
             $w = $this->parsingCss->value['width'];
             $h = $imageHeight * $w / $imageWidth;
         } else {
             if ($this->parsingCss->value['height']) {
                 $h = $this->parsingCss->value['height'];
                 $w = $imageWidth * $h / $imageHeight;
             } else {
                 // convert px to pt
                 $w = 72.0 / 96.0 * $imageWidth;
                 $h = 72.0 / 96.0 * $imageHeight;
             }
         }
     }
     // are we in a float
     $float = $this->parsingCss->getFloat();
     // if we are in a float, but if something else if on the line => Break Line
     if ($float && $this->_maxH) {
         // make the break line (false if we are in "_isForOneLine" mode)
         if (!$this->_tag_open_BR(array())) {
             return false;
         }
     }
     // position of the image
     $x = $this->pdf->getX();
     $y = $this->pdf->getY();
     // if the image can not be put on the current line => new line
     if (!$float && $x + $w > $this->pdf->getW() - $this->pdf->getrMargin() && $this->_maxH) {
         if ($this->_isForOneLine) {
             return false;
         }
         // set the new line
         $hnl = max($this->_maxH, $this->parsingCss->getLineHeight());
         $this->_setNewLine($hnl);
         // get the new position
         $x = $this->pdf->getX();
         $y = $this->pdf->getY();
     }
     // if the image can not be put on the current page
     if ($y + $h > $this->pdf->getH() - $this->pdf->getbMargin() && !$this->_isInOverflow) {
         // new page
         $this->_setNewPage();
         // get the new position
         $x = $this->pdf->getX();
         $y = $this->pdf->getY();
     }
     // correction for display the image of a list
     $hT = 0.8 * $this->parsingCss->value['font-size'];
     if ($subLi && $h < $hT) {
         $y += $hT - $h;
     }
     // add the margin top
     $yc = $y - $this->parsingCss->value['margin']['t'];
     // get the width and the position of the parent
     $old = $this->parsingCss->getOldValues();
     if ($old['width']) {
         $parentWidth = $old['width'];
         $parentX = $x;
     } else {
         $parentWidth = $this->pdf->getW() - $this->pdf->getlMargin() - $this->pdf->getrMargin();
         $parentX = $this->pdf->getlMargin();
     }
     // if we are in a gloat => adapt the parent position and width
     if ($float) {
         list($lx, $rx) = $this->_getMargins($yc);
         $parentX = $lx;
         $parentWidth = $rx - $lx;
     }
     // calculate the position of the image, if align to the right
     if ($parentWidth > $w && $float != 'left') {
         if ($float == 'right' || $this->parsingCss->value['text-align'] == 'li_right') {
             $x = $parentX + $parentWidth - $w - $this->parsingCss->value['margin']['r'] - $this->parsingCss->value['margin']['l'];
         }
     }
     // display the image
     if (!$this->_subPart && !$this->_isSubPart) {
         if ($src) {
             $this->pdf->Image($src, $x, $y, $w, $h, '', $this->_isInLink);
         } else {
             // rectangle if the image can not be loaded
             $this->pdf->setFillColorArray(array(240, 220, 220));
             $this->pdf->Rect($x, $y, $w, $h, 'F');
         }
     }
     // apply the margins
     $x -= $this->parsingCss->value['margin']['l'];
     $y -= $this->parsingCss->value['margin']['t'];
     $w += $this->parsingCss->value['margin']['l'] + $this->parsingCss->value['margin']['r'];
     $h += $this->parsingCss->value['margin']['t'] + $this->parsingCss->value['margin']['b'];
     if ($float == 'left') {
         // save the current max
         $this->_maxX = max($this->_maxX, $x + $w);
         $this->_maxY = max($this->_maxY, $y + $h);
         // add the image to the margins
         $this->_addMargins($float, $x, $y, $x + $w, $y + $h);
         // get the new position
         list($lx, $rx) = $this->_getMargins($yc);
         $this->pdf->setXY($lx, $yc);
     } else {
         if ($float == 'right') {
             // save the current max. We don't save the X because it is not the real max of the line
             $this->_maxY = max($this->_maxY, $y + $h);
             // add the image to the margins
             $this->_addMargins($float, $x, $y, $x + $w, $y + $h);
             // get the new position
             list($lx, $rx) = $this->_getMargins($yc);
             $this->pdf->setXY($lx, $yc);
         } else {
             // set the new position at the end of the image
             $this->pdf->setX($x + $w);
             // save the current max
             $this->_maxX = max($this->_maxX, $x + $w);
             $this->_maxY = max($this->_maxY, $y + $h);
             $this->_maxH = max($this->_maxH, $h);
         }
     }
     return true;
 }