Pop\Pdf\Pdf::drawEllipse PHP Method

drawEllipse() public method

Method to add an ellipse to the PDF.
public drawEllipse ( integer $x, integer $y, integer $w, integer $h = null, boolean $fill = true ) : Pdf
$x integer
$y integer
$w integer
$h integer
$fill boolean
return Pdf
    public function drawEllipse($x, $y, $w, $h = null, $fill = true)
    {
        if (null === $h) {
            $h = $w;
        }
        $x1 = $x + $w;
        $y1 = $y;
        $x2 = $x;
        $y2 = $y - $h;
        $x3 = $x - $w;
        $y3 = $y;
        $x4 = $x;
        $y4 = $y + $h;
        // Calculate coordinate number one's 2 bezier points.
        $coor1_bez1_x = $x1;
        $coor1_bez1_y = round(0.55 * ($y2 - $y1)) + $y1;
        $coor1_bez2_x = $x1;
        $coor1_bez2_y = round(0.45 * ($y1 - $y4)) + $y4;
        // Calculate coordinate number two's 2 bezier points.
        $coor2_bez1_x = round(0.45 * ($x2 - $x1)) + $x1;
        $coor2_bez1_y = $y2;
        $coor2_bez2_x = round(0.55 * ($x3 - $x2)) + $x2;
        $coor2_bez2_y = $y2;
        // Calculate coordinate number three's 2 bezier points.
        $coor3_bez1_x = $x3;
        $coor3_bez1_y = round(0.55 * ($y2 - $y3)) + $y3;
        $coor3_bez2_x = $x3;
        $coor3_bez2_y = round(0.45 * ($y3 - $y4)) + $y4;
        // Calculate coordinate number four's 2 bezier points.
        $coor4_bez1_x = round(0.55 * ($x3 - $x4)) + $x4;
        $coor4_bez1_y = $y4;
        $coor4_bez2_x = round(0.45 * ($x4 - $x1)) + $x1;
        $coor4_bez2_y = $y4;
        $co_index = $this->getContentObject();
        $this->objects[$co_index]->setStream("\n{$x1} {$y1} m\n{$coor1_bez1_x} {$coor1_bez1_y} {$coor2_bez1_x} {$coor2_bez1_y} {$x2} {$y2} c\n{$coor2_bez2_x} {$coor2_bez2_y} {$coor3_bez1_x} {$coor3_bez1_y} {$x3} {$y3} c\n{$coor3_bez2_x} {$coor3_bez2_y} {$coor4_bez1_x} {$coor4_bez1_y} {$x4} {$y4} c\n{$coor4_bez2_x} {$coor4_bez2_y} {$coor1_bez2_x} {$coor1_bez2_y} {$x1} {$y1} c\n" . $this->setStyle($fill) . "\n");
        return $this;
    }

Usage Example

Exemplo n.º 1
0
    $pdf->addPage('Letter');
    $pdf->setVersion('1.4')->setTitle('Test Title')->setAuthor('Test Author')->setSubject('Test Subject')->setCreateDate(date('D, M j, Y h:i A'));
    $pdf->setCompression(true);
    $pdf->setTextParams(6, 6, 100, 100, 30, 0)->setFillColor(new Rgb(12, 101, 215))->setStrokeColor(new Rgb(215, 101, 12));
    $pdf->addFont('Arial');
    $pdf->addText(50, 620, 18, 'Hello World! & You!', 'Arial');
    $pdf->setTextParams();
    $pdf->addFont('Courier-Bold');
    $pdf->addText(150, 350, 48, 'Hello World!', 'Courier-Bold');
    $sz = $pdf->getStringSize('Hello World!', 'Courier-Bold', 48);
    $pdf->addUrl(150, 350 - $sz['baseline'], $sz['width'], $sz['height'], 'http://www.google.com/');
    $pdf->addPage('Letter');
    $pdf->setFillColor(new Rgb(12, 101, 215))->setStrokeColor(new Rgb(215, 101, 12))->setStrokeWidth(4, 10, 5);
    $pdf->drawCircle(150, 700, 60, false);
    $pdf->setPage(1)->setFillColor(new Rgb(0, 0, 255));
    $pdf->drawRectangle(100, 550, 175, 50);
    $pdf->addLink(100, 550, 175, 50, 150, 550, 1, 2);
    $pdf->setPage(2)->setFillColor(new Rgb(12, 101, 215))->setStrokeColor(new Rgb(215, 101, 12))->setStrokeWidth(4, 10, 5);
    $pdf->drawCircle(250, 650, 25);
    $pdf->addImage('../assets/images/logo-rgb.jpg', 150, 400);
    $pdf->setPage(1)->setFillColor(new Rgb(255, 10, 25))->setStrokeColor(new Rgb(12, 101, 215))->setStrokeWidth(2);
    $pdf->drawEllipse(300, 150, 200, 100, false);
    $pdf->addPage('Legal');
    $pdf->addFont('Courier-Bold');
    $pdf->addText(50, 650, 36, 'Hello World Again!', 'Courier-Bold');
    $pdf->addUrl(50, 650, 380, 36, 'http://www.popphp.org/');
    $pdf->orderPages(array(3, 1, 2));
    $pdf->output();
} catch (\Exception $e) {
    echo $e->getMessage();
}