Horde_Pdf_Writer::setDrawColor PHP Method

setDrawColor() public method

Depending on the colorspace called, the number of color component parameters required can be either 1, 3 or 4. The method can be called before the first page is created and the color is retained from page to page.
See also: setFillColor()
See also: line()
See also: rect()
See also: cell()
See also: multiCell()
public setDrawColor ( string $cs = 'rgb', float $c1, float $c2, float $c3, float $c4 )
$cs string Indicates the colorspace which can be either 'rgb', 'hex', 'cmyk' or 'gray'. Defaults to 'rgb'.
$c1 float First color component, floating point value between 0 and 1. Required for gray, rgb and cmyk.
$c2 float Second color component, floating point value between 0 and 1. Required for rgb and cmyk.
$c3 float Third color component, floating point value between 0 and 1. Required for rgb and cmyk.
$c4 float Fourth color component, floating point value between 0 and 1. Required for cmyk.
    public function setDrawColor($cs = 'rgb', $c1 = 0, $c2 = 0, $c3 = 0, $c4 = 0)
    {
        $cs = Horde_String::lower($cs);
        // convert hex to rgb
        if ($cs == 'hex') {
            $cs = 'rgb';
            list($c1, $c2, $c3) = $this->_hexToRgb($c1);
        }
        if ($cs == 'rgb') {
            $this->_draw_color = sprintf('%.3F %.3F %.3F RG', $c1, $c2, $c3);
        } elseif ($cs == 'cmyk') {
            $this->_draw_color = sprintf('%.3F %.3F %.3F %.3F K', $c1, $c2, $c3, $c4);
        } else {
            $this->_draw_color = sprintf('%.3F G', $c1);
        }
        if ($this->_page > 0) {
            $this->_out($this->_draw_color);
        }
    }

Usage Example

コード例 #1
0
ファイル: WriterTest.php プロジェクト: jubinpatel/horde
 public function testTextColorUsingHex()
 {
     $pdf = new Horde_Pdf_Writer();
     $pdf->setInfo('timestamp', $this->fixtureCreationDate());
     $pdf->setCompression(false);
     $pdf->open();
     $pdf->addPage();
     $pdf->setFont('Helvetica', 'B', 48);
     $pdf->setDrawColor('hex', '#F00');
     $pdf->setTextColor('hex', '#0F0');
     $pdf->setFillColor('hex', '#00F');
     $this->assertEquals('1.000 0.000 0.000 RG', $pdf->getDrawColor());
     $this->assertEquals('0.000 1.000 0.000 rg', $pdf->getTextColor());
     $this->assertEquals('0.000 0.000 1.000 rg', $pdf->getFillColor());
 }