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, 2014 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Convert::Color::HTML; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
22772
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
82
|
|
9
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
50
|
|
10
|
2
|
|
|
2
|
|
7
|
use base qw( Convert::Color::Library ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
474
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Ensure that Color::Library::Dictionary::HTML is loaded |
13
|
2
|
|
|
2
|
|
480
|
use Color::Library; |
|
2
|
|
|
|
|
126235
|
|
|
2
|
|
|
|
|
576
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->register_color_space( 'html' ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
C - color conversion using C |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Directly: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Convert::Color::HTML; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $red = Convert::Color::HTML->new( 'red' ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $blue = Convert::Color::HTML->new( '#0000FF' ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Via L: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use Convert::Color; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $cyan = Convert::Color->new( 'html:cyan' ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Conversion from RGB: |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $green = Convert::Color::RGB->( 0, 1.0, 0 )->as_html; |
42
|
|
|
|
|
|
|
say "HTML colour name is " . $green->name; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This subclass of L provides a shortcut to performing |
47
|
|
|
|
|
|
|
library lookups specifically within the C dictionary. Additionally it |
48
|
|
|
|
|
|
|
will parse C<#RRGGBB> color specifications. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 $color = Convert::Color::HTML->new( $name ) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Returns a new object to represent the named color from the C dictionary |
59
|
|
|
|
|
|
|
or plain RGB triplet. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub new |
64
|
|
|
|
|
|
|
{ |
65
|
20
|
|
|
20
|
1
|
13281
|
my $class = shift; |
66
|
20
|
|
|
|
|
29
|
my ( $name ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
20
|
100
|
|
|
|
65
|
if( $name =~ m/^#([0-9a-f]{6})$/i ) { |
69
|
2
|
|
|
|
|
12
|
my $self = $class->Convert::Color::RGB8::new( $1 ); |
70
|
2
|
|
|
|
|
57
|
$self->[3] = uc "#$1"; |
71
|
2
|
|
|
|
|
10
|
return $self; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
18
|
|
|
|
|
79
|
return $class->SUPER::new( "html/$name" ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 METHODS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 $name = $color->name |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Returns the name of the color instance; either the C dictionary name, or |
84
|
|
|
|
|
|
|
the plain RGB triplet notation, as was passed to the constructor. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Don't register this as a palette space, because we can always represent any |
89
|
|
|
|
|
|
|
# RGB8 colour. Instead, provide the methods directly |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my %palette; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub new_from_rgb8 |
94
|
|
|
|
|
|
|
{ |
95
|
2
|
|
|
2
|
0
|
167
|
my $class = shift; |
96
|
2
|
|
|
|
|
4
|
my ( $rgb8 ) = @_; |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
9
|
my $hex = $rgb8->hex; |
99
|
|
|
|
|
|
|
|
100
|
2
|
100
|
|
|
|
84
|
unless( keys %palette ) { |
101
|
16
|
|
|
|
|
182
|
%palette = map { |
102
|
17
|
|
|
|
|
194
|
my $color = $class->new( $_ ); |
103
|
16
|
|
|
|
|
44
|
$color->hex => $color |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
# RT100404 - omit the misspelled 'fuscia' |
106
|
1
|
|
|
|
|
12
|
grep { $_ ne "fuscia" } Color::Library::Dictionary::HTML->color_names; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
2
|
|
66
|
|
|
45
|
return $palette{$hex} || $class->new( "#$hex" ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub new_rgb |
113
|
|
|
|
|
|
|
{ |
114
|
2
|
|
|
2
|
0
|
236
|
my $class = shift; |
115
|
2
|
|
|
|
|
9
|
return $class->new_from_rgb8( Convert::Color::RGB->new( @_ )->as_rgb8 ); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Paul Evans |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
0x55AA; |