 |
 |
|
|
 |
| |
 |
Downloads > Add-On |
 |
|
 |
| |
|
|
|
|
| |
Dashed rectangle
InformationsAuthor: Antoine Michéa License: GPL
DescriptionAllows to draw a dashed rectangle. Parameters are:
x1, y1: upper left corner of the rectangle.
x2, y2: lower right corner of the rectangle.
width: dash thickness (1 by default).
nb: number of dashes per line (15 by default).
Note: for a more complete support of dashes, see this script.
Source
<?php /* Author : Antoine Michéa Mail : saturn@saturn-share.org Web : saturn-share.org Program : dashed_rect.php License : GPL v2 Description: Allows to draw a dashed rectangle. Parameters are: x1, y1 : upper left corner of the rectangle. x2, y2 : lower right corner of the rectangle. width : dash thickness (1 by default). nb : number of dashes per line (15 by default). Date : 2003-01-07 */
define('FPDF_FONTPATH', 'font/'); require('fpdf.php');
class PDF extends FPDF { function DashedRect($x1, $y1, $x2, $y2, $width=1, $nb=15) { $this->SetLineWidth($width); $longueur=abs($x1-$x2); $hauteur=abs($y1-$y2); if($longueur>$hauteur) { $Pointilles=($longueur/$nb)/2; // length of dashes } else { $Pointilles=($hauteur/$nb)/2; } for($i=$x1;$i<=$x2;$i+=$Pointilles+$Pointilles) { for($j=$i;$j<=($i+$Pointilles);$j++) { if($j<=($x2-1)) { $this->Line($j, $y1, $j+1, $y1); // upper dashes $this->Line($j, $y2, $j+1, $y2); // lower dashes } } } for($i=$y1;$i<=$y2;$i+=$Pointilles+$Pointilles) { for($j=$i;$j<=($i+$Pointilles);$j++) { if($j<=($y2-1)) { $this->Line($x1, $j, $x1, $j+1); // left dashes $this->Line($x2, $j, $x2, $j+1); // right dashes } } } } }
$pdf=new PDF(); $pdf->Open(); $pdf->AddPage(); $pdf->SetDrawColor(200); $pdf->DashedRect(40, 10, 165, 40); $pdf->SetFont('Arial', 'B', 30); $pdf->SetXY(40, 10); $pdf->Cell(125, 30, 'Enjoy dashes!', 0, 0, 'C', 0); $pdf->Output(); ?>
|
View the result here.
DownloadZIP | TGZ
| | |