Example #1
0
 /**
  * Gets rtf code of section.
  * @return string rtf code
  */
 public function getContent()
 {
     $content = '';
     //section is not first section
     if (!$this->_isFirst) {
         $content .= '\\sect \\sectd ';
     }
     //headers
     $headers = $this->_headers ? $this->_headers : $this->_rtf->getHeaders();
     if (!empty($headers)) {
         foreach ($headers as $value) {
             $content .= $value->getContent();
         }
     }
     //footers
     $footers = $this->_footers ? $this->_footers : $this->_rtf->getFooters();
     if (!empty($footers)) {
         foreach ($footers as $value) {
             $content .= $value->getContent();
         }
     }
     //borders
     $border = $this->_border ? $this->_border : $this->_rtf->getBorder();
     if ($border) {
         $content .= $border->getContent($this->_rtf, '\\pg');
     }
     //do not break within the section
     if ($this->_doNotBreak) {
         $content .= '\\sbknone ';
     }
     //set column index, when using more than one column for this section
     if ($this->_numberOfColumns > 1) {
         $content .= '\\cols' . $this->_numberOfColumns . ' ';
     }
     if ($this->_columnWidths === null) {
         if ($this->_spaceBetweenColumns) {
             $content .= '\\colsx' . round($this->_spaceBetweenColumns * PHPRtfLite::TWIPS_IN_CM) . ' ';
         }
     } else {
         $width = 0;
         foreach ($this->_columnWidths as $value) {
             $width += $value * PHPRtfLite::TWIPS_IN_CM;
         }
         $printableWidth = $this->_rtf->getPaperWidth() - $this->_rtf->getMarginLeft() - $this->_rtf->getMarginRight();
         $space = round(($printableWidth * PHPRtfLite::TWIPS_IN_CM - $width) / (count($this->_columnWidths) - 1));
         $i = 1;
         foreach ($this->_columnWidths as $key => $value) {
             $content .= '\\colno' . $i . '\\colw' . $value * PHPRtfLite::TWIPS_IN_CM;
             if (!empty($this->_columnWidths[$key])) {
                 $content .= '\\colsr' . $space;
             }
             $i++;
         }
         $content .= ' ';
     }
     if ($this->_lineBetweenColumns) {
         $content .= '\\linebetcol ';
     }
     /*---Page part---*/
     if ($this->_paperWidth) {
         $content .= '\\pgwsxn' . round($this->_paperWidth * PHPRtfLite::TWIPS_IN_CM) . ' ';
     }
     if ($this->_paperHeight) {
         $content .= '\\pghsxn' . round($this->_paperHeight * PHPRtfLite::TWIPS_IN_CM) . ' ';
     }
     if ($this->_marginLeft) {
         $content .= '\\marglsxn' . round($this->_marginLeft * PHPRtfLite::TWIPS_IN_CM) . ' ';
     }
     if ($this->_marginRight) {
         $content .= '\\margrsxn' . round($this->_marginRight * PHPRtfLite::TWIPS_IN_CM) . ' ';
     }
     if ($this->_marginTop) {
         $content .= '\\margtsxn' . round($this->_marginTop * PHPRtfLite::TWIPS_IN_CM) . ' ';
     }
     if ($this->_marginBottom) {
         $content .= '\\margbsxn' . round($this->_marginBottom * PHPRtfLite::TWIPS_IN_CM) . ' ';
     }
     if ($this->_gutter) {
         $content .= '\\guttersxn' . round($this->_gutter * PHPRtfLite::TWIPS_IN_CM) . ' ';
     }
     if ($this->_useMirrorMargins) {
         $content .= '\\margmirsxn ';
     }
     if ($this->_verticalAlignment) {
         switch ($this->_verticalAlignment) {
             case 'center':
                 $content .= '\\vertalc ';
                 break;
             case 'bottom':
                 $content .= '\\vertalb ';
                 break;
             case 'justify':
                 $content .= '\\vertalj ';
                 break;
             default:
                 $content .= '\\vertalt ';
                 break;
         }
     }
     $content .= "\r\n" . parent::getContent() . "\r\n";
     return $content;
 }
Example #2
0
 /**
  * Gets rtf code of footer
  *
  * @return string rtf code
  */
 public function getContent()
 {
     $content = isset($this->_offsetHeight) ? '\\footery' . round(PHPRtfLite::TWIPS_IN_CM * $this->_offsetHeight) . ' ' : '';
     $content .= '{\\' . $this->getTypeAsRtfCode() . ' ' . parent::getContent() . '\\par ' . '}';
     return $content . "\r\n";
 }
Example #3
0
 /**
  * Gets rtf code for cell
  *
  * @return string rtf code
  */
 public function getContent()
 {
     $content = '{';
     switch ($this->_alignment) {
         case self::TEXT_ALIGN_LEFT:
             $content .= '\\ql';
             break;
         case self::TEXT_ALIGN_CENTER:
             $content .= '\\qc';
             break;
         case self::TEXT_ALIGN_RIGHT:
             $content .= '\\qr';
             break;
         case self::TEXT_ALIGN_JUSTIFY:
             $content .= '\\qj';
             break;
     }
     if ($this->_font) {
         $content .= $this->_font->getContent($this->_table->getRtf());
     }
     $content .= parent::getContent() . '\\cell \\pard }' . "\r\n";
     return $content;
 }
Example #4
0
 /**
  * gets rtf instance
  *
  * @return PHPRtfLite
  */
 public function getRtf()
 {
     return $this->_container->getRtf();
 }
Example #5
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");
 }
Example #6
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");
 }