line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graphics::Primitive; |
2
|
1
|
|
|
1
|
|
19211
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.67'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
no Moose; |
9
|
|
|
|
|
|
|
1; |
10
|
|
|
|
|
|
|
__END__ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Graphics::Primitive - Device and library agnostic graphic primitives |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Graphics::Primitive is a device and library agnostic system for creating |
21
|
|
|
|
|
|
|
and manipulating various graphical elements such as Borders, Fonts, Paths |
22
|
|
|
|
|
|
|
and the like. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $c = Graphics::Primitive::Component->new( |
25
|
|
|
|
|
|
|
background_color => Graphics::Color::RGB->new( |
26
|
|
|
|
|
|
|
red => 1, green => 0, blue => 0 |
27
|
|
|
|
|
|
|
), |
28
|
|
|
|
|
|
|
width => 500, height => 350, |
29
|
|
|
|
|
|
|
border => new Graphics::Primitive::Border->new( width => 5 ) |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $driver = Graphics::Primitive::Driver::Cairo->new(format => 'SVG'); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$driver->prepare($c); |
35
|
|
|
|
|
|
|
$driver->finalize($c); |
36
|
|
|
|
|
|
|
$driver->draw($c); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$driver->write($filename) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Graphics::Primitive is library agnostic system for drawing things. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
The idea is to allow you to create and manipulate graphical components and |
45
|
|
|
|
|
|
|
then pass them off to a L<Driver|Graphics::Primitive::Driver> for actual |
46
|
|
|
|
|
|
|
drawing. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 CONCEPTS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
The root object for Graphics::Primitive is the |
51
|
|
|
|
|
|
|
L<Component|Graphics::Primitive::Component>. Components contain all the |
52
|
|
|
|
|
|
|
common elements that you'd expect: margins, padding, background color etc. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
The next most important is the L<Container|Graphics::Primitive::Container>. |
55
|
|
|
|
|
|
|
Containers are Components that can hold other Components. Containers have all |
56
|
|
|
|
|
|
|
the attributes and methods of a Component with the addition of the |
57
|
|
|
|
|
|
|
I<layout_manager> attribute for us with L<Layout::Manager>. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Another important Component is the L<Canvas|Graphics::Primitive::Canvas>. |
60
|
|
|
|
|
|
|
The Canvas differs from other components by being a container for various |
61
|
|
|
|
|
|
|
L<Geometry::Primitive> objects. This allows drawing of arbitrary shapes |
62
|
|
|
|
|
|
|
that do not fit existing components. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DRAWING LIFECYCLE |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
After creating all your components, there is a lifecycle that allows them |
67
|
|
|
|
|
|
|
to do their internal housekeeping to prepare for eventual drawing. The |
68
|
|
|
|
|
|
|
lifecycle is: B<prepare>, B<layout> and B<pack>. Detailed explanation of |
69
|
|
|
|
|
|
|
these methods can be found in L<Component|Graphics::Primitive::Component>. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 PREPARATION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Graphics::Primitive::Component has a C<prepared> flag. This flag is set as |
74
|
|
|
|
|
|
|
part of the C<prepare> method (shocking, I know). If this flag is set, then |
75
|
|
|
|
|
|
|
subsequent calls to C<prepare> are ignored. Containers also have a prepare |
76
|
|
|
|
|
|
|
flag, but this flag is B<not> set when calling C<prepare>. A Container's flag |
77
|
|
|
|
|
|
|
should be set by the layout manager. More information may be found with |
78
|
|
|
|
|
|
|
L<Layout::Manager>. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 INSPIRATION |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Most of the concepts that you'll find in Graphics::Primitive are inspired by |
83
|
|
|
|
|
|
|
L<Cairo|http://cairographics.org>'s API and |
84
|
|
|
|
|
|
|
L<CSS|http://www.w3.org/Style/CSS/>'s box model. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Cory Watson, C<< <gphat@cpan.org> >> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Florian Ragwitz |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Many of the ideas here come from my experience using the Cairo library. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright 2008-2010 by Cory G Watson. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
103
|
|
|
|
|
|
|
under the same terms as Perl itself. |