Esempio n. 1
0
 /**
  * Add a new style
  * @param @stylename style name
  * @param @fontface  font face
  * @param @fontsize  font size
  * @param @fontstyle font style (B=bold, I=italic)
  * @param @fontcolor font color
  * @param @fillcolor fill color
  */
 public function addStyle($stylename, $fontface, $fontsize, $fontstyle, $fontcolor, $fillcolor)
 {
     // instancia um objeto para estilo de fonte (PHPRtfLite_Font)
     $font = new PHPRtfLite_Font($fontsize, $fontface, $fontcolor);
     $font->setBold(strstr($fontstyle, 'B'));
     $font->setItalic(strstr($fontstyle, 'I'));
     $font->setUnderline(strstr($fontstyle, 'U'));
     //  armazena o objeto fonte e a cor de preenchimento
     $this->styles[$stylename]['font'] = $font;
     $this->styles[$stylename]['bgcolor'] = $fillcolor;
 }
Esempio n. 2
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");
         }
     }
 }
Esempio n. 3
0
 /**
  * renders footnote/endnote
  *
  * @return string
  */
 public function getContent()
 {
     $content = '\\chftn ' . '{\\footnote' . ($this->isFootnote() ? '' : '\\ftnalt') . '\\pard\\plain \\lin283\\fi-283 ';
     if ($this->_parFormat) {
         $content .= $this->_parFormat->getContent($this->_rtf);
     }
     $content .= $this->_font->getContent($this->_rtf);
     $content .= '{\\up6\\chftn}' . "\r\n" . PHPRtfLite::quoteRtfCode($this->_text) . '} ';
     return $content;
 }
Esempio n. 4
0
 /**
  * tests getContent().
  */
 public function testGetContent()
 {
     $this->_font->setBold();
     $this->_font->setItalic();
     $this->_font->setUnderline();
     $this->_font->setAnimation(PHPRtfLite_Font::ANIMATE_LAS_VEGAS_LIGHTS);
     $this->_font->setDoubleStriked();
     $this->assertEquals('\\fs20 \\b \\i \\ul \\animtext1\\striked1 1', trim($this->_font->getContent()));
 }
Esempio n. 5
0
 /**
  * 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(' ');
 }
Esempio n. 6
0
 function Generate_Content()
 {
     PHPRtfLite::registerAutoloader();
     $largerFont = new PHPRtfLite_Font(16, 'Courier New');
     $largerFont->setBold();
     $smallerFont = new PHPRtfLite_Font(12, 'Times New Roman');
     $tableFont = new PHPRtfLite_Font(10, 'Courier New');
     //Izveido pašu dokumentu
     $rtf = new PHPRtfLite();
     $parHead = new PHPRtfLite_ParFormat();
     $parHead->setSpaceBefore(3);
     $parHead->setSpaceAfter(8);
     $parBody = new PHPRtfLite_ParFormat();
     $parBody->setSpaceBefore(1);
     //Izveido pirmo sekciju
     $sect =& $rtf->addSection();
     $sect->writeText("Atzīmju izraksts", $largerFont, $parHead);
     $sect->writeText("Skolnieks: " . $this->studentName, $smallerFont, $parHead);
     for ($i = 0; $i < count($this->grades); $i++) {
         $grade = $this->grades[$i];
         $sect->writeText(sprintf("%s  %s  %s", $grade["date"], $grade["lesson"], $grade["grade"]), $tableFont, $parBody);
     }
     $this->fileContents = $rtf;
 }
Esempio n. 7
0
 /**
  * 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($text);
     }
     $stream->write($this->getClosingToken() . "\r\n");
 }
Esempio n. 8
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;
 }
Esempio n. 9
0
 /**
  * gets font index for list character
  *
  * @return string
  */
 protected function getListCharFontIndex()
 {
     $fontFamily = $this->_listCharFont->getFontFamily();
     return $this->_rtf->getFontTable()->getFontIndex($fontFamily);
 }
Esempio n. 10
0
//tournament result
/*$i = 1;
foreach ($chessResults as $playerResult) {
    $j = 1;
    $sum = 0;
    foreach ($playerResult as $result)  {
        if ($i != $j) {
            $table->writeToCell($i + 1, $j + 1, $result, new PHPRtfLite_Font(11, 'Times new Roman', '#7A2900'), new PHPRtfLite_ParFormat('center'));
            $sum += $result;
        }
        $j++;
    }
    $table->writeToCell($i + 1, $j + 1, '<b>'.$sum.'</b>', new PHPRtfLite_Font(11, 'Times new Roman', '#7A2900'), new PHPRtfLite_ParFormat('center'));
    $i++;
}*/
$fontBold = new PHPRtfLite_Font(11, 'Times new Roman', '#7A2900');
$fontBold->setBold();
$table->setTextAlignmentForCellRange('center', 2, 2, $countRows, $countCols);
$table->setFontForCellRange(new PHPRtfLite_Font(11, 'Times new Roman', '#7A2900'), 2, 2, $countRows, $countCols - 1);
$table->setFontForCellRange($fontBold, 2, $countCols, $countRows);
$table->writeToCell(1, $countCols, 'TOTAL', $font1, new PHPRtfLite_ParFormat('center'));
$border = PHPRtfLite_Border::create($rtf, 1.5, '#000000');
$table->setBorderForCellRange($border, 1, $countCols, $countRows, $countCols);
$borderFormat = new PHPRtfLite_Border_Format(1, '#0000ff', 'dash');
$border = new PHPRtfLite_Border($rtf, null, null, null, $borderFormat);
//Registry::$debug = true;
$table->setBorderForCellRange($border, 2, $countCols, $countRows - 1, $countCols);
$sect->writeText('Chess tournamet play-offs (write your data)' . "\n", new PHPRtfLite_Font(14, 'Arial'), new PHPRtfLite_ParFormat());
$countSmall = 5;
$countLarge = 6;
$smallWidth = '0.75';
Esempio n. 11
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) . '} ');
 }
Esempio n. 12
0
 /**
  * registers the font in color table and font table
  *
  * @param PHPRtfLite_Font $font
  */
 public function registerFont(PHPRtfLite_Font $font)
 {
     $font->setColorTable($this->getColorTable());
     $font->setFontTable($this->getFontTable());
 }
Esempio n. 13
0
 /**
  * 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;
 }
Esempio n. 14
0
 /**
  * prepares rtf contents
  */
 protected function render()
 {
     $this->_writer->open();
     $defaultFontSize = 20;
     $defaultFontIndex = 0;
     if ($this->_defaultFont) {
         $defaultFontIndex = $this->getFontTable()->getFontIndex($this->_defaultFont->getFontFamily());
         $defaultFontSize = $this->_defaultFont->getSize() * 2;
     }
     $this->_writer->write('{\\rtf\\ansi\\deff' . $defaultFontIndex . '\\fs' . $defaultFontSize . "\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 . ' ');
     }
     // 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());
     // default font
     if ($this->_defaultFont) {
         $this->_writer->write($this->_defaultFont->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();
 }
Esempio n. 15
0
 /**
  * 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");
 }