Re: rounded rectangles - deformed!

Alan Fry <ajf-n9G92GgND9yX/[email protected]> Sat, 5 Jul 2008 14:29:48 +0100
Newsgroups gmane.comp.lang.perl.modules.pdfapi2
Message-ID <[email protected]>
I agree with you --  'rrrect' fails.

If you alter to top right arc to:

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

the nature of the fault shows up even more clearly.

Something is wrong with 'arc' or 'arctocurve' -- but I cannot for the  
moment see what it is.

You can get around the problem by drawing 'hline' or 'vline' segments  
between the rounded corners, but that's at best a very nasty hack.

Alan Fry

On 5 Jul 2008, at 02:07, Rick Measham wrote:

> 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
>
>
>