Ejemplo n.º 1
0
 /**
  * Pre-render cell to get recommended width and height
  * @param Core_Pdf_Page $page
  * @param $posX
  * @param $posY
  * @param bool $inContentArea
  * @throws Zend_Exception
  */
 public function preRender(Core_Pdf_Page $page, $posX, $posY, $inContentArea = true)
 {
     if (!$this->_width) {
         //no width given, get max width of page
         if ($inContentArea) {
             $width = $page->getWidth() - $posX - ($page->getMargin(Core_Pdf::LEFT) + $page->getMargin(Core_Pdf::RIGHT));
         } else {
             $width = $page->getWidth() - $posX;
         }
     } else {
         $width = $this->_width;
     }
     //calc max cell width
     $maxWidth = $width - ($this->_padding[Core_Pdf::LEFT] + $this->_padding[Core_Pdf::RIGHT]) - (+$this->_getBorderLineWidth(Core_Pdf::LEFT) + $this->_getBorderLineWidth(Core_Pdf::RIGHT));
     if ($this->_text) {
         //set font
         $page->setFont($this->_font, $this->_fontSize);
         //get height,width,lines
         $textProps = $page->getTextProperties($this->_text['text'], $maxWidth);
         //reset style
         $page->setStyle($page->getDefaultStyle());
         //set width
         if (!$this->_width) {
             //add padding
             $this->_recommendedWidth = $textProps['text_width'] + ($this->_padding[Core_Pdf::LEFT] + $this->_padding[Core_Pdf::RIGHT]) + $this->_getBorderLineWidth(Core_Pdf::LEFT) + $this->_getBorderLineWidth(Core_Pdf::RIGHT);
         } else {
             $this->_recommendedWidth = $textProps['max_width'];
         }
         if (!$this->_height) {
             //set height, add padding
             if ($this->_textLineSpacing) {
                 $height = $this->_textLineSpacing * count($textProps['lines']) + $textProps['height'];
             } else {
                 $height = $textProps['height'];
             }
             $this->_recommendedHeight = $height + ($this->_padding[Core_Pdf::TOP] + $this->_padding[Core_Pdf::BOTTOM]);
         }
         //store text props;
         $this->_text['width'] = $textProps['text_width'];
         $this->_text['max_width'] = $textProps['max_width'];
         $this->_text['height'] = $textProps['height'];
         $this->_text['lines'] = $textProps['lines'];
     } elseif ($this->_image) {
         $image = Zend_Pdf_Image::imageWithPath($this->_image['filename']);
         if (!$this->_width) {
             $this->_recommendedWidth = $this->_image['scale'] * $image->getPixelWidth() + ($this->_padding[Core_Pdf::LEFT] + $this->_padding[Core_Pdf::RIGHT]) + $this->_getBorderLineWidth(Core_Pdf::LEFT) + $this->_getBorderLineWidth(Core_Pdf::RIGHT);
         }
         if (!$this->_height) {
             $this->_recommendedHeight = $this->_image['scale'] * $image->getPixelHeight() + ($this->_padding[Core_Pdf::TOP] + $this->_padding[Core_Pdf::BOTTOM]);
         }
         $this->_image['image'] = $image;
         $this->_image['width'] = $this->_image['scale'] * $image->getPixelWidth();
         $this->_image['height'] = $this->_image['scale'] * $image->getPixelHeight();
     } else {
         throw new Zend_Exception("not defined", "preRender()");
     }
 }
Ejemplo n.º 2
0
 private function _drawHeader(Core_Pdf_Page $page, $currentPage)
 {
     if (!$this->_header) {
         return;
     }
     if ($page instanceof Core_Pdf_Page) {
         //set table width
         $currHeader = clone $this->_header;
         //check for special place holders
         $rows = $currHeader->getRows();
         foreach ($rows as $key => $row) {
             $row->setWidth($page->getWidth() - $this->_margin[Core_Pdf::LEFT] - $this->_margin[Core_Pdf::RIGHT]);
             $cols = $row->getColumns();
             $num = 0;
             foreach ($cols as $col) {
                 if ($col->hasText()) {
                     $num += $col->replaceText('@@CURRENT_PAGE', $currentPage);
                     $num += $col->replaceText('@@TOTAL_PAGES', count($this->pages));
                 }
             }
             if ($num > 0) {
                 $row->setColumns($cols);
                 $currHeader->replaceRow($row, $key);
             }
         }
         $page->addTable($currHeader, $this->_margin[Core_Pdf::LEFT], +$this->_headerYOffset - $this->_margin[Core_Pdf::TOP], false);
     }
 }
Ejemplo n.º 3
0
 /**
  * Pre-Render Row
  * @param Core_Pdf_Page $page
  * @param $posX
  * @param $posY
  * @param bool $inContentArea
  */
 public function preRender(Core_Pdf_Page $page, $posX, $posY, $inContentArea = true)
 {
     //pre-render each cell in row and get height
     $maxHeight = 0;
     //get width -> auto column width
     if ($this->_width) {
         //set given row width
         $maxRowWidth = $this->_width;
     } else {
         //no width given, use available page width
         if ($inContentArea) {
             $maxRowWidth = $page->getWidth() - $page->getMargin(Core_Pdf::LEFT) - $page->getMargin(Core_Pdf::RIGHT);
         } else {
             $maxRowWidth = $page->getWidth();
         }
     }
     if ($this->_forceUniformColumnWidth) {
         $uniformWidth = $maxRowWidth / $this->NumColumns;
     } else {
         //check if some colums have specific widths
         $fixedRowWidth = 0;
         $dynamicColumns = 0;
         $dynamicRowWidth = 0;
         foreach ($this->_cols as $col) {
             //set font if no font set
             if (!$col->getFont()) {
                 $col->setFont($this->_font, $this->_fontSize);
             }
             $w = $col->getWidth();
             if ($w) {
                 //column with specified width
                 $fixedRowWidth += $w;
             } else {
                 //column with no width specified
                 //pre-render to get a first estimation of width
                 $col->preRender($page, $posX, $posY, $inContentArea);
                 $dynamicRowWidth += $col->getRecommendedWidth();
                 $dynamicColumns++;
             }
         }
         $freeWidth = $maxRowWidth - $dynamicRowWidth - $fixedRowWidth;
         if ($dynamicColumns > 0) {
             $uniformWidth = ($maxRowWidth - $fixedRowWidth) / $dynamicColumns;
             $freeWidth = $freeWidth / $dynamicColumns;
         } else {
             //nothing to distribute (all fixed colum widths)
             $freeWidth = -1;
         }
         if ($freeWidth < 0) {
             //force text line break for dynamic rows
             $forceLineBreaking = true;
             $freeWidth = 0;
         } else {
             $forceLineBreaking = false;
         }
     }
     //get max column height
     foreach ($this->_cols as $col) {
         //set width ->auto-width=true
         if (!$col->getWidth()) {
             //calc width for colums without given width /aproximation
             if ($this->_forceUniformColumnWidth) {
                 $width = $uniformWidth;
             } else {
                 if ($col->hasImage()) {
                     //has priority
                     $width = $col->getRecommendedWidth() + $freeWidth;
                 } elseif ($col->hasText()) {
                     if ($forceLineBreaking && $col->getRecommendedWidth() > $uniformWidth) {
                         $width = $uniformWidth;
                     } else {
                         $width = $col->getRecommendedWidth() + $freeWidth;
                     }
                 }
             }
             $col->setWidth($width);
         }
         if (!$col->getFont()) {
             $col->setFont($this->_font, $this->_fontSize);
         }
         foreach ($this->_cellPadding as $pos => $val) {
             if (!$col->getPadding($pos)) {
                 $col->setPadding($pos, $val);
             }
         }
         $col->preRender($page, $posX, $posY);
         $height = $col->getRecommendedHeight();
         if ($height > $maxHeight) {
             $maxHeight = $height;
         }
     }
     //get border thickness of top&bottom row
     $this->_height = $maxHeight;
 }