getWriter() public méthode

gets writer
public getWriter ( ) : PHPRtfLite_Writer_Interface
Résultat PHPRtfLite_Writer_Interface
Exemple #1
0
 /**
  * tests render
  */
 public function testRender()
 {
     $header = new PHPRtfLite_Container_Header($this->_rtf);
     $header->writeText('hello world and see my rtf header!');
     $header->render();
     $this->assertEquals('{\\header {hello world and see my rtf header!}' . "\r\n\\par}\r\n", $this->_rtf->getWriter()->getContent());
 }
 /**
  * tests render().
  */
 public function testRender()
 {
     $hyperlink = new PHPRtfLite_Element_Hyperlink($this->_rtf, 'My link text!');
     $hyperlink->setHyperlink('http://www.phprtf.com/');
     $hyperlink->render();
     $expected = '{\\field {\\*\\fldinst {HYPERLINK "http://www.phprtf.com/"}}{\\fldrslt {My link text!}}}';
     $this->assertEquals($expected, trim($this->_rtf->getWriter()->getContent()));
 }
Exemple #3
0
 /**
  *
  */
 public function testRenderImageUnresized()
 {
     $source = dirname(__FILE__) . '/../../samples/sources/rtf_thumb.jpg';
     if (!is_file($source)) {
         $this->markTestSkipped('Source image file could not be found!');
         return;
     }
     $image = PHPRtfLite_Image::createFromFile($this->_rtf, $source);
     $image->render();
     $expected = self::getRtfThumbHexCode(510, 510);
     $this->assertEquals($expected, $this->_rtf->getWriter()->getContent());
 }
Exemple #4
0
 /**
  * renders list
  */
 public function render()
 {
     $stream = $this->_rtf->getWriter();
     $number = 0;
     foreach ($this->_items as $item) {
         // item is a list
         if ($item instanceof PHPRtfLite_List_Numbering) {
             if ($this instanceof PHPRtfLite_List_Numbering) {
                 $item->setPrefix($this->_prefix . $this->getNumber($number) . $this->_separator);
                 $item->setSuffix($this->_suffix);
             }
         } else {
             $number++;
             $listCharFontIndex = $this->getListCharFontIndex();
             $listCharacter = $this->getListCharacter($number);
             $listCharDefinition = '{\\*\\pn\\pnlvlblt' . '\\pnf' . $listCharFontIndex;
             if ($this->_font) {
                 $listCharDefinition .= '\\pnfs' . $this->_font->getSize() * 2;
                 if ($color = $this->_font->getColor()) {
                     $listCharDefinition .= '\\pncf' . $this->_rtf->getColorTable()->getColorIndex($color);
                 }
             }
             $listCharDefinition .= '\\pnindent0{\\pntxtb ' . $listCharacter . '}}';
             $textIndent = $this->_listIndent + $this->_textIndent;
             $stream->write('\\nowidctlpar\\fi-' . $this->_listIndent . '\\li' . $textIndent . "\r\n");
             $stream->write($listCharDefinition);
         }
         // renders item
         $item->render();
         if (false == $item instanceof PHPRtfLite_List) {
             $stream->write('\\par\\pard' . "\r\n");
         }
     }
 }
Exemple #5
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");
 }
Exemple #6
0
 /**
  * renders rtf code for that container
  *
  * @return string rtf code
  */
 public function render()
 {
     $stream = $this->_rtf->getWriter();
     if ($this instanceof PHPRtfLite_Table_Cell && $this->countElements() == 0) {
         $stream->write('{');
         $font = $this->getCellFont($this);
         if ($font) {
             $stream->write($font->getContent());
         }
         if (!$this->isVerticalMerged() && !$this->isHorizontalMerged() || $this->isVerticalMergedFirstInRange()) {
             $stream->write('{\\~}');
         }
         $stream->write('}\\intbl');
     }
     $lastKey = $this->countElements() - 1;
     foreach ($this->_elements as $key => $element) {
         if ($this instanceof PHPRtfLite_Table_Cell && !$element instanceof PHPRtfLite_Table) {
             // table cell initialization
             $stream->write('\\intbl\\itap' . $this->getTable()->getNestDepth() . "\r\n");
             $stream->write($this->getCellAlignment());
         }
         if ($element instanceof PHPRtfLite_Element_Plain) {
             $element->render();
             continue;
         }
         $parFormat = null;
         if (!$element instanceof PHPRtfLite_Table) {
             $parFormat = $element->getParFormat();
         }
         if ($parFormat) {
             $stream->write($this->_pard);
             if ($this instanceof PHPRtfLite_Table_Cell && $lastKey != $key) {
                 $stream->write('{');
             }
             $stream->write($parFormat->getContent());
         }
         $font = $this->getCellFont($element);
         if ($font) {
             $stream->write($font->getContent());
         }
         $element->render();
         if ($this->needToAddParagraphEnd($key)) {
             $stream->write('\\par ');
         }
         if ($font) {
             $stream->write($font->getClosingContent());
         }
         if ($parFormat && $this instanceof PHPRtfLite_Table_Cell && $lastKey != $key) {
             $stream->write('}');
         }
     }
 }
 /**
  * renders form field
  */
 public function render()
 {
     $stream = $this->_rtf->getWriter();
     $stream->write(' ');
     if ($this->_font) {
         $stream->write('{' . $this->_font->getContent());
     }
     $defaultValue = PHPRtfLite_Utf8::getUnicodeEntities($this->_defaultValue, $this->_rtf->getCharset());
     $content = '{\\field' . '{\\*\\fldinst ' . $this->getType() . '  {\\*\\formfield' . $this->getRtfCode() . '}' . '}{\\fldrslt ' . $defaultValue . '}}';
     $stream->write($content);
     if ($this->_font) {
         $stream->write($this->_font->getClosingContent() . '}');
     }
     $stream->write(' ');
 }
Exemple #8
0
 /**
  * writes image into rtf stream
  *
  * @param integer $startFrom
  */
 protected function writeIntoRtfStream($startFrom = 0)
 {
     fseek($this->_stream, $startFrom);
     $rtfImageType = $this->getImageTypeAsRtf();
     $rtfStream = $this->_rtf->getWriter();
     $rtfStream->write('{\\*\\shppict {\\pict');
     if ($this->_border) {
         $rtfStream->write($this->_border->getContent());
     }
     $rtfStream->write($rtfImageType . '\\picscalex100\\picscaley100');
     $rtfStream->write('\\picwgoal' . $this->getImageRtfWidth());
     $rtfStream->write('\\pichgoal' . $this->getImageRtfHeight());
     $rtfStream->write(' ');
     while (!feof($this->_stream)) {
         $stringBuffer = fread($this->_stream, 1024);
         $stringHex = bin2hex($stringBuffer);
         $rtfStream->write($stringHex);
     }
     $rtfStream->write('}}');
 }
 /**
  * tests render
  */
 public function testRender()
 {
     $footnote = new PHPRtfLite_Footnote($this->_rtf, 'hello rtf world!');
     $footnote->render();
     $this->assertEquals('\\chftn {\\footnote\\pard\\plain \\lin283\\fi-283 \\fs20 {\\up6\\chftn}' . "\r\n" . 'hello rtf world!} ', $this->_rtf->getWriter()->getContent());
 }
Exemple #10
0
 /**
  * renders footnote/endnote
  */
 public function render()
 {
     $stream = $this->_rtf->getWriter();
     $typeSetting = $this->_typeSettingType != self::TYPE_NORMAL ? '\\' . $this->_typeSettingType : '';
     $stream->write('{' . $typeSetting . '\\chftn}' . '{' . $this->getTypeAsRtfCode() . '\\pard\\plain\\lin283\\fi-283 ');
     if ($this->_parFormat) {
         $stream->write($this->_parFormat->getContent());
     }
     if ($this->_font) {
         $stream->write($this->_font->getContent());
     }
     $stream->write('{\\up6\\chftn}' . "\r\n" . PHPRtfLite::quoteRtfCode($this->_text) . '} ');
 }