rounded rectangles - deformed!

Rick Measham <rick-6wk1kIbWGY9Wo+R/V/U2/[email protected]> Sat, 05 Jul 2008 11:07:01 +1000
Newsgroups gmane.comp.lang.perl.modules.pdfapi2
Message-ID <[email protected]>
Why does my rrect fail? Run the script below (or 
http://rick.measham.id.au/paste/rrect.txt) and notice that the resulting 
shape is rather deformed. It was even worse when I did it with bogens 
rather than arcs.

Cheers!
Rick Measham


#!/usr/bin/perl

# rrect for PDF::API2

use strict;
use warnings;
use constant mm => 25.4 / 72;

use PDF::API2;

my $pdf = PDF::API2->new( -file => "$0.pdf" );
my $page = $pdf->page;
$page->mediabox(297/mm, 210/mm);

my $gfx = $page->gfx;

$gfx->strokecolor('black');
$gfx->rrect( 10/mm, 10/mm, 277/mm, 190/mm, 50/mm );
$gfx->stroke;

$pdf->save;

=item $gfx->rrect $x, $y, $w, $h, $r

will draw a rounded rectangle with a corner radius of $r

=cut

sub PDF::API2::Content::rrect {
	my ($gfx, $x, $y, $w, $h, $r) = @_;

	# Top left
	$gfx->arc( $x + $r, $y + $h - $r, $r, $r, 180, 90, 1 );

	# Top right
	$gfx->arc( $x + $w - $r, $y + $h - $r, $r, $r, 90, 0, 0 );

	# Bottom right
	$gfx->arc( $x + $w - $r, $y + $r, $r, $r, 360, 270, 0 );

	# Bottom left
	$gfx->arc( $x + $r, $y + $r, $r, $r, 270, 180, 0 );

	$gfx->close;

	return $gfx;
}
-- 
Message  protected for iSite by MailGuard: e-mail anti-virus, anti-spam and content filtering.
http://www.mailguard.com.au