Skip Menu |

This queue is for tickets about the PDF-Create CPAN distribution.

Report information
The Basics
Id: 31834
Status: resolved
Worked: 10 min
Priority: 0/
Queue: PDF-Create

People
Owner: MARKUSB [...] cpan.org
Requestors: SREZIC [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.08
Fixed in: (no value)



Subject: Additional methods for PDF::Create::Page
It would be nice if the methods in the attached file (set_stroke_color, set_fill_color, set_line_width, circle) could be part of PDF::Create::Page. Regards, Slaven
Subject: PDF-Create-Page-additions.txt
use constant PI => 3.141592653; sub set_stroke_color { my($page, $r, $g, $b) = @_; return if (defined $page->{'current_stroke_color'} && $page->{'current_stroke_color'} eq join(",", $r, $g, $b)); $page->{'pdf'}->page_stream($page); $page->{'pdf'}->add("$r $g $b RG"); $page->{'current_stroke_color'} = join(",", $r, $g, $b); } sub set_fill_color { my($page, $r, $g, $b) = @_; return if (defined $page->{'current_fill_color'} && $page->{'current_fill_color'} eq join(",", $r, $g, $b)); $page->{'pdf'}->page_stream($page); $page->{'pdf'}->add("$r $g $b rg"); $page->{'current_fill_color'} = join(",", $r, $g, $b); } sub set_line_width { my($page, $w) = @_; return if (defined $page->{'current_line_width'} && $page->{'current_line_width'} == $w); $page->{'pdf'}->page_stream($page); $page->{'pdf'}->add("$w w"); $page->{'current_line_width'} = $w; } sub circle { my($page, $x, $y, $r) = @_; my @coords; for(my $i = 0; $i < PI*2; $i+=PI*2/$r/2) { my($xi,$yi) = map { $_*$r } (sin $i, cos $i); push @coords, $x+$xi, $y+$yi; } push @coords, @coords[0,1]; @coords = map { sprintf "%.2f", $_ } @coords; $page->moveto(shift @coords, shift @coords); for(my $i = 0; $i <= $#coords; $i+=2) { $page->lineto($coords[$i], $coords[$i+1]); } }
I had a look at your proposed additions: - some functionality already exists - set_stroke_color = setrgbcolorstroke - set_line_width = width - set_fill_color = setrgbcolor - I tried to make a circle, but it did not work (did now show up in acrobat) I'm not fundamentally against adding your things. You names are better, but I'm reluctant to add them just because the name is more understandable. Markus
On Tue Jun 03 08:45:47 2008, MARKUSB wrote: Show quoted text
> I had a look at your proposed additions: > - some functionality already exists > - set_stroke_color = setrgbcolorstroke > - set_line_width = width > - set_fill_color = setrgbcolor > - I tried to make a circle, but it did not work (did now show up in
acrobat) Show quoted text
> > I'm not fundamentally against adding your things. You names are better, > but I'm reluctant to add them just because the name is more
understandable. Show quoted text
>
I see that in current PDF::Create the methods were added. Thanks! For a rationale: the difference between the three set_* methods and the existing methods is that the former are remembering the current value and don't output anything to the PDF if it is not necessary. This may decrease the size of the generated PDF. For the circle, there is a bug in the method: the final stroke is missing. Just add $page->stroke; at the end of the method, and it should work. And just one improvement: I learned that it's better to calculate pi using the atan function, so the maximum precision is always used. So it's better to use use constant PI => 4 * atan2(1, 1);' than the current definition. Regards, Slaven
Methods asked for already defined in recent versions of PDF::Create.