line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2009-2014 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Convert::Color::Library; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
31661
|
use strict; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
129
|
|
9
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
112
|
|
10
|
4
|
|
|
4
|
|
22
|
use base qw( Convert::Color::RGB8 ); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
2006
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->register_color_space( 'lib' ); |
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
72407
|
use Carp; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1076
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
C - named lookup of colors from C |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Directly: |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use Convert::Color::Library; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $red = Convert::Color::Library->new( 'red' ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Only use the SVG dictionary |
31
|
|
|
|
|
|
|
my $brown = Convert::Color::Library->new( 'svg/brown' ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Use either HTML or SVG dictionary |
34
|
|
|
|
|
|
|
my $pink = Convert::Color::Library->new( 'html,svg/pink' ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Via L: |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use Convert::Color; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $cyan = Convert::Color->new( 'lib:cyan' ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $darkcyan = Convert::Color->new( 'lib:windows/darkcyan' ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This subclass of L provides lookup of color names |
47
|
|
|
|
|
|
|
using Robert Krimen's L module. It therefore provides |
48
|
|
|
|
|
|
|
convenient access to named colours in many dictionaries, such as SVG, X11 and |
49
|
|
|
|
|
|
|
HTML. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 $color = Convert::Color::Library->new( $name ) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Returns a new object to represent the named color. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
If the name is of the form |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
dicts/name |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Then C is parsed as a comma-separated list of dictionary names to pass |
66
|
|
|
|
|
|
|
to C. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new |
71
|
|
|
|
|
|
|
{ |
72
|
22
|
|
|
22
|
1
|
4675
|
my $class = shift; |
73
|
|
|
|
|
|
|
|
74
|
22
|
|
|
|
|
1242
|
require Color::Library; |
75
|
|
|
|
|
|
|
|
76
|
22
|
50
|
|
|
|
262699
|
@_ == 1 or |
77
|
|
|
|
|
|
|
croak "usage: Convert::Color::Library->new( NAME )"; |
78
|
|
|
|
|
|
|
|
79
|
22
|
|
|
|
|
31
|
my ( $name ) = @_; |
80
|
|
|
|
|
|
|
|
81
|
22
|
|
|
|
|
27
|
my $color; |
82
|
|
|
|
|
|
|
|
83
|
22
|
100
|
|
|
|
113
|
if( $name =~ m{^(.*)/(.*)$} ) { |
84
|
20
|
|
|
|
|
54
|
( my $dicts, $name ) = ( $1, $2 ); |
85
|
|
|
|
|
|
|
|
86
|
20
|
|
|
|
|
100
|
$color = Color::Library->color( [ split m/,/, $dicts ], $name ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
2
|
|
|
|
|
13
|
$color = Color::Library->color( $name ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
22
|
50
|
|
|
|
60411
|
defined $color or croak "No such library color named '$name'"; |
93
|
22
|
|
|
|
|
63
|
my $self = $class->SUPER::new( $color->rgb ); |
94
|
|
|
|
|
|
|
|
95
|
22
|
|
|
|
|
576
|
$self->[3] = $color->name; |
96
|
22
|
|
|
|
|
186
|
$self->[4] = $color->dictionary->name; |
97
|
|
|
|
|
|
|
|
98
|
22
|
|
|
|
|
647
|
return $self; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 METHODS |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 $name = $color->name |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 $dict = $color->dict |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Returns the name of the color within its dictionary, and the name of the |
110
|
|
|
|
|
|
|
dictionary itself. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
7
|
|
|
7
|
1
|
7186
|
sub name { shift->[3] } |
115
|
4
|
|
|
4
|
1
|
3305
|
sub dict { shift->[4] } |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 TODO |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over 4 |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Consider an API for getting the list of dictionary names and colour names. |
124
|
|
|
|
|
|
|
That said, it's easy enough to do directly to C, so maybe not |
125
|
|
|
|
|
|
|
needed. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Expose other dictionaries (SVG? Windows?) as named spaces, like the HTML one. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SEE ALSO |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item * |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
L - color space conversions |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item * |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L - An easy-to-use and comprehensive named-color library |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L - color conversion using C |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 AUTHOR |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Paul Evans |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
0x55AA; |