/** * gets rtf code for dropdown form field * * @return string */ public function getRtfCode() { $content = '{\\fftype2\\ffres25\\fftypetxt0\\ffhaslistbox\\ffdefres0'; foreach ($this->_items as $text) { $text = PHPRtfLite_Utf8::getUnicodeEntities($text, $this->_rtf->getCharset()); $content .= '{\\*\\ffl ' . $text . '}'; } $content .= '}'; return $content; }
/** * 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(' '); }
/** * gets rtf info part * * @return string */ protected function getInfoPart() { $part = '{\\info' . "\r\n"; foreach ($this->_properties as $key => $value) { $value = PHPRtfLite_Utf8::getUnicodeEntities($value, $this->_charset); $part .= '{\\' . $key . ' ' . $value . '}' . "\r\n"; } $part .= '}' . "\r\n"; return $part; }
/** * renders the element */ public function render() { $stream = $this->_rtf->getWriter(); $text = $this->_text; if (!$this->_isRtfCode) { $charset = $this->_rtf->getCharset(); $text = PHPRtfLite::quoteRtfCode($text); if ($this->_convertTagsToRtf) { $text = self::convertTagsToRtf($text, $charset); } $text = PHPRtfLite_Utf8::getUnicodeEntities($text, $charset); } $stream->write($this->getOpeningToken()); if ($this->_font) { $stream->write($this->_font->getContent()); } if ($this->isEmptyParagraph() && !$this->_isRtfCode) { $stream->write('\\par'); } else { $stream->write($text); } $stream->write($this->getClosingToken() . "\r\n"); }
/** * 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()); } $charset = $this->_rtf->getCharset(); $textEncoded = PHPRtfLite::quoteRtfCode($this->_text); $stream->write('{\\up6\\chftn}' . "\r\n" . PHPRtfLite_Utf8::getUnicodeEntities($textEncoded, $charset) . '} '); }
/** * Writes text to container. * * @param string $text Text. Also you can use html style tags. Possible tags:<br> * strong, b- bold; <br> * em - ; <br> * i - italic; <br> * u - underline; <br> * br - line break; <br> * chdate - current date; <br> * chdpl - current date in long format; <br> * chdpa - current date in abbreviated format; <br> * chtime - current time; <br> * chpgn, pagenum - page number ; <br> * tab - tab * sectnum - section number; <br> * line - line break; <br> * page - page break; <br> * sect - section break; <br> * @param PHPRtfLite_Font $font font of text * @param PHPRtfLite_ParFormat $parFormat paragraph format, if null, text is written in the same paragraph. * @param boolean $replaceTags if false, then html style tags are not replaced with rtf code * @todo Documentation */ public function writeText($text, PHPRtfLite_Font $font = null, PHPRtfLite_ParFormat $parFormat = null, $replaceTags = true) { $text = PHPRtfLite::quoteRtfCode($text); if ($replaceTags) { //bold $text = preg_replace('/<STRONG[ ]*>(.*?)<\\/STRONG[ ]*>/smi', '\\b \\1\\b0 ', $text); $text = preg_replace('/<B[ ]*>(.*?)<\\/B[ ]*>/smi', '\\b \\1\\b0 ', $text); //italic $text = preg_replace('/<EM[ ]*>(.*?)<\\/EM[ ]*>/smi', '\\i \\1\\i0 ', $text); $text = preg_replace('/<I[ ]*>(.*?)<\\/I[ ]*>/smi', '\\i \\1\\i0 ', $text); //underline $text = preg_replace('/<U[ ]*>(.*?)<\\/U[ ]*>/smi', '\\ul \\1\\ul0 ', $text); //break $text = preg_replace('/<BR[ ]*(\\/)?[ ]*>/smi', '\\line ', $text); //horizontal rule $text = preg_replace('/<HR[ ]*(\\/)?[ ]*>/smi', '{\\pard \\brdrb \\brdrs \\brdrw10 \\brsp20 \\par}', $text); $text = preg_replace('/<CHDATE[ ]*(\\/)?[ ]*>/smi', '\\chdate ', $text); $text = preg_replace('/<CHDPL[ ]*(\\/)?[ ]*>/smi', '\\\\chdpl ', $text); $text = preg_replace('/<CHDPA[ ]*(\\/)?[ ]*>/smi', '\\chdpa ', $text); $text = preg_replace('/<CHTIME[ ]*(\\/)?[ ]*>/smi', '\\chtime ', $text); $text = preg_replace('/<CHPGN[ ]*(\\/)?[ ]*>/smi', '\\chpgn ', $text); $text = preg_replace('/<TAB[ ]*(\\/)?[ ]*>/smi', '\\tab ', $text); $text = preg_replace('/<BULLET[ ]*(\\/)?[ ]*>/smi', '\\bullet ', $text); $text = preg_replace('/<PAGENUM[ ]*(\\/)?[ ]*>/smi', '\\chpgn ', $text); $text = preg_replace('/<SECTNUM[ ]*(\\/)?[ ]*>/smi', '\\sectnum ', $text); $text = preg_replace('/<LINE[ ]*(\\/)?[ ]*>/smi', '\\line ', $text); //$text = preg_replace('/<PAGE[ ]*(\/)?[ ]*>/smi', '\\page ', $text); //$text = preg_replace('/<SECT[ ]*(\/)?[ ]*>/smi', '\\sect', $text); } $text = PHPRtfLite_Utf8::getUnicodeEntities($text); //content formating $content = $parFormat && count($this->_elements) != 0 && !$this->_emptyPar ? '\\par ' : ''; $this->_emptyPar = false; $content .= $parFormat ? $this->_pard . $parFormat->getContent($this->_rtf) : ''; $content .= '{'; if ($font) { $content .= $font->getContent($this->_rtf); } $content .= $text . '}' . "\r\n"; $this->_elements[] = $content; }