/** * Test htmlToRGB() */ public function testHtmlToRGB() { // Prepare test values [ original, expected ] $values[] = array('#FF99DD', array(255, 153, 221)); // With # $values[] = array('FF99DD', array(255, 153, 221)); // 6 characters $values[] = array('F9D', array(255, 153, 221)); // 3 characters $values[] = array('0F9D', false); // 4 characters // Conduct test foreach ($values as $value) { $result = Drawing::htmlToRGB($value[0]); $this->assertEquals($value[1], $result); } }
/** * Get all data * * @return string */ private function writeDocument() { $this->fontTable = $this->populateFontTable(); $this->colorTable = $this->populateColorTable(); // Set the default character set $sRTFContent = '{\\rtf1'; $sRTFContent .= '\\ansi\\ansicpg1252'; // Set the default font (the first one) $sRTFContent .= '\\deff0'; // Set the default tab size (720 twips) $sRTFContent .= '\\deftab720'; $sRTFContent .= PHP_EOL; // Set the font tbl group $sRTFContent .= '{\\fonttbl'; foreach ($this->fontTable as $idx => $font) { $sRTFContent .= '{\\f' . $idx . '\\fnil\\fcharset0 ' . $font . ';}'; } $sRTFContent .= '}' . PHP_EOL; // Set the color tbl group $sRTFContent .= '{\\colortbl '; foreach ($this->colorTable as $idx => $color) { $arrColor = Drawing::htmlToRGB($color); $sRTFContent .= ';\\red' . $arrColor[0] . '\\green' . $arrColor[1] . '\\blue' . $arrColor[2] . ''; } $sRTFContent .= ';}' . PHP_EOL; $sRTFContent .= '{\\*\\generator PhpWord;}' . PHP_EOL; // Set the generator $sRTFContent .= '\\viewkind4'; // Set the view mode of the document $sRTFContent .= '\\uc1'; // Set the numberof bytes that follows a unicode character $sRTFContent .= '\\pard'; // Resets to default paragraph properties. $sRTFContent .= '\\nowidctlpar'; // No widow/orphan control $sRTFContent .= '\\lang1036'; // Applies a language to a text run (1036 : French (France)) $sRTFContent .= '\\kerning1'; // Point size (in half-points) above which to kern character pairs $sRTFContent .= '\\fs' . PhpWord::DEFAULT_FONT_SIZE * 2; // Set the font size in half-points $sRTFContent .= PHP_EOL; // Body $sRTFContent .= $this->writeContent(); $sRTFContent .= '}'; return $sRTFContent; }
/** * Write color table * * @return string */ private function writeColorTable() { $content = ''; $content .= '{'; $content .= '\\colortbl'; foreach ($this->colorTable as $color) { list($red, $green, $blue) = Drawing::htmlToRGB($color); $content .= ";\\red{$red}\\green{$green}\\blue{$blue}"; } $content .= '}'; $content .= PHP_EOL; return $content; }