Ejemplo n.º 1
0
 /**
  * renders rtf code of section
  */
 public function render()
 {
     $stream = $this->_rtf->getWriter();
     //headers
     $headers = $this->_headers ? $this->_headers : $this->_rtf->getHeaders();
     if (!empty($headers)) {
         foreach ($headers as $header) {
             $header->render();
         }
     }
     //footers
     $footers = $this->_footers ? $this->_footers : $this->_rtf->getFooters();
     if (!empty($footers)) {
         foreach ($footers as $footer) {
             $footer->render();
         }
     }
     //borders
     $border = $this->_border ? $this->_border : $this->_rtf->getBorder();
     if ($border) {
         $stream->write($border->getContent('\\pg'));
     }
     //do not break within the section
     if ($this->_doNotBreak) {
         $stream->write('\\sbknone ');
     }
     //set column index, when using more than one column for this section
     if ($this->_numberOfColumns > 1) {
         $stream->write('\\cols' . $this->_numberOfColumns . ' ');
     }
     if (empty($this->_columnWidths)) {
         if ($this->_spaceBetweenColumns) {
             $stream->write('\\colsx' . PHPRtfLite_Unit::getUnitInTwips($this->_spaceBetweenColumns) . ' ');
         }
     } else {
         $width = 0;
         foreach ($this->_columnWidths as $value) {
             $width += PHPRtfLite_Unit::getUnitInTwips($value);
         }
         $printableWidth = $this->_rtf->getPaperWidth() - $this->_rtf->getMarginLeft() - $this->_rtf->getMarginRight();
         $space = round((PHPRtfLite_Unit::getUnitInTwips($printableWidth) - $width) / (count($this->_columnWidths) - 1));
         $i = 1;
         foreach ($this->_columnWidths as $key => $value) {
             $stream->write('\\colno' . $i . '\\colw' . PHPRtfLite_Unit::getUnitInTwips($value));
             if (!empty($this->_columnWidths[$key])) {
                 $stream->write('\\colsr' . $space);
             }
             $i++;
         }
         $stream->write(' ');
     }
     if ($this->_lineBetweenColumns) {
         $stream->write('\\linebetcol ');
     }
     /*---Page part---*/
     if ($this->_paperWidth) {
         $stream->write('\\pgwsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_paperWidth) . ' ');
     }
     if ($this->_paperHeight) {
         $stream->write('\\pghsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_paperHeight) . ' ');
     }
     if ($this->_marginLeft) {
         $stream->write('\\marglsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginLeft) . ' ');
     }
     if ($this->_marginRight) {
         $stream->write('\\margrsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginRight) . ' ');
     }
     if ($this->_marginTop) {
         $stream->write('\\margtsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginTop) . ' ');
     }
     if ($this->_marginBottom) {
         $stream->write('\\margbsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginBottom) . ' ');
     }
     if ($this->_gutter) {
         $stream->write('\\guttersxn' . PHPRtfLite_Unit::getUnitInTwips($this->_gutter) . ' ');
     }
     if ($this->_useMirrorMargins) {
         $stream->write('\\margmirsxn ');
     }
     $stream->write("\r\n");
     parent::render();
     $stream->write("\r\n");
 }
Ejemplo n.º 2
0
 /**
  * renders rtf code for cell
  */
 public function render()
 {
     $stream = $this->_rtf->getWriter();
     $stream->write("\r\n");
     // renders container elements
     parent::render();
     $containerElements = $this->getElements();
     $numOfContainerElements = count($containerElements);
     if ($this->_table->isNestedTable()) {
         // if last container element is not a nested table, close cell
         if ($numOfContainerElements == 0 || !$containerElements[$numOfContainerElements - 1] instanceof PHPRtfLite_Table_Nested) {
             $stream->write('{\\nestcell{\\nonesttables\\par}\\pard}' . "\r\n");
             // if last cell of row, close row
             if ($this->getColumnIndex() == $this->_table->getColumnsCount()) {
                 $stream->write('{\\*\\nesttableprops ');
                 $row = $this->_table->getRow($this->_rowIndex);
                 $this->_table->renderRowDefinition($row);
                 $stream->write('\\nestrow}');
             }
         }
     } else {
         if ($numOfContainerElements > 0 && $containerElements[$numOfContainerElements - 1] instanceof PHPRtfLite_Table_Nested) {
             $stream->write('\\intbl\\itap1\\~');
         }
         // closing tag for cell definition
         $stream->write('\\cell');
     }
     $stream->write("\r\n");
 }