| 1 | package PDF::Make::Builder::Shape::Circle; | ||
| 2 | 53 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 53 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 53 | ▶ | use Object::Proto; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 53 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 53 | Object::Proto::define('PDF::Make::Builder::Shape::Circle', | |
| 8 | 'fill_colour:Str:default(#000)', | ||
| 9 | 'x:Num:required', | ||
| 10 | 'y:Num:required', | ||
| 11 | 'r:Num:required', | ||
| 12 | ); | ||
| 13 | 53 | Object::Proto::import_accessors('PDF::Make::Builder::Shape::Circle'); | |
| 14 | } | ||
| 15 | |||
| 16 | # Bezier control point ratio for circle approximation | ||
| 17 | 53 | ▶ | use constant K => 0.5522847498; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | |||
| 19 | 1 | ▶ | sub add { |
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||
| 20 | 1 | my ($self, $builder) = @_; | |
| 21 | 1 | my $page = $builder->page; | |
| 22 | 1 | my $canvas = $page->canvas; | |
| 23 | 1 | my $font = $builder->font; | |
| 24 | |||
| 25 | 1 | my $cx = $self->x; | |
| 26 | 1 | my $cy = $self->y; | |
| 27 | 1 | my $radius = $self->r; | |
| 28 | 1 | my ($cr, $cg, $cb) = $font->hex_to_rgb(fill_colour $self); | |
| 29 | |||
| 30 | 1 | my $k = $radius * K; | |
| 31 | |||
| 32 | 1 | $canvas->q->rg($cr, $cg, $cb); | |
| 33 | |||
| 34 | # 4 cubic Bezier curves forming a circle | ||
| 35 | 1 | $canvas->m($cx + $radius, $cy) | |
| 36 | ->c($cx + $radius, $cy + $k, $cx + $k, $cy + $radius, $cx, $cy + $radius) | ||
| 37 | ->c($cx - $k, $cy + $radius, $cx - $radius, $cy + $k, $cx - $radius, $cy) | ||
| 38 | ->c($cx - $radius, $cy - $k, $cx - $k, $cy - $radius, $cx, $cy - $radius) | ||
| 39 | ->c($cx + $k, $cy - $radius, $cx + $radius, $cy - $k, $cx + $radius, $cy) | ||
| 40 | ->f->Q; | ||
| 41 | |||
| 42 | 1 | return $self; | |
| 43 | } | ||
| 44 | |||
| 45 | 53 | 1; | |
| 46 | |||
| 47 | __END__ | ||