/** * constructor * * @param integer $size size of border * @param string $color color of border (example '#ff0000' or '#f00') * @param string $type represented by class constants PHPRtfLite_Border_Format::TYPE_*<br> * Possible values:<br> * TYPE_SINGLE: single (default)<br> * TYPE_DOT: dot<br> * TYPE_DASH: dash<br> * TYPE_DOTDASH: dotdash<br> * @param float $space space between borders and the paragraph */ public function __construct($size = 0, $color = null, $type = null, $space = 0) { $this->_size = $size * PHPRtfLite::SPACE_IN_POINTS; $this->_type = $type; $this->_color = $color; $this->_space = PHPRtfLite_Unit::getUnitInTwips($space); }
/** * constructor * * @param float $size size of border * @param string $color color of border (example '#ff0000' or '#f00') * @param string $type represented by class constants PHPRtfLite_Border_Format::TYPE_*<br> * Possible values:<br> * TYPE_SINGLE: single (default)<br> * TYPE_DOT: dot<br> * TYPE_DASH: dash<br> * TYPE_DOTDASH: dotdash<br> * @param float $space space between borders and the paragraph */ public function __construct($size = 0.0, $color = null, $type = null, $space = 0.0) { $this->_size = round($size * PHPRtfLite::SPACE_IN_POINTS); // convert points to twips $this->_type = $type; $this->_color = $color; $this->_space = PHPRtfLite_Unit::getUnitInTwips($space); }
/** * sets text indent * * @param float $indent */ public function setTextIndent($indent) { $this->_textIndent = PHPRtfLite_Unit::getUnitInTwips($indent); }
/** * streams rtf code for header/footer * @return string rtf code */ public function render() { $stream = $this->_rtf->getWriter(); if (isset($this->_offsetHeight)) { $stream->write('\\' . $this->getRtfType() . 'y' . PHPRtfLite_Unit::getUnitInTwips($this->_offsetHeight)); } $stream->write('{\\' . $this->getTypeAsRtfCode() . ' '); parent::render(); $containerElements = $this->getElements(); if ($containerElements && $containerElements[count($containerElements) - 1] instanceof PHPRtfLite_Element) { $stream->write('\\par'); } $stream->write('}' . "\r\n"); }
/** * 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(); }
/** * renders row definition * * @param PHPRtfLite_Table_Row $row */ public function renderRowDefinition(PHPRtfLite_Table_Row $row) { $rowIndex = $row->getRowIndex(); $stream = $this->getRtf()->getWriter(); $stream->write('\\trowd'); if ($this->_alignment) { switch ($this->_alignment) { case self::ALIGN_CENTER: $stream->write('\\trqc'); break; case self::ALIGN_RIGHT: $stream->write('\\trqr'); break; default: $stream->write('\\trql'); break; } } $rowHeight = $row->getHeight(); if ($rowHeight) { $stream->write('\\trrh' . PHPRtfLite_Unit::getUnitInTwips($rowHeight)); } if ($this->isPreventPageBreak()) { $stream->write('\\trkeep '); } if ($this->isFirstRowHeader() && $rowIndex == 1) { $stream->write('\\trhdr '); } if ($this->getLeftPosition() != '') { $stream->write('\\trleft' . PHPRtfLite_Unit::getUnitInTwips($this->getLeftPosition()) . ' '); } $width = 0; foreach ($this->getColumns() as $columnIndex => $column) { $cell = $this->getCell($rowIndex, $columnIndex + 1); // render cell definition if (!$cell->isHorizontalMerged()) { $cell->renderDefinition(); // cell width $width += PHPRtfLite_Unit::getUnitInTwips($cell->getWidth()); $stream->write('\\cellx' . $width); } } }
/** * 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"); }
/** * gets rtf image height * * @return integer */ private function getImageRtfHeight() { if ($this->_height > 0) { return PHPRtfLite_Unit::getUnitInTwips($this->_height); } $imageHeight = $this->_imageHeight ? $this->_imageHeight : 100; if ($this->_width > 0) { $imageWidth = $this->_imageWidth ? $this->_imageWidth : 100; $height = $imageHeight / $imageWidth * $this->_width; return PHPRtfLite_Unit::getUnitInTwips($height); } return PHPRtfLite_Unit::getPointsInTwips($imageHeight); }
/** * renders cell definition */ public function renderDefinition() { $stream = $this->_rtf->getWriter(); if ($this->isVerticalMerged()) { if ($this->isVerticalMergedFirstInRange()) { $stream->write('\\clvmgf'); } else { $stream->write('\\clvmrg'); } } $backgroundColor = $this->getBackgroundColor(); if ($backgroundColor) { $colorTable = $this->_rtf->getColorTable(); $stream->write('\\clcbpat' . $colorTable->getColorIndex($backgroundColor) . ' '); } switch ($this->getVerticalAlignment()) { case self::VERTICAL_ALIGN_TOP: $stream->write('\\clvertalt'); break; case self::VERTICAL_ALIGN_CENTER: $stream->write('\\clvertalc'); break; case self::VERTICAL_ALIGN_BOTTOM: $stream->write('\\clvertalb'); break; } switch ($this->getRotateTo()) { case self::ROTATE_RIGHT: $stream->write('\\cltxtbrl'); break; case self::ROTATE_LEFT: $stream->write('\\cltxbtlr'); break; } // NOTE: microsoft and all other rtf readers I know confound left with top cell padding if ($this->_paddingLeft) { $stream->write('\\clpadft3\\clpadt' . PHPRtfLite_Unit::getUnitInTwips($this->_paddingLeft) . ' '); } if ($this->_paddingTop) { $stream->write('\\clpadfl3\\clpadl' . PHPRtfLite_Unit::getUnitInTwips($this->_paddingTop) . ' '); } if ($this->_paddingBottom) { $stream->write('\\clpadfb3\\clpadb' . PHPRtfLite_Unit::getUnitInTwips($this->_paddingBottom) . ' '); } if ($this->_paddingRight) { $stream->write('\\clpadfr3\\clpadr' . PHPRtfLite_Unit::getUnitInTwips($this->_paddingRight) . ' '); } $border = $this->getBorder(); if ($border) { $stream->write($border->getContent('\\cl')); } }
/** * 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; }