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
|
|
44683
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
158
|
|
9
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
142
|
|
10
|
4
|
|
|
4
|
|
31
|
use base qw( Convert::Color::RGB8 ); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
2417
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->register_color_space( 'lib' ); |
13
|
|
|
|
|
|
|
|
14
|
4
|
|
|
4
|
|
89411
|
use Carp; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1317
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
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
|
23
|
|
|
23
|
1
|
4911
|
my $class = shift; |
73
|
|
|
|
|
|
|
|
74
|
23
|
|
|
|
|
1842
|
require Color::Library; |
75
|
|
|
|
|
|
|
|
76
|
23
|
50
|
|
|
|
327118
|
@_ == 1 or |
77
|
|
|
|
|
|
|
croak "usage: Convert::Color::Library->new( NAME )"; |
78
|
|
|
|
|
|
|
|
79
|
23
|
|
|
|
|
32
|
my ( $name ) = @_; |
80
|
|
|
|
|
|
|
|
81
|
23
|
|
|
|
|
38
|
my $color; |
82
|
|
|
|
|
|
|
|
83
|
23
|
100
|
|
|
|
160
|
if( $name =~ m{^(.*)/(.*)$} ) { |
84
|
21
|
|
|
|
|
58
|
( my $dicts, $name ) = ( $1, $2 ); |
85
|
|
|
|
|
|
|
|
86
|
21
|
|
|
|
|
196
|
$color = Color::Library->color( [ split m/,/, $dicts ], $name ); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
2
|
|
|
|
|
11
|
$color = Color::Library->color( $name ); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
23
|
50
|
|
|
|
87113
|
defined $color or croak "No such library color named '$name'"; |
93
|
23
|
|
|
|
|
65
|
my $self = $class->SUPER::new( $color->rgb ); |
94
|
|
|
|
|
|
|
|
95
|
23
|
|
|
|
|
586
|
$self->[3] = $color->name; |
96
|
23
|
|
|
|
|
198
|
$self->[4] = $color->dictionary->name; |
97
|
|
|
|
|
|
|
|
98
|
23
|
|
|
|
|
799
|
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
|
5921
|
sub name { shift->[3] } |
115
|
4
|
|
|
4
|
1
|
3477
|
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; |