fpdf
PHP powered
home was ist fpdf? downloads & add-ons dokumentation faq forum impressum links kontakt
 

Downloads > Add-On

 
         
 

Rounded rectangle

Informations

Author: Maxime Delorme
License: Freeware

Description

Allows to draw rounded rectangles (requires FPDF 1.51). Parameters are:

x, y: top left corner of the rectangle.
w, h: width and height.
r: radius of the rounded corners.
style: same as Rect(): F, D (default), FD or DF.

Source

<?php
require('fpdf.php');

class PDF extends FPDF
{
    function RoundedRect($x,  $y,  $w,  $h, $r,  $style = '')
    {
        $k = $this->k;
        $hp = $this->h;
        if($style=='F')
            $op='f';
        elseif($style=='FD' or $style=='DF')
            $op='B';
        else
            $op
='S';
        $MyArc = 4/* (sqrt(2) - 1);
        $this->_out(sprintf('%.2f %.2f m', ($x+$r)*$k, ($hp-$y)*$k ));
        $xc = $x+$w-$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2f %.2f l',  $xc*$k, ($hp-$y)*$k ));

        $this->_Arc($xc + $r*$MyArc,  $yc - $r,  $xc + $r,  $yc - $r*$MyArc,  $xc + $r,  $yc);
        $xc = $x+$w-$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2f %.2f l', ($x+$w)*$k, ($hp-$yc)*$k));
        $this->_Arc($xc + $r,  $yc + $r*$MyArc,  $xc + $r*$MyArc,  $yc + $r,  $xc,  $yc + $r);
        $xc = $x+$r ;
        $yc = $y+$h-$r;
        $this->_out(sprintf('%.2f %.2f l', $xc*$k, ($hp-($y+$h))*$k));
        $this->_Arc($xc - $r*$MyArc,  $yc + $r,  $xc - $r,  $yc + $r*$MyArc,  $xc - $r,  $yc);
        $xc = $x+$r ;
        $yc = $y+$r;
        $this->_out(sprintf('%.2f %.2f l', ($x)*$k, ($hp-$yc)*$k ));
        $this->_Arc($xc - $r,  $yc - $r*$MyArc,  $xc - $r*$MyArc,  $yc - $r,  $xc,  $yc - $r);
        $this->_out($op);
    }

    function _Arc($x1,  $y1,  $x2,  $y2,  $x3,  $y3)
    {
        $h = $this->h;
        $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ',  $x1*$this->k,  ($h-$y1)*$this->k,
            $x2*$this->k,  ($h-$y2)*$this->k,  $x3*$this->k,  ($h-$y3)*$this->k));
    }
}

$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetLineWidth(0.5);
$pdf->SetFillColor(192);
$pdf->RoundedRect(70,  30,  68,  46,  3.5,  'DF');
$pdf->Output();
?>

View the result here.

Download

ZIP | TGZ
 






 
         
         
 
 
fpdf.de © Copyright 2004-2006 carrib internet solutions - Beachten Sie bitte die Nutzungsbedingungen
Eine Verwendung der auf fpdf.de befindlichen Inhalte (Texte, Grafiken) ist nur mit Zustimmung des Betreibers zulässig.