/** * 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('}}'); }
/** * Gets rtf code of image * * @return string rtf code */ public function getContent() { $content = '{\\pict'; if ($this->_border) { $content .= $this->_border->getContent($this->_rtf); } $content .= '\\picwgoal' . $this->getImageWidth(); $content .= '\\pichgoal' . $this->getImageHeight(); switch ($this->_extension) { case 'jpeg': case 'jpg': $content .= '\\jpegblip '; break; case 'png': $content .= '\\pngblip '; break; } $content .= $this->getFileAsHex(); $content .= '}'; return $content; }
/** * prepares rtf contents */ protected function prepare() { $part = $this->getInfoPart(); //page properties $part .= $this->_isLandscape ? '\\landscape ' : ''; $part .= '\\deftab' . round(self::TWIPS_IN_CM * $this->_defaultTabWidth) . ' '; $part .= '\\paperw' . round(self::TWIPS_IN_CM * $this->_paperWidth) . ' '; $part .= '\\paperh' . round(self::TWIPS_IN_CM * $this->_paperHeight) . ' '; $part .= '\\margl' . round(self::TWIPS_IN_CM * $this->_marginLeft) . ' '; $part .= '\\margr' . round(self::TWIPS_IN_CM * $this->_marginRight) . ' '; $part .= '\\margt' . round(self::TWIPS_IN_CM * $this->_marginTop) . ' '; $part .= '\\margb' . round(self::TWIPS_IN_CM * $this->_marginBottom) . ' '; if (null !== $this->_gutter) { $part .= '\\gutter' . round($this->_gutter * self::TWIPS_IN_CM) . ' '; } if (true == $this->_useMirrorMargins) { $part .= '\\margmirror '; } if (null !== $this->_viewMode) { $part .= '\\viewkind' . $this->_viewMode . ' '; } if (null !== $this->_zoomMode) { $part .= '\\viewzk' . $this->_zoomMode . ' '; } if (null !== $this->_zoomLevel) { $part .= '\\viewscale' . $this->_zoomLevel . ' '; } if ($this->_sections[0] && $this->_sections[0]->getBorder()) { $part .= $this->_sections[0]->getBorder()->getContent($this, '\\pg'); } elseif ($this->_border) { $part .= $this->_border->getContent($this, '\\pg'); } //headers and footers properties if ($this->_useOddEvenDifferent) { $part .= '\\facingp '; } if ($this->_titlepg) { $part .= '\\titlepg '; } // document header definiton for footnotes and endnotes $part .= $this->getNoteDocHeadDefinition()->getContent(); //headers and footers if there are no sections if (count($this->_sections) == 0) { foreach ($this->_headers as $header) { $part .= $header->getContent(); } foreach ($this->_footers as $footer) { $part .= $footer->getContent(); } } //sections foreach ($this->_sections as $key => $section) { $part .= $section->getContent(); } $this->_content = '{\\rtf\\ansi\\deff0 \\r\\n'; $this->_content .= $this->getFontTable(); $this->_content .= $this->getColorTable(); $this->_content .= $part . '}'; }
/** * prepares rtf contents */ protected function render() { $this->_writer->open(); $this->_writer->write('{\\rtf\\ansi\\deff0' . "\r\n"); $this->_writer->write($this->getFontTable()->getContent()); $this->_writer->write($this->getColorTable()->getContent()); $this->_writer->write($this->getInfoPart()); $paperWidth = $this->_paperWidth; $paperHeight = $this->_paperHeight; // page properties if ($this->_isLandscape) { $this->_writer->write('\\landscape '); if ($paperWidth < $paperHeight) { $tmp = $paperHeight; $paperHeight = $paperWidth; $paperWidth = $tmp; } } $this->_writer->write('\\paperw' . PHPRtfLite_Unit::getUnitInTwips($paperWidth) . ' '); $this->_writer->write('\\paperh' . PHPRtfLite_Unit::getUnitInTwips($paperHeight) . ' '); // hyphenation if ($this->_isHyphenation) { $this->_writer->write('\\hyphauto1'); } $this->_writer->write('\\deftab' . PHPRtfLite_Unit::getUnitInTwips($this->_defaultTabWidth) . ' '); $this->_writer->write('\\margl' . PHPRtfLite_Unit::getUnitInTwips($this->_marginLeft) . ' '); $this->_writer->write('\\margr' . PHPRtfLite_Unit::getUnitInTwips($this->_marginRight) . ' '); $this->_writer->write('\\margt' . PHPRtfLite_Unit::getUnitInTwips($this->_marginTop) . ' '); $this->_writer->write('\\margb' . PHPRtfLite_Unit::getUnitInTwips($this->_marginBottom) . ' '); if (null !== $this->_gutter) { $this->_writer->write('\\gutter' . PHPRtfLite_Unit::getUnitInTwips($this->_gutter) . ' '); } if (true == $this->_useMirrorMargins) { $this->_writer->write('\\margmirror '); } if (null !== $this->_viewMode) { $this->_writer->write('\\viewkind' . $this->_viewMode . ' '); } if (null !== $this->_zoomMode) { $this->_writer->write('\\viewzk' . $this->_zoomMode . ' '); } if (null !== $this->_zoomLevel) { $this->_writer->write('\\viewscale' . $this->_zoomLevel . ' '); } if (isset($this->_sections[0]) && $this->_sections[0]->getBorder()) { $this->_writer->write($this->_sections[0]->getBorder()->getContent('\\pg')); } elseif ($this->_border) { $this->_writer->write($this->_border->getContent('\\pg')); } // page numbering start $this->_writer->write('\\pgnstart' . $this->_pageNumberStart); //headers and footers properties if ($this->_useOddEvenDifferent) { $this->_writer->write('\\facingp '); } if ($this->_titlepg) { $this->_writer->write('\\titlepg '); } // document header definition for footnotes and endnotes $this->_writer->write($this->getNoteDocHead()->getContent()); //headers and footers if there are no sections if (count($this->_sections) == 0) { foreach ($this->_headers as $header) { $header->render(); } foreach ($this->_footers as $footer) { $footer->render(); } } //sections foreach ($this->_sections as $key => $section) { if ($key != 0) { $this->_writer->write('\\sect\\sectd '); } $section->render(); } $this->_writer->write('}'); $this->_writer->close(); }
/** * Gets rtf code of paragraph * * @param PHPRtfLite $rtf * * @return string rtf code */ public function getContent(PHPRtfLite $rtf) { $content = ''; switch ($this->_alignment) { case self::TEXT_ALIGN_RIGHT: $content .= '\\qr '; break; case self::TEXT_ALIGN_CENTER: $content .= '\\qc '; break; case self::TEXT_ALIGN_JUSTIFY: $content .= '\\qj '; break; default: $content .= '\\ql '; break; } if ($this->_indentFirstLine > 0) { $content .= '\\fi' . $this->_indentFirstLine . ' '; } if ($this->_indentLeft > 0) { $content .= '\\li' . $this->_indentLeft . ' '; } if ($this->_indentRight > 0) { $content .= '\\ri' . $this->_indentRight . ' '; } if ($this->_spaceBefore > 0) { $content .= '\\sb' . $this->_spaceBefore . ' '; } if ($this->_spaceAfter > 0) { $content .= '\\sa' . $this->_spaceAfter . ' '; } if ($this->_spaceBetweenLines > 0) { $content .= '\\sl' . $this->_spaceBetweenLines . ' '; } if ($this->_border) { $content .= $this->_border->getContent($rtf, '\\'); } if ($this->_shading > 0) { $content .= '\\shading' . $this->_shading . ' '; } if ($this->_backgroundColor) { $rtf->addColor($this->_backgroundColor); $content .= '\\cbpat' . $rtf->getColor($this->_backgroundColor) . ' '; } return $content; }
/** * renders rtf code of section */ public function render() { $writer = $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 if ($this->_border) { if ($this->_borderSurroundsHeader) { $writer->write('\\pgbrdrhead'); } if ($this->_borderSurroundsFooter) { $writer->write('\\pgbrdrfoot'); } $writer->write($this->_border->getContent('\\pg')); } else { if ($border = $this->_rtf->getBorder()) { if ($this->_rtf->borderSurroundsHeader()) { $writer->write('\\pgbrdrhead'); } if ($this->_rtf->borderSurroundsFooter()) { $writer->write('\\pgbrdrfoot'); } $writer->write($border->getContent('\\pg')); } } //do not break within the section if ($this->_doNotBreak) { $writer->write('\\sbknone '); } //set column index, when using more than one column for this section if ($this->_numberOfColumns > 1) { $writer->write('\\cols' . $this->_numberOfColumns . ' '); } if (empty($this->_columnWidths)) { if ($this->_spaceBetweenColumns) { $writer->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) { $writer->write('\\colno' . $i . '\\colw' . PHPRtfLite_Unit::getUnitInTwips($value)); if (!empty($this->_columnWidths[$key])) { $writer->write('\\colsr' . $space); } $i++; } $writer->write(' '); } if ($this->_lineBetweenColumns) { $writer->write('\\linebetcol '); } /*---Page part---*/ if ($this->_isLandscape) { $writer->write('\\lndscpsxn '); } if ($this->_paperWidth) { $writer->write('\\pgwsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_paperWidth) . ' '); } if ($this->_paperHeight) { $writer->write('\\pghsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_paperHeight) . ' '); } if ($this->_marginLeft) { $writer->write('\\marglsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginLeft) . ' '); } if ($this->_marginRight) { $writer->write('\\margrsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginRight) . ' '); } if ($this->_marginTop) { $writer->write('\\margtsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginTop) . ' '); } if ($this->_marginBottom) { $writer->write('\\margbsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginBottom) . ' '); } if ($this->_gutter) { $writer->write('\\guttersxn' . PHPRtfLite_Unit::getUnitInTwips($this->_gutter) . ' '); } if ($this->_useMirrorMargins) { $writer->write('\\margmirsxn '); } if ($this->_font) { $writer->write($this->_font->getContent()); } $writer->write("\r\n"); parent::render(); $writer->write("\r\n"); }
/** * gets rtf code of paragraph * * @return string rtf code */ public function getContent() { $content = ''; switch ($this->_alignment) { case self::TEXT_ALIGN_RIGHT: $content .= '\\qr '; break; case self::TEXT_ALIGN_CENTER: $content .= '\\qc '; break; case self::TEXT_ALIGN_JUSTIFY: $content .= '\\qj '; break; default: $content .= '\\ql '; break; } if ($this->_indentFirstLine != 0) { $content .= '\\fi' . PHPRtfLite_Unit::getUnitInTwips($this->_indentFirstLine) . ' '; } if ($this->_indentLeft > 0) { $content .= '\\li' . PHPRtfLite_Unit::getUnitInTwips($this->_indentLeft) . ' '; } if ($this->_indentRight > 0) { $content .= '\\ri' . PHPRtfLite_Unit::getUnitInTwips($this->_indentRight) . ' '; } if ($this->_spaceBefore > 0) { $content .= '\\sb' . $this->_spaceBefore . ' '; } if ($this->_spaceAfter > 0) { $content .= '\\sa' . $this->_spaceAfter . ' '; } if ($this->_spaceBetweenLines > 0) { $content .= '\\sl' . $this->_spaceBetweenLines . ' '; } if ($this->_border) { $content .= $this->_border->getContent('\\'); } if ($this->_shading > 0) { $content .= '\\shading' . $this->_shading . ' '; } if ($this->_backgroundColor && $this->_colorTable) { $colorIndex = $this->_colorTable->getColorIndex($this->_backgroundColor); if ($colorIndex !== false) { $content .= '\\cbpat' . $colorIndex . ' '; } } return $content; }