コード例 #1
0
ファイル: SectionLexerTest.php プロジェクト: alipek/rtf
    function testShouldLexColorTable()
    {
        $lexer = new JoshRibakoff_Note_SectionLexer();
        $lexer->setInput(array('\\rtf\\ansi\\deff0', array('\\fonttbl{\\f0\\froman Tms Rmn;}{\\f1\\fdecor 
Symbol;}{\\f2\\fswiss Helv;}'), array('\\colortbl;\\red0\\green0\\blue0;
\\red0\\green0\\blue255;\\red0\\green255\\blue255;\\red0\\green255\\
blue0;\\red255\\green0\\blue255;\\red255\\green0\\blue0;\\red255\\
green255\\blue0;\\red255\\green255\\blue255;'), array('\\stylesheet{\\fs20 \\snext0Normal;}'), array('\\info{\\author John Doe}
{\\creatim\\yr1990\\mo7\\dy30\\hr10\\min48}{\\version1}{\\edmins0}
{\\nofpages1}{\\nofwords0}{\\nofchars0}{\\vern8351}'), '\\widoctrl\\ftnbj \\sectd\\linex0\\endnhere \\pard\\plain \\fs20 This is plain text.\\par'));
        $expected = array('000000', '000000', '0000FF', '00FFFF', '00FF00', 'FF00FF', 'FF0000', 'FFFF00', 'FFFFFF');
        $this->assertEquals($expected, $lexer->colorTable(), 'should lex out color table');
    }
コード例 #2
0
ファイル: Note.php プロジェクト: alipek/rtf
 /** Set the RTF text this Note object should represent. Overwrites any previously set RTF data. */
 function setRTF($rtf)
 {
     $this->raw_rtf = $rtf;
     $rtf = $this->stripOuterBraces($rtf);
     $tree = $this->convertBracesToArray($rtf);
     // find 'text' section (last element of tree array) and escape RTF tokens (brace lexer un-escapes them)
     $textSection = $tree[count($tree) - 1];
     $textSection = str_replace('{', '\\{', $textSection);
     $textSection = str_replace('}', '\\}', $textSection);
     $tree[count($tree) - 1] = $textSection;
     $sectionLexer = new JoshRibakoff_Note_SectionLexer();
     $sectionLexer->setInput($tree);
     $this->rtf_fonttable = $sectionLexer->fontTable();
     $this->rtf_colortable = $sectionLexer->colorTable();
     $this->rtf_text_pieces = $sectionLexer->textPieces();
     $this->rtf_text = $sectionLexer->text();
 }