Re: Re: rounded rectangles - deformed!

Alfred Reibenschuh <[email protected]> Thu, 10 Jul 2008 03:05:44 +0200
Newsgroups gmane.comp.lang.perl.modules.pdfapi2
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

| --- In [email protected], Alan Fry <ajf@...> wrote:
|> So far as I can see the 'Niko Tyni patch' is not applied to the
|> 'Content.pm' returned by the link to CPAN below.

the patch has been applied to the "bogen method" vs. curve that you use.

| I have no idea what you're smoking. I'll leave it to Frodo to supply
| the final answer, if he's following this thread.

i know what i smoke and i comprehend what bogen and arc does
vs. the much simpler curve and spline methods.

- --------------------------
#!/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->move( $x, $y + $h - $r);
	$gfx->spline( $x, $y + $h, $x + $r, $y + $h);

	# top
	$gfx->line( $x + $w - $r, $y + $h );

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

	# right
	$gfx->line($x + $w, $y + $r);

	# Bottom right
	$gfx->spline( $x + $w, $y, $x + $w - $r, $y);

	# bottom
	$gfx->line( $x + $r, $y );

	# Bottom left
	$gfx->spline( $x, $y, $x, $y + $r);

	# left
	$gfx->line( $x, $y + $h - $r);

	$gfx->close;

	return $gfx;
}


- --------------------------


hope that this code is more comprehensible to anyone ....


- --
fredo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEAREIAAYFAkh1YGgACgkQpyPEZ/g4emMVlwCglwjayV6gITC2mYdrxU5durVC
laYAnAu/FJqybmN9rNIwOhNY03m4boCI
=EYgH
-----END PGP SIGNATURE-----